Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

deeply

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deeply

Deeply merges properties of the provided objects, returns untangled copy (clone)

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1K
decreased by-7.31%
Maintainers
1
Weekly downloads
 
Created
Source

Deeply Build Status Dependency Status

Javascript (Node + Browser) library that deeply merges properties of the provided objects, returns untangled copy (clone).

Install

Node

$ npm install deeply

Ender

$ ender add deeply --use=your_ender_file

Usage

merge

– Deeply merges two or more objects.

Node:

var merge = require('deeply');

merge({a: {a1: 1}}, {a: {a2: 2}}); // -> {a: {a1: 1, a2: 2}}

Ender:

$.merge({a: {a1: 1}}, {a: {a2: 2}}); // -> {a: {a1: 1, a2: 2}}

clone

– As degenerated case of merging one object on itself, it's possible to use deeply as deep clone function.

Node:

var merge = require('deeply')
  , clone = merge
  ;

var x = {a: {b: {c: 1}}};
var y = clone(x);

y.a.b.c = 2;

console.log(x.a.b.c); // -> 1

Ender:

var clone = $.merge;
var x = {a: {b: {c: 1}}};
var y = clone(x);

y.a.b.c = 2;

console.log(x.a.b.c); // -> 1

Arrays custom merging

– By default array treated as primitive values and being replaced upon conflict, for more meaningful array merge strategy, provide custom reduce function as last argument.

Node:

var merge = require('deeply');

// default behavior

merge({ a: { b: [0, 2, 4] }}, { a: {b: [1, 3, 5] }}); // -> { a: { b: [1, 3, 5] }}

// custom merge function

function customMerge(a, b)
{
  return (a||[]).concat(b);
}

merge({ a: { b: [0, 2, 4] }}, { a: {b: [1, 3, 5] }}, customMerge); // -> { a: { b: [0, 2, 4, 1, 3, 5] }}

Ender:


// default behavior

$.merge({ a: { b: [0, 2, 4] }}, { a: {b: [1, 3, 5] }}); // -> { a: { b: [1, 3, 5] }}

// custom merge function

function customMerge(a, b)
{
  return (a||[]).concat(b);
}

$.merge({ a: { b: [0, 2, 4] }}, { a: {b: [1, 3, 5] }}, customMerge); // -> { a: { b: [0, 2, 4, 1, 3, 5] }}

More examples can be found in test/index.js.

License

Deeply is licensed under the MIT license.

Keywords

FAQs

Package last updated on 03 Sep 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc