set-new

1.0.0 • Public • Published

set-new

Build Status Test Coverage

Set value and return new object without mutating the original object.

INSTALLATION

npm install set-new --save

USAGE

With object:

const set = require('set-new');
const source = { some: { nested: 'object' };
 
const result = set(source, ['some', 'nested'], 'changed');
 
source.some.nested === 'object'; // true
result.some.nested === 'changed'; // true
 
const another = set(result, 'some.nested', 'another');
 
result.some.nested === 'changed'; // true
another.some.nested === 'another'; // true

With array:

const set = require('set-new');
const source = ['some', ['nested', ['array']]];
 
const result = set(source, [1, 1], 'changed');
 
source[1][1] === 'object'; // true
result[1][1] === 'changed'; // true
 
const another = set(result, '1.1', 'another');
 
result[1][1] === 'changed'; // true
another[1][1] === 'another'; // true

Readme

Keywords

none

Package Sidebar

Install

npm i set-new

Weekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • arch-mage