segmented-property
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i segmented-property

Weekly Downloads

3,325

Version

4.0.0

License

MIT

Unpacked Size

30.5 kB

Total Files

14

Last publish

Collaborators

  • mariuslundgard