An extended Map and the one JavaScript should have shipped
Installation · Docs · Usage
Follow @marcuspoehls and @superchargejs for updates!
The @supercharge/map package provides an extended JavaScript Map class. It comes with additional methods like .isEmpty() or .map(callback).
You already know methods like .map() from arrays and having them available on maps improves your development experience and makes your code more readable.
npm i @supercharge/map
Find all the details for @supercharge/map in the extensive Supercharge docs.
Using @supercharge/map is pretty straightforward. Import the Map class exported from the @supercharge/map package and use it (almost) the same way you would use JavaScript’s Map class. This package gives you the parameter order key, value, map in callbacks. JavaScript’s Map class gives you value, key, map:
const Map = require('@supercharge/map')
const cache = new Map()
cache.isEmpty()
// true
cache
.set('user:1', 'Marcus')
.set('user:2', 'Supercharge')
cache.isNotEmpty()
// true
const users = cache.map((key, value, map) => {
return { [key]: value }
})
// [{ 'user:1': 'Marcus' }, { 'user:2': 'Supercharge' }]Do you miss a function? We very much appreciate your contribution! Please send in a pull request 😊
- Create a fork
- Create your feature branch:
git checkout -b my-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request 🚀
MIT © Supercharge
superchargejs.com · GitHub @supercharge · Twitter @superchargejs