Skip to content

Repository files navigation

typescript-object-utils

Immutable object manipulation methods

NPMBuild Status

Installation

Library can be installed via npm.

$ npm install typescript-object-utils

Examples

shallowEquals

import{shallowEquals}from"typescript-object-utils";shallowEquals({a: 1,b: 2},{a: 1,b: 2});//=> true

merge

import{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;//=> false

shallowMerge

import{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;//=> true

mergeDeep

import{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;//=> false

shallowMergeDeep

import{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;//=> true

objectMap

import{objectMap}from"typescript-object-utils";constobj={a: 1,b: 2};objectMap(obj,v=>String(v*2))//=> { a: '2', b: '4' }

objectMap

import{objectReduce}from"typescript-object-utils";constobj={a: 1,b: 2};objectReduce(obj,(acc,v)=>acc+v,0)//=> 3

About

Immutable object manipulation helper methods

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages