Map Or Similar is a JavaScript utility that provides a `Map`-like object, defaulting to the native `Map` if available in the environment, or falling back to a custom polyfill implementation otherwise. Currently at version 1.5.0, it focuses on delivering a high-performance, dependency-free solution for environments where native `Map` support might be lacking or incomplete. The library supports core `Map` methods such as `set`, `get`, `has`, `delete`, `forEach`, and the `size` property, making it suitable for basic key-value storage. It is designed to work seamlessly in both browser and Node.js environments. Its primary differentiator is its lightweight footprint and performance-oriented implementation, achieved by only replicating a subset of the full `Map` API, rather than attempting a complete polyfill.
npm install map-or-similarVerified import paths — ran on the pinned version, not inferred.
Demonstrates instantiation of `MapOrSimilar` and basic usage of its core methods: `set`, `get`, `has`, `size`, `forEach`, and `delete` with various key types.
Ensure your code only uses the explicitly supported methods: `set`, `get`, `has`, `delete`, `forEach`, and `size`. If full `Map` functionality is required, consider a comprehensive `Map` polyfill or target environments with native `Map` support.
For Node.js, use `require('map-or-similar')`. For browser environments or projects using ESM, ensure your bundler (e.g., Webpack, Rollup, Parcel) is configured to correctly handle CJS modules imported into an ESM context.If you specifically need to use the `map-or-similar` polyfill implementation even when native `Map` exists (e.g., for consistent behavior across environments or specific performance characteristics), you would need to manually check for and use its internal polyfill class if exposed, or use a different library that strictly enforces its own implementation.
Review the documentation and use only the supported methods: `set`, `get`, `has`, `delete`, `forEach`, and `size`. For iteration, rely on `forEach` instead of iterator methods.
Ensure you have `const MapOrSimilar = require('map-or-similar');` (CommonJS) or `import MapOrSimilar from 'map-or-similar';` (ESM, with bundler support) at the top of your file.No dependency data recorded yet.