Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

hashmap

Version Badge Build Status License

A superior alternative to object literals for basic hash maps

Install

Download the development or minified version, or install via NPM:

npm install @ryanmorr/hashmap

Usage

Use just like an object literal:

const map = hashmap();

map.foo = 1;
map.bar = 2;

{}.toString.call(map); //=> "[object Object]"
JSON.stringify(map); //=> "{\"foo\":1,\"bar\":2}"

Unlike object literals, there is no chance of name collisions:

'toString' in {}; //=> true
'toString' in hashmap(); //=> false

for (const key in map) {
    // `hasOwnProperty` check is unnecessary
}

Provide objects as arguments to pre-populate the map:

const map = hashmap({foo: 1}, {bar: 2}, {foo: 10, baz: 3});

map.foo; //=> 10
map.bar; //=> 2
map.baz; //=> 3

Implements the iterable protocol, enabling for...of loops:

const map = hashmap({foo: 1, bar: 2, baz: 3});

for (const [key, value] of map) {
    // Do something
}

License

This project is dedicated to the public domain as described by the Unlicense.

About

A superior alternative to object literals for basic hash maps

Topics

Resources

License

Packages

No packages published
You can’t perform that action at this time.