jsonscore
v0.1.0
Published
edit json file with underscore chain method
Downloads
22
Readme
JSONscore
Edit json file with underscore.js chain method
Installation
$ npm install jsonscore
Usage
var jsonscore = require('jsonscore');
/*
* alter metadata json file in the root directory
* addnew and filter two new json object
*/
var metadata = jsonscore('metadata.json', {
// default json file content value
defaultValue: [],
// json file encoding
encoding: 'utf8',
// format json with replacer function
replacer: null,
// number of space between json object
space: 4
})
.extend({
compile_sass: {
run: false,
time: 1405213450
},
minify_js: {
run: true,
time: 1405213454
}
})
.filter(function(task) {
return task.run ? false : true;
})
.write();
console.log(metadata);
Using lodash
instead of default underscore
library
var jsonscore = require('jsonscore');
var _ = require('lodash');
jsonscore('metadata.json', {
engine: _
}).extend(obj).write();
Custom mixin methods
var jsonscore = require('jsonscore');
var _ = require('underscore');
_.mixin({
filterWith: [Function]
});
jsonscore('metadata.json', {
engine: _
}).filterWith(obj).write();
API
jsonscore(filepath, [, options]) return an underscore chain method
- filepath String
- options Object
- defaultValue [Array|Object] | [] default = []
- engine Function | _ default = _
- encoding String | Null default = 'utf8'
- replacer Function | Null default = null JSON format replacer paramter
- space: Number | Null default = null JSON format space paramter
write() write json object back into file return json data
Authors
License
Licensed under the GPL license.