1.0.5 • Published 6 years ago

map-attack v1.0.5

Weekly downloads
110
License
UNLICENSED
Repository
github
Last release
6 years ago

map-attack

Turns Maps into Arrays, Turns Arrays into Maps

npm version dependencies Build Status

#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

1.0.5

6 years ago

1.0.4

6 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

8 years ago