Skip to content

arupex/map-attack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Turns Maps into Arrays, Turns Arrays into Maps

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published