Immutable object manipulation methods
Library can be installed via npm.
$ npm install typescript-object-utils
import{shallowEquals}from"typescript-object-utils";shallowEquals({a: 1,b: 2},{a: 1,b: 2});//=> trueimport{merge}from"typescript-object-utils";constx={a: 1,b: 2};consty={b: 2,c: 3};constr=merge(x,y);r;//=> { a: 1, b: 2, c: 3 }consts=merge(x,x);s;//=> {a: 1, b: 2}x===s;//=> falseimport{shallowMerge}from"typescript-object-utils";constx={a: 1,b: 2,c: 3};consty={c: 5,d: 4};constz={a: 1,b: 2};constr=shallowMerge(x,y);r;//=> { a: 1, b: 2, c: 5, d: 4 }consts=shallowMerge(x,x);s;//=> { a: 1, b: 2, c: 3 }x===s;//=> trueconstt=shallowMerge(x,z);t;//=> { a: 1, b: 2, c: 3 }x===t;//=> trueimport{mergeDeep}from"typescript-object-utils";constx={a: 1,b: {c: 3}};consty={b: {c: 3,d: 4}};constz={b: {c: 3}};constr=mergeDeep(x,y);r;//=> { a: 1, b: { c: 3, d: 4 }}consts=mergeDeep(x,z);s;//=> { a: 1, b: { c: 3 }}x===s;//=> falseimport{shallowMergeDeep}from"typescript-object-utils";constx={a: 1,b: {c: 3}};consty={b: {c: 3,d: 4}};constz={b: {c: 3}};constr=shallowMergeDeep(x,y);r;//=> { a: 1, b: { c: 3, d: 4 }}consts=shallowMergeDeep(x,z);s;//=> { a: 1, b: { c: 3 }}x===s;//=> trueimport{objectMap}from"typescript-object-utils";constobj={a: 1,b: 2};objectMap(obj,v=>String(v*2))//=> { a: '2', b: '4' }import{objectReduce}from"typescript-object-utils";constobj={a: 1,b: 2};objectReduce(obj,(acc,v)=>acc+v,0)//=> 3