Skip to content

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ipath

Build Status

Ensure immutability by updating javascript objects using a path similar to CSS/jQuery selector, great for react/redux applications where immutability is required, especially when working with deeply nested objects.

documetation

Install

npm i -S ipath

Usage

import { update } from 'ipath';

const obj = {
  artists: [
    {
      id: 3,
      name: 'A1',
      albums: [
        { id: 1, name: 'a1', year: 1990 },
        { id: 2, name: 'a2', year: 1995 },
      ]
    }
  ]
};

let newObj = update(obj, 'artists[id=3].albums[name=a2].year', 1992);
// obj doesn't change, newObj.artists[0].albums[1].year = 1992

let newAlbum = { id: 3, name: 'a3', year: 2000 }
newObj = update(obj, 'artists[0].albums[]', newAlbum);
// add newAlbum to the albums list

newObj = update(obj, 'artists[id=3].albums[name=a2]', null);
// delete an item from array

newObj = update({ a: { b: 1 } }, 'a.b', x => x + 1);
// calculate the new value based on the existing value

About

Ensure immutability by updating javascript objects using a path similar to CSS/jQuery selector, great for react/redux applications where immutability is required, especially when working with deeply nested objects.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages