GithubHelp home page GithubHelp logo

map-like's Introduction

map-like Actions Status: test

ECMAScript Map like class.

It has same API with Map - JavaScript | MDN.

This library is tiny - 1.5kB(gzip).

✈ bundle-size map-like
[email protected]

env  bundle   minify   gzip
--   5.73 kB  3.08 kB  1.5 kB

Limitation ⚠️

  • Not support Symbol.Iterator
    • This means that MapLike object is not iterable.
  • Return Array insteadof Iterator object.
    • MapLike#values(), MapLike#keys(), MapLike#entries() return a Array.
  • Not support toString()

Why Map-like?

I've created Map-like to avoid Symbol.iterator. Because, the transpiled code of Iterator has a run-time cost at the current moment.

So, MapLike does not support Iterator object.

Install

Install with npm:

npm install map-like

Usage

const { MapLike } = require("map-like");
const map = new MapLike(["key", "value"]);
const value = map.get("key");
map.set("newKey", "newValue");

API

MapLike

ES6 Map like object. See Map - JavaScript | MDN

size

return map size

Returns: Number

entries(): Array

entries [[key, value], [key, value]] value

Returns: Array

keys(): Array

get keys

Returns: Array

values(): Array

get values

Returns: Array

get(key: Any): Any

Parameters

  • key: Any - The key of the element to return from the Map object.

Returns: Any

has(key: Any): boolean

has value of key

Parameters

  • key: Any - The key of the element to return from the Map object.

Returns: boolean

set(key: Any, value: Any): MapLike

set value for key

Parameters

  • key: Any - The key of the element to return from the Map object.
  • value: Any

Returns: MapLike

delete(key: Any): boolean

delete value for key

Parameters

  • key: Any - The key of the element to return from the Map object.

Returns: boolean

clear(): MapLike

clear defined key,value

Returns: MapLike

forEach(handler: function (value, key, map), thisArg: [Any])

forEach map

Parameters

  • handler: function (value, key, map)
  • thisArg: [Any]

Changelog

See Releases page.

Running tests

Install devDependencies and Run npm test:

npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

License

MIT © azu

Thanks

Test MapLike with test-case of https://github.com/Financial-Times/polyfill-service/blob/master/polyfills/Map/tests.js.

map-like's People

Contributors

azu avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

map-like's Issues

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.