Socket
Socket
Sign inDemoInstall

pseudomap

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pseudomap

A thing that is a lot like ES6 `Map`, but without iterators, for use in environments where `for..of` syntax and `Map` are not available.


Version published
Weekly downloads
12M
increased by2.57%
Maintainers
1
Install size
8.75 kB
Created
Weekly downloads
 

Package description

What is pseudomap?

The pseudomap npm package is a simple implementation of a Map-like data structure that mimics the ES6 Map API. It is designed to be lightweight and provides basic functionalities of a map without adhering strictly to the ES6 specification, making it suitable for environments where a full ES6 implementation is not necessary or desired.

What are pseudomap's main functionalities?

Set and Get

Allows setting a key-value pair and retrieving the value associated with a key.

const PseudoMap = require('pseudomap');
let map = new PseudoMap();
map.set('key', 'value');
console.log(map.get('key')); // Outputs: 'value'

Iteration

Supports iterating over the map using for-of loops to access keys and values.

const PseudoMap = require('pseudomap');
let map = new PseudoMap();
map.set('key1', 'value1');
map.set('key2', 'value2');
for (let [key, value] of map) {
  console.log(key + ': ' + value);
}

Clear

Provides a method to clear all key-value pairs in the map.

const PseudoMap = require('pseudomap');
let map = new PseudoMap();
map.set('key1', 'value1');
map.clear();
console.log(map.size); // Outputs: 0

Other packages similar to pseudomap

Readme

Source

pseudomap

A thing that is a lot like ES6 Map, but without iterators, for use in environments where for..of syntax and Map are not available.

If you need iterators, or just in general a more faithful polyfill to ES6 Maps, check out es6-map.

If you are in an environment where Map is supported, then that will be returned instead, unless process.env.TEST_PSEUDOMAP is set.

You can use any value as keys, and any value as data. Setting again with the identical key will overwrite the previous value.

Internally, data is stored on an Object.create(null) style object. The key is coerced to a string to generate the key on the internal data-bag object. The original key used is stored along with the data.

In the event of a stringified-key collision, a new key is generated by appending an increasing number to the stringified-key until finding either the intended key or an empty spot.

Note that because object traversal order of plain objects is not guaranteed to be identical to insertion order, the insertion order guarantee of Map.prototype.forEach is not guaranteed in this implementation. However, in all versions of Node.js and V8 where this module works, forEach does traverse data in insertion order.

API

Most of the Map API, with the following exceptions:

  1. A Map object is not an iterator.
  2. values, keys, and entries methods are not implemented, because they return iterators.
  3. The argument to the constructor can be an Array of [key, value] pairs, or a Map or PseudoMap object. But, since iterators aren't used, passing any plain-old iterator won't initialize the map properly.

USAGE

Use just like a regular ES6 Map.

var PseudoMap = require('pseudomap')

// optionally provide a pseudomap, or an array of [key,value] pairs
// as the argument to initialize the map with
var myMap = new PseudoMap()

myMap.set(1, 'number 1')
myMap.set('1', 'string 1')
var akey = {}
var bkey = {}
myMap.set(akey, { some: 'data' })
myMap.set(bkey, { some: 'other data' })

FAQs

Last updated on 05 Jan 2016

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