Registry / serialization / map-or-similar

map-or-similar

JSON →
library1.5.0jsnpmunverified

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-similar
INSTALL
IMPORT
SIG · MAP-OR-SIMILAR
M
map-or-similar
serializationjavascriptv1.5.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MapOrSimilar
const MapOrSimilar = require('map-or-similar');
import MapOrSimilar from 'map-or-similar';
Primary usage pattern is CommonJS `require()`. While it might technically work with a default import in some bundlers, the package's design and documentation strongly suggest CJS.
MapOrSimilar
import MapOrSimilar from 'map-or-similar';
import { MapOrSimilar } from 'map-or-similar';
For ES Modules, assuming the CommonJS export (`module.exports = MapOrSimilar;`) maps to a default export in ESM environments. Named imports are not explicitly supported by the module's structure.
Usage
const myMap = new MapOrSimilar();
const myMap = MapOrSimilar();
The exported symbol is a constructor function and must be instantiated with `new` to create a map-like instance.

Demonstrates instantiation of `MapOrSimilar` and basic usage of its core methods: `set`, `get`, `has`, `size`, `forEach`, and `delete` with various key types.

const MapOrSimilar = require('map-or-similar'); // Create a new map-like object. // This will either be a native Map if available, or a custom polyfill implementation. const myMap = new MapOrSimilar(); // Set various types of keys and values myMap.set('stringKey', 'stringValue'); myMap.set(123, { id: 1, name: 'Number Key Object' }); const complexKey = { type: 'object', id: 'complex' }; myMap.set(complexKey, 'value associated with complex object'); // Retrieve values console.log('Value for stringKey:', myMap.get('stringKey')); console.log('Value for complexKey:', myMap.get(complexKey)); // Check for existence and size console.log('Has 123?', myMap.has(123)); console.log('Current size:', myMap.size); // Iterate over entries myMap.forEach(function(value, key, map) { console.log(`Key: ${JSON.stringify(key)}, Value: ${JSON.stringify(value)}`); }); // Delete an entry myMap.delete('stringKey'); console.log('Size after deletion:', myMap.size); console.log('Has stringKey?', myMap.has('stringKey'));
Debug
Known issues
gotchaThis library only implements a subset of the standard `Map` API. Methods like `keys()`, `values()`, `entries()`, `clear()`, and the `Symbol.iterator` are not supported. Attempting to use these will result in a `TypeError`.
fix
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.
affects: >=1.0.0
gotchaThe library primarily targets CommonJS (CJS) environments as demonstrated by its `require()` examples. While modern bundlers might transpile ES Modules (ESM) `import` statements, direct ESM compatibility might vary or require specific build configurations.
fix
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.
affects: >=1.0.0
gotchaThe package falls back to a polyfill only if `Map` is not available. In environments where `Map` *is* available but has specific quirks or performance issues you wish to avoid, this library will still return the native `Map` instance, not its own polyfill.
fix
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.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: myMap.keys is not a function
Attempting to use a Map method (like `keys()`, `values()`, `entries()`, `clear()`) that is not implemented by `map-or-similar`.
fix
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.
ReferenceError: MapOrSimilar is not defined
The `map-or-similar` module was not correctly imported or required, or the variable name `MapOrSimilar` was misspelled.
fix
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.
Upgrade
Version history
1.5.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
map-or-similar — npm install map-or-similar · libregistry