JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 86
  • Score
    100M100P100Q79745F
  • License MIT

Non-destructively set a nested property, given its path

Package Exports

  • @f/set-prop

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@f/set-prop) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

set-prop

Build status Git tag NPM version Code style

Non-destructively set a nested property, given its path

Installation

$ npm install @f/set-prop

Usage

var setProp = require('@f/set-prop')
var obj = {a: {b: 1}}
var newObj = setProp('a.b', obj, 2)

obj.a.b === 1
newObj.a.b === 2
obj !== newObj

API

setProp(path, obj, value)

  • path - The path (specified as array or dotted string) of the property you wish to set
  • obj - The root object you want to set within
  • value - The value you want to assign to path within obj

Returns: A new root obj that has path changed to value, and all of the sub-objects in its tree cloned as well.

License

MIT