Socket
Socket
Sign inDemoInstall

map-or-similar

Package Overview
Dependencies
0
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    map-or-similar

A JavaScript (JS) Map or Similar object polyfill if Map is not available.


Version published
Weekly downloads
5.2M
increased by3.87%
Maintainers
1
Install size
25.4 kB
Created
Weekly downloads
 

Package description

What is map-or-similar?

The map-or-similar npm package provides a simple and flexible way to create and manage map-like collections. It allows for the easy manipulation of key-value pairs with a focus on providing a consistent interface that works similarly to the native JavaScript Map object, but with additional utilities and fallbacks for environments where Map is not available or desired.

What are map-or-similar's main functionalities?

Creating a new map

This feature allows users to create a new map-like collection. The collection can store key-value pairs, similar to the native JavaScript Map.

const MapOrSimilar = require('map-or-similar');
const myMap = new MapOrSimilar();

Setting and getting values

Users can set key-value pairs in the collection and retrieve values by their keys. This functionality mimics that of the JavaScript Map, providing a familiar interface for managing collections.

myMap.set('key', 'value');
const value = myMap.get('key');

Checking for key existence

This feature allows users to check whether a specific key exists in the collection. It's useful for conditionally adding or modifying data based on the presence of keys.

const hasKey = myMap.has('key');

Other packages similar to map-or-similar

Readme

Source

Map Or Similar

Returns a JavaScript Map() or a similar object with the same interface, if Map is not available. Focuses on performance. No dependencies. Made for the browser and nodejs.

Install

npm install map-or-similar --save

Use

var MapOrSimilar = require('map-or-similar');

// make a new map or similar object
var myMap = new MapOrSimilar();

// use it like a map
myMap.set('key1', 'value1');
myMap.set({ val: 'complex object as key' }, 'value2');

The following methods and properties are supported identically to Map():

set(key, val)     : Sets a value to a key. Key can be a complex object, array, etc.
get(key)          : Returns the value of a key.
has(key)          : Returns true if the key exists, otherwise false.
delete(key)       : Deletes a key and its value.
forEach(callback) : Invokes callback(val, key, object) once for each key-value pair in insertion order.
size              : Returns the number of keys-value pairs.

Does not support other Map methods or properties.

Test

npm run test

License

Released under an MIT license.

Other Libs

  • Memoizerific: Fastest, smallest, most-efficient JavaScript memoization lib to memoize JS functions.
  • Multi Key Cache: A JavaScript (JS) cache that can have multiple complex values as keys.

Keywords

FAQs

Last updated on 20 Jan 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc