Package Exports
- @strikeentco/set
- @strikeentco/set/main.js
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 (@strikeentco/set) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
set

One of the smallest (31 sloc) and most effective implementations of setting a nested value on an object.
Usage
$ npm install @strikeentco/set --save
const set = require('@strikeentco/set');
set({ a: { b: 'c' } }, 'a.b', 'd');
//=> { a: { b: 'd' } }
set({ a: { b: ['c', 'd'] } }, 'a.b.1', 'e');
//=> { a: { b: ['c', 'e'] } }
set({ a: { b: ['c', 'd'] } }, ['a', 'b'], 'c');
//=> { a: { b: 'c' } }
set({ a: { b: 'c' } }, 'a.b.c.d', 'e');
//=> { a: { b: { c: { d: 'e' } } } }
set({ a: { b: 'c' } }, 'a:b', 'd', ':');
//=> { a: { b: 'd' } }
API
set(obj, path, val, [separator])
Params:
- obj (Object) - Source object.
- path (String|Array) - String or array with path.
- val (Any) - Value to set.
- [separator] (String) -
.
by default.
License
The MIT License (MIT)
Copyright (c) 2018-present Alexey Bystrov