2.1.1 • Published 5 years ago

simply-immutable v2.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

simply-immutable

ZERO dependencies! FAST! See the benchmarks. Minimal object changes on updates. Type safety for CRUD operations in TypeScript. Immutable in - immutable out: deep clones incoming objects/arrays for safety.

cloneImmutable

Deep clone of an object/array. Returns a deeply frozen clone.

cloneMutable

Deep clone of an object/array. Does not freeze anything in the result, so this is a good way to remove immutability.

shallowCloneMutable

Shallow clone of an object/array. First level of the result is not frozen.

replaceImmutable

Replaces object/array fields in the target object/array. Deep compare on replacing object to minimally change structure. Creates intermediate objects/arrays as necessary.

updateImmutable

Merges object/array fields into the target object/array. Deep compare on updating object fields to minimally change structure. Creates intermediate objects/arrays as necessary.

deepUpdateImmutable

Merges object/array fields into the target object/array; merging happens recursively (unlike updateImmutable, which only merges at the first level). Merging after the first level only happens on objects, not arrays. Deep compare on updating object fields to minimally change structure. Creates intermediate objects/arrays as necessary.

deleteImmutable

Removes target field.

incrementImmutable

Adds to an existing numeric value. If the target value is not a number then it is treated as 0. obj = incrementImmutable(obj, ['foo', 'count'], 1);

arrayPushImmutable

Adds new values to the end of an array. If the target is not an array then it will be replaced by a new array with only the new values in it. obj = arrayPushImmutable(obj, ['foo', 'vals'], 'newVal1', 'newVal2');

arrayPopImmutable

Removes the last value from the end of an array. If the target is not an array then it will be replaced by an empty array. obj = arrayPopImmutable(obj, ['foo', 'vals']);

arrayUnshiftImmutable

Adds new values to the front of an array. If the target is not an array then it will be replaced by a new array with only the new values in it. obj = arrayUnshiftImmutable(obj, ['foo', 'vals'], 'newVal1', 'newVal2');

arrayShiftImmutable

Removes the first value from the front of an array. If the target is not an array then it will be replaced by an empty array. obj = arrayShiftImmutable(obj, ['foo', 'vals']);

arrayConcatImmutable

Adds an array of new values to the end of an array. If the target is not an array then it will be replaced by a new array with only the new values in it. obj = arrayConcatImmutable(obj, ['foo', 'vals'], ['newVal1', 'newVal2']);

arraySliceImmutable

Works just like Array.slice(). If the target is not an array then it will be replaced by an empty array. obj = arraySliceImmutable(obj, ['foo', 'vals'], 2, -1); obj = arraySliceImmutable(obj, ['foo', 'vals'], 1);

arraySpliceImmutable

Works just like Array.splice(). If the target is not an array then it will be replaced by a new array with only the new values in it. If the target is not an array then it will be replaced by an empty array. This function is much preferable to replaceImmutable for arrays when the change operations are known, because replaceImmutable diffs by array index so a deleted or inserted value will break diffing. arraySpliceImmutable does not have this problem. obj = arraySpliceImmutable(obj, ['foo', 'vals'], 3, 1, 'insertedVal');

diffImmutable

Given two objects/arrays, generates a diff that can be applied to the second parameter (using applyDiffImmutable) to get the first parameter.

applyDiffImmutable

Applies a diff generated by diffImmutable. Works almost the same as deepUpdateImmutable, except that nested arrays are also merged.

filterImmutable

Filters out members of an object/array based on a filter function.

mapImmutable

Remaps members of an object/array based on a callback function.

deepFreeze

Recursively freezes an object/array and all children.

isFrozen

Checks if an object/array is frozen.

isDeepFrozen

Recursively checks if object/array and all children are frozen.

freezeImmutableStructures

Enables or disables deep freezing of the outputs of the *Immutable functions. Enabled by default, but recommended to turn off in production builds (benchmarks have deep freezing turned off).

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago