Have your Maps and eat it, too.
Extends functionality of the map to be more like an array.
npm install --save-dev @cspruit/array-like-map
in the same directory as the package.json file lives.import {mapFilter} from '@cspruit/array-like-map';
const animals = new Map();
animals.set('dog', { isPet: true});
animals.set('tiger', { isPet: false});
const pets = mapFilter(animals, value => value.isPet);
import {mapFilter} from '@cspruit/array-like-map';
const animals = new Map();
animals.set('dog', { name: 'Spot', isPet: true});
animals.set('dragon', { name: 'Smaug', isPet: false});
const pets = mapFilter(animals, value => value.isPet);
// Should return a map of ['dog', {isPet: true}]
import {mapToArray} from '@cspruit/array-like-map';
const animals = new Map();
animals.set('dog', { name: 'Spot', isPet: true});
animals.set('dragon', { name: 'Smaug', isPet: false});
const pets = mapToArray(animals);
// Should return [{name: 'Spot', isPet: true}, {name: 'Smaug', isPet: false}]
import {mapToArray} from '@cspruit/array-like-map';
const animals = new Map();
animals.set('dog', { name: 'Spot', isPet: true});
animals.set('dragon', { name: 'Smaug', isPet: false});
const pets = mapToArray(animals);
// Should return ['dog', 'dragon']
import {mapPop} from '@cspruit/array-like-map';
const animals = new Map();
const dog = {name: 'Spot', isPet: true};
const dragon = {name: 'Smaug', isPet: false};
animals.set('dog', dog);
animals.set('dragon', dragon);
const removedDragon = mapPop(animals, 'dragon');
// Should return {name: 'Smaug', isPet: false} and the map now only has 'dog'
import {mapFind} from '@cspruit/array-like-map';
const animals = new Map();
const dog = {name: 'Spot', isPet: true};
const dragon = {name: 'Smaug', isPet: false};
animals.set('dog', dog);
animals.set('dragon', dragon);
const foundDog = mapFind(animals, (pet) => pet.name === 'Spot');
// Should return {name: 'Spot', isPet: true}
All contributions, suggestions, and issues are welcome!
Check out the Issues page. In general anything listed is up for grabs, though bugs tend to be more detailed than enhancements and might be better to pick up if starting out.
This project uses GPL 3.0.