GithubHelp home page GithubHelp logo

stringmap's Introduction

stringmap.js

A fast and robust stringmap implementation that can hold any string keys, including __proto__, with minimal overhead compared to a plain object. Works in node and browsers.

The API is created to be as close to the ES6 Map API as possible. Prefer sm.remove("key") for deleting a key. ES6 Map uses map.delete("key") instead and for that reason sm['delete']("key") is available as a stringmap alias as well. Never do sm.delete("key") unless you're certain to be in the land of ES5 or later.

Examples

Available in examples.js

var StringMap = require("stringmap");

var sm1 = new StringMap();
sm1.set("greeting", "yoyoma");
sm1.set("check", true);
sm1.set("__proto__", -1);
console.log(sm1.has("greeting")); // true
console.log(sm1.get("__proto__")); // -1
sm1.remove("greeting");
console.log(sm1.keys()); // [ 'check', '__proto__' ]
console.log(sm1.values()); // [ true, -1 ]
console.log(sm1.items()); // [ [ 'check', true ], [ '__proto__', -1 ] ]
console.log(sm1.toString()); // {"check":true,"__proto__":-1}

var sm2 = new StringMap({
    one: 1,
    two: 2,
});
console.log(sm2.map(function(value, key) {
    return value * value;
})); // [ 1, 4 ]
sm2.forEach(function(value, key) {
    // ...
});
console.log(sm2.isEmpty()); // false
console.log(sm2.size()); // 2

var sm3 = sm1.clone();
sm3.merge(sm2);
sm3.setMany({
    a: {},
    b: [],
});
console.log(sm3.toString()); // {"check":true,"one":1,"two":2,"a":{},"b":[],"__proto__":-1}

Installation

Node

Install using npm

npm install stringmap
var StringMap = require("stringmap");

Browser

Clone the repo and include it in a script tag

git clone https://github.com/olov/stringmap.git
<script src="stringmap/stringmap.js"></script>

stringmap's People

Contributors

olov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

stringmap's Issues

Could you tag your releases?

could you please tag your releases?

I ask here for stringmap, but the same problem occurs with other repositories you have : you publish them on npm, but not formally on github.

I would like to package some of yours in Debian, so I need official versions to work on.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.