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

advance-json-merge

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

advance-json-merge

[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php) [![npm version](https://badge.fury.io/js/advance-json-merge.svg)](https://badge.fury.io/js/advance-json-merge)

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12
Maintainers
1
Weekly downloads
 
Created
Source

advance-json-merge

MIT Licence npm version

Advance json merge

  • written in Typescript
  • combination Object.assign method
  • can merge with any level

Installation

Node.js / Browserify

npm install advance-json-merge --save
var advanceMerge = require('advance-json-merge');

Global object

Include the pre-built script.

<script src="./dist/index.umd.min.js"></script>

usage


var { mergeWithLevel } = require('advance-json-merge');
const origin = {
      e: {
        a: {
          c: 'o_c',
          d: 'o_d'
        },
        b: {
          e: 'o_e'
        },
        c: {
          h: 'o_h'
        },
        d: {
          j: 'o_j'
        }
      },
      f: 1
    };
const target = {
      e: {
        a: {
          a: 't_a'
        },
        b: {
          e: 't_e',
          f: 't_f'
        },
        d: 2
      },
      f: {
        a: {},
        b: {
          c: 't_c',
          h: 't_h'
        }
      }
    };

// level 0 merge
    const result = mergeWithLevel(origin, target, 0);
    expect(result).toEqual(target);

// level 1 merge
    const result = mergeWithLevel(origin, target, 1);
    expect(result).toEqual(Object.assign({}, origin, target));

// level 2 merge
    const result = mergeWithLevel(origin, target, 2);
    expect(result).toEqual({
      e: {
        a: {
          a: 't_a'
        },
        b: {
          e: 't_e',
          f: 't_f'
        },
        c: {
          h: 'o_h'
        },
        d: 2
      },
      f: {
        a: {},
        b: {
          c: 't_c',
          h: 't_h'
        }
      }
    });

// level 3+ merge
    const levelNum = chance.integer({ min: 3, max: 1000 });
    const result = mergeWithLevel(origin, target, levelNum);
    expect(result).toEqual({
      e: {
        a: {
          a: 't_a',
          c: 'o_c',
          d: 'o_d'
        },
        b: {
          e: 't_e',
          f: 't_f'
        },
        c: {
          h: 'o_h'
        },
        d: 2
      },
      f: {
        a: {},
        b: {
          c: 't_c',
          h: 't_h'
        }
      }
    });  

Build & test

npm run build
npm test

document

npm run doc

then open the generated out/index.html file in your browser.

License

MIT.

FAQs

Package last updated on 16 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

  • 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