1.1.2 • Published 7 years ago

simple-immutability-helpers v1.1.2

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

Simple helper functions for working with immutable data

Examples

Add item ( object, integer, string, bool etc. ) to an array:

const { addToArray } = require('simple-immutability-helpers');
const array = [1, 2, 3, 4];

const newArray = addToArray(array, 5)
// returns a new array containing [1, 2, 3, 4, 5]

Remove an item from an array

const { removeFromArray } = require('simple-immutability-helpers');
const array = [{ name: 'Jack' }, { name: 'Tom' }];

const newArray = removeFromArray(array, { name: 'Tom' })
//returns a new array, [{ name: 'Jack' }]

Clone an array

const { clone, cloneDeep } = require('simple-immutability-helpers');

const array = [1, 2, 3];
const clonedArray = clone(array)
//returns a new array, [1, 2, 3]

const nestedObject = { name: 'Jack', favoriteFood: ['Pizza', 'Steak'] }
const clonedNestedObject = cloneDeep(nestedObject);
//returns a deep clone of the object, { name: 'Jack', favoriteFood: ['Pizza', 'Steak'] }
1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago