CLeeSpruit / Array-Like-Map

Extends functionality of the map to be more like an array
GNU General Public License v3.0
0 stars 0 forks source link

Build Status codecov npm license XO code style Greenkeeper badge

Array-Like-Map

Have your Maps and eat it, too.

Extends functionality of the map to be more like an array.

Installation

Usage

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);

MapFilter

Example

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}]

MapToArray

Example

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}]

MapKeysToArray

Example

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']

MapPop

Example

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'

MapFind

Example

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}

Contributing

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.

License

This project uses GPL 3.0.