map-like
v2.0.0
Published
ECMAScript Map like object.
Downloads
43,011
Readme
map-like
ECMAScript Map
like class.
It has same API with Map - JavaScript | MDN.
It is tiny library - 1.5kB(gzip).
✈ bundle-size map-like
[email protected]
env bundle minify gzip
-- 5.73 kB 3.08 kB 1.5 kB
Limitation :warning:
- Not support
Symbol.Iterator
- it meansMapLike
is not iterable. - Not support
toString()
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.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- 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.