copy-json-file-merged
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 = ;;
From CLI:
./node_modules/.bin/copy-json-file-merged src.json dest.json --overwrite --mergeKey id
From package.json's scripts:
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 isid
; -
overwrite
— shows whether source object should overwrite destination one (if it exists), by default isfalse
; 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
dest.json
; // => { "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.