Skip to content

mleko/typescript-object-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

typescript-object-utils

Immutable object manipulation methods

NPM Build 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";
const x = {a: 1, b: 2};
const y = {b: 2, c: 3};

const r = merge(x, y); r;
 //=> { a: 1, b: 2, c: 3 }
 
const s = merge(x, x); s;
 //=> {a: 1, b: 2}
x === s;
 //=> false

shallowMerge

import {shallowMerge} from "typescript-object-utils";
const x = {a: 1, b: 2, c: 3};
const y = {c: 5, d: 4};
const z = {a: 1, b: 2};

const r = shallowMerge(x, y); r;
 //=> { a: 1, b: 2, c: 5, d: 4 }

const s = shallowMerge(x, x); s;
 //=> { a: 1, b: 2, c: 3 }
x === s;
 //=> true

const t = shallowMerge(x, z); t;
 //=> { a: 1, b: 2, c: 3 }
x === t;
 //=> true

mergeDeep

import {mergeDeep} from "typescript-object-utils";
const x = {a: 1, b: {c: 3}};
const y = {b: {c: 3, d: 4}};
const z = {b: {c: 3}};

const r = mergeDeep(x, y); r;
 //=> { a: 1, b: { c: 3, d: 4 } }
 
const s = mergeDeep(x, z); s;
 //=> { a: 1, b: { c: 3 } }
x === s;
 //=> false

shallowMergeDeep

import {shallowMergeDeep} from "typescript-object-utils";
const x = {a: 1, b: {c: 3}};
const y = {b: {c: 3, d: 4}};
const z = {b: {c: 3}};

const r = shallowMergeDeep(x, y); r;
 //=> { a: 1, b: { c: 3, d: 4 } }
 
const s = shallowMergeDeep(x, z); s;
 //=> { a: 1, b: { c: 3 } }
x === s;
 //=> true

objectMap

import {objectMap} from "typescript-object-utils";
const obj = {a: 1, b: 2};

objectMap(obj, v => String(v*2))
 //=> { a: '2', b: '4' }

objectMap

import {objectReduce} from "typescript-object-utils";
const obj = {a: 1, b: 2};

objectReduce(obj, (acc, v) => acc + v, 0)
 //=> 3

Releases

No releases published

Packages

No packages published