Socket
Book a DemoInstallSign in
Socket

merge-objects-values

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

merge-objects-values

## Installation

2.0.0
latest
Source
npmnpm
Version published
Weekly downloads
13
333.33%
Maintainers
1
Weekly downloads
 
Created
Source

merge-objects-values

Installation

yarn add merge-objects-values OR npm i --save merge-objects-values

Usage

const merge = require("merge-objects-values");

// Simple merge
const object1 = { foo: 2 };
const object2 = { foo: 4 };

merge(null, object1, object2); // { foo: 6 }

// It merge recursively, so you can make the sum of sub-objects
const object3 = { foo: { bar: 2 } };
const object4 = { foo: { bar: 4 } };
const object5 = { foo: { bar: 6 } };

merge(null, object3, object4, object5); // { foo: { bar: 12 } }

// You can disable deep merge
const object6 = { foo: { bar: 2 } };
const object7 = { foo: { bar: 4 } };

merge({ deep: false }, object6, object7); // { foo: { bar: 4 } }

// You can apply transformer on number
const object8 = { foo: 10, bar: 3 };
const object9 = { foo: 2, bar: 9 };

merge({ number: (a, b) => a * b }, object8, object9); // { foo: 20, bar: 27 }

// You can apply transformer on string
const object10 = { bar: "oui" };
const object11 = { bar: "non" };
merge({ string: (a, b) => `${a} - ${b}` }, object10, object11); // { bar: "oui - non" }

The first param is the config, and all the next params are objects you want to merge.

config :

  • deep Boolean, default true
  • string Function
  • number Function

FAQs

Package last updated on 23 May 2019

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.