{"library":"map-or-similar","title":"Map Or Similar","description":"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.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install map-or-similar"],"cli":null},"imports":["const MapOrSimilar = require('map-or-similar');","import MapOrSimilar from 'map-or-similar';","const myMap = new MapOrSimilar();"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const MapOrSimilar = require('map-or-similar');\n\n// Create a new map-like object.\n// This will either be a native Map if available, or a custom polyfill implementation.\nconst myMap = new MapOrSimilar();\n\n// Set various types of keys and values\nmyMap.set('stringKey', 'stringValue');\nmyMap.set(123, { id: 1, name: 'Number Key Object' });\nconst complexKey = { type: 'object', id: 'complex' };\nmyMap.set(complexKey, 'value associated with complex object');\n\n// Retrieve values\nconsole.log('Value for stringKey:', myMap.get('stringKey'));\nconsole.log('Value for complexKey:', myMap.get(complexKey));\n\n// Check for existence and size\nconsole.log('Has 123?', myMap.has(123));\nconsole.log('Current size:', myMap.size);\n\n// Iterate over entries\nmyMap.forEach(function(value, key, map) {\n  console.log(`Key: ${JSON.stringify(key)}, Value: ${JSON.stringify(value)}`);\n});\n\n// Delete an entry\nmyMap.delete('stringKey');\nconsole.log('Size after deletion:', myMap.size);\nconsole.log('Has stringKey?', myMap.has('stringKey'));","lang":"javascript","description":"Demonstrates instantiation of `MapOrSimilar` and basic usage of its core methods: `set`, `get`, `has`, `size`, `forEach`, and `delete` with various key types.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}