segmented-property

A utility for immutably setting and getting properties on JavaScript objects as slash-delimited paths.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
segmented-property
003.0.32 years ago6 years agoMinified + gzip package size for segmented-property in KB

Readme

segmented-property
A utility for immutably setting and getting properties on JavaScript objects as slash-delimited paths.
npm install segmented-property

npm version

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.