segmented-property
v4.0.0
Published
A utility for immutably setting and getting properties on JavaScript objects as slash-delimited paths.
Downloads
9,010
Readme
segmented-property
A utility for immutably setting and getting properties on JavaScript objects as slash-delimited paths.
npm install segmented-property
Usage
import {get, set} from 'segmented-property'
const obj1 = {foo: {bar: 1}}
const obj2 = set(obj1, 'foo/bar', 2)
console.log(get(obj1, 'foo/bar')) // 1
console.log(get(obj2, 'foo/bar')) // 2
API
get(source, [key])
Gets a value.
set(source, [key], value)
Sets a new value and returns a new object.