Coder Social home page Coder Social logo

orderedmap's People

Contributors

adrianheine avatar andrewvasilchuk avatar lpellegr avatar marijnh avatar mgenware avatar saul-mirone avatar whawker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

orderedmap's Issues

Use named export for ES module compatibility

Currently this package exports a class as the module, which isn't supported in ES modules. A simple solution is to just use a named export, i.e.

exports.OrderedMap = OrderedMap;

Commonjs consumers would then import via:

const { OrderedMap } = require('orderedmap');

The motivation for this is to smooth the path for packages wanting to adopt ES modules that depend on this package.

Error with TypeScript 3.5, "An accessor cannot be declared in an ambient context."

The types introduced in #6 include a getter that is not supported in TypeScript versions 3.6 and earlier. This particular change in the compiler output was widely criticized at the time.

While these TypeScript versions are pretty old (~2 years) by now, they're still used by some projects. Our particular issue is with the Kendo UI Editor for Angular when running in Angular 8.x projects, but it may not be limited to it.

My suggestion is to replace it with a readonly field to remain compatible with older versions of TypeScript.

The only downside to that is that inheriting OrderedMap will require using a field for overriding size. I'm not sure if inheriting the class is a common scenario for the library. Edit: I've just noticed that the constructor is marked as private and extending the class is not supported.

diff --git a/types/index.d.ts b/types/index.d.ts
index 551e742..fdc372c 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -21,7 +21,7 @@ declare class OrderedMap<T = any> {
 
   subtract(map: MapLike<T>): OrderedMap<T>
 
-  get size(): number
+  readonly size: number
 
   static from<T>(map: MapLike<T>): OrderedMap<T>
 }

Any plans for implementing Symbol.iterator support?

WIth modern linters, especially with TypeScript code, (e.g. the unicorn/recommended rules), I've noticed it trying to replace my .forEach loops for a for (const item of orderedMapObject) which breaks my code.
Any reason to not implement support for the Symbol.iterator method so that using for() loops will work smoothly with this library?
If this is accepted, I don't PR-ing a fix for this.

[feature request] Add support for toObject in the from function

The from function should use the value of a 'toObject' function if it exists on the given object. This will add compatibility with other mapped classes, and more importantly, make orderedmap compatible with other versions of itself (that also have the toObject function) so that it does not need to be a shared dependency (for consumers using the newer version).

example implementation (checks that a 0 argument toObject function exists and then calls it)
if (value && typeof value.toObject === 'function' && value.toObject.length === 0) value = value.toObject()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.