0.2.1 • Published 8 years ago
copy-json-file-merged v0.2.1
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 --saveUsage
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 idFrom 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 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** ```json { "obj1": { "merged": true }, "obj2": { "merged": true } } ``` **dest.json** ```json { "obj1": { "merged": false }, "obj2": { "merged": false } } ``` ```javascript copyJsonFileMerged('src.json', 'dest.json', { overwrite: ['obj1'] }); // => { "obj1": { "merged": true }, "obj2": { "merged": false } } ```
Building
In order to build library run:
npm run buildTesting
Run unit tests:
npm testIn order to run tests with coverage run the following command:
npm run test:coverageIn order to run tests with Coveralls locally you have to provide COVERALLS_REPO_TOKEN:
COVERALLS_REPO_TOKEN=<token> npm run test:coverallsContribution
Before making a pull request, please, be sure that your changes are rebased to develop branch.