@pomgui/deep
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Deep

Ultra small footprint merge & freeze methods.

deepMerge

This method is like assign except that it recursively merges own and inherited enumerable string keyed properties of source objects into the destination object. Source properties that resolve to undefined are skipped if a destination value exists. Array and plain object properties are merged recursively. Other objects and value types are overridden by assignment. Source objects are applied from left to right. Subsequent sources overwrite property assignments of previous sources.

For the most cases it is compatible with lodash.merge package.

deepFreeze

This method executes an recursive Object.freeze.

Installation

Using npm:

$ {sudo -H} npm i -g npm
$ npm i --save @pomgui/deep

In Node.js:

var { deepMerge } = require('@pomgui/deep');

With typescript:

import { deepMerge } from '@pomgui/deep';

Usage

deepMerge

const object = {
  'a': [{ 'b': 2 }, { 'd': 4 }]
}
const other = {
  'a': [{ 'c': 3 }, { 'e': 5 }]
}
deepMerge(object, other)
// => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }

### deepFreeze

const frozen = deepFreeze(obj);
// frozen === obj

const frozenArr = deepFreeze(obj1, obj2, obj3);
// frozenArr[0] === obj1
// frozenArr[1] === obj2
// frozenArr[2] === obj3

Package Sidebar

Install

npm i @pomgui/deep

Weekly Downloads

8

Version

1.1.0

License

MIT

Unpacked Size

6.44 kB

Total Files

9

Last publish

Collaborators

  • wpomier