Socket
Socket
Sign inDemoInstall

copy-json-file-merged

Package Overview
Dependencies
6
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    copy-json-file-merged

Copies source JSON file and merges its contents with destination JSON file if present.


Version published
Weekly downloads
4
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

0.2.1 (2018-02-28)

  • Libraries are upgraded.
  • More Node.js versions are added to Travis CI config.

Readme

Source

copy-json-file-merged

npm version Build Status Coverage Status

Copies source JSON file and merges its contents with destination JSON file if present.

Installation

npm install copy-json-file-merged --save

Usage

In code:

var copyJsonFileMerged = require('copy-json-file-merged');
copyJsonFileMerged('src.json', 'dest.json', {
    overwrite: true,
    mergeKey: 'id'
});

From CLI:

./node_modules/.bin/copy-json-file-merged src.json dest.json --overwrite --mergeKey id

From package.json's scripts:

{
  "scripts": {
    "copy": "copy-json-file-merged src.json dest.json --overwrite --mergeKey id"
  }
}

API

copyJsonFileMerged function accepts three arguments:

  • src — path to source JSON file (must exist);
  • dest — path to destination JSON file (can exist);
  • options — object of properties (optional):
    • mergeKey — a key (property) to merge nested objects and arrays by (see merge arrays uniting their object items by specified identifier field), by default is id;

    • overwrite — shows whether source object should overwrite destination one (if it exists), by default is false; alternatively, an array of top-level properties' names of source JSON object can be passed to limit sections of destination JSON file to overwrite, e.g.:

      src.json

      {
        "obj1": { "merged": true },
        "obj2": { "merged": true }
      }
      

      dest.json

      {
        "obj1": { "merged": false },
        "obj2": { "merged": false }
      }
      
      copyJsonFileMerged('src.json', 'dest.json', {
          overwrite: ['obj1']
      }); // => { "obj1": { "merged": true }, "obj2": { "merged": false } }
      

Building

In order to build library run:

npm run build

Testing

Run unit tests:

npm test

In order to run tests with coverage run the following command:

npm run test:coverage

In order to run tests with Coveralls locally you have to provide COVERALLS_REPO_TOKEN:

COVERALLS_REPO_TOKEN=<token> npm run test:coveralls

Contribution

Before making a pull request, please, be sure that your changes are rebased to develop branch.

License

MIT

Keywords

FAQs

Last updated on 28 Feb 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc