Git Product home page Git Product logo

array-like-map's Introduction

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

  • Install by running npm install --save-dev @cspruit/array-like-map in the same directory as the package.json file lives.

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

  • Takes a map and returns a sub-map of all results that are true.

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

  • Converts a map's values into an array

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

  • Converts a map's keys into an array

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

  • Removes and returns a value from a map
  • Works similar to Map.delete, but returns the value removed instead of a boolean

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

  • Searches and returns the first value that is true for the condition

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.

array-like-map's People

Contributors

cleespruit avatar greenkeeper[bot] avatar semantic-release-bot avatar

Watchers

James Cloos avatar  avatar

array-like-map's Issues

An in-range update of babel7 is breaking the build 🚨

There have been updates to the babel7 monorepo:

    • The devDependency @babel/core was updated from 7.7.7 to 7.8.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

This monorepo update includes releases of one or more dependencies which all belong to the babel7 group definition.

babel7 is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of nyc is breaking the build 🚨


🚨 Reminder! Less than one month left to migrate your repositories over to Snyk before Greenkeeper says goodbye on June 3rd! πŸ’œ πŸššπŸ’¨ πŸ’š

Find out how to migrate to Snyk at greenkeeper.io


The devDependency nyc was updated from 15.0.1 to 15.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

nyc is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

Commits

The new version differs by 5 commits.

  • de7baa4 chore(release): 15.1.0
  • 992359a feat(experimental): Support using --all with node.js ESM (#1320)
  • 086fd20 chore: Regenerate package-lock, update source-map-support test (#1314)
  • b20f751 chore: add bugs (used, e.g., by npmjs) (#1313)
  • 6898e88 chore: Fix CHANGELOG.md version header

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of codecov is breaking the build 🚨

The devDependency codecov was updated from 3.6.4 to 3.6.5.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

codecov is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

Commits

The new version differs by 2 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

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.