map-attack

1.0.5 • Public • Published

map-attack

Turns Maps into Arrays, Turns Arrays into Maps

npm version dependencies Build Status Pledge To Arupex!

Install

npm install map-attack --save

Usage

var mapAttack = require('map-attack');

mapAttack( Map||Array, indexByString)

Converting Array to Map

    mapAttack([
        {
            id : '1',
            value : 'hello'
        },
        {
            id : '2',
            value : 'world'
        },
        {
            id : '3',
            value : '!'
        }
    ],'id');

Result :

    //Results in a Map indexed by your second parameter
    {
         1 : {
             id : '1',
             value : 'hello'
         },
         2 : {
             id : '2',
             value : 'world'
         },
         3 : {
             id : '3',
             value : '!'
         }
     }

Converting Map to Array

    mapAttack({
           1 : {
               value : 'hello'
           },
           2 : {
               value : 'world'
           },
           3 : {
               value : '!'
           }
       }, 'id')

Result :

    //Results in a Array with ids by your second parameter
       [
            {
                id : '1',
                value : 'hello'
            },
            {
                id : '2',
                value : 'world'
            },
            {
                id : '3',
                value : '!'
            }
        ]

Notes:

This library uses:

deep-setter

deep-value

So any syntax those accept for setting/getting values from objects you can use for your index by parameter

Readme

Keywords

Package Sidebar

Install

npm i map-attack

Weekly Downloads

111

Version

1.0.5

License

UNLICENSED

Unpacked Size

19.3 kB

Total Files

8

Last publish

Collaborators

  • dirwin517