Surfacing additional JSON.stringify arguments in formats.json.stringify, and adding the json_spacing option to the File constructor.
This commit is contained in:
parent
b3699314cf
commit
6ce0b7aef3
2 changed files with 6 additions and 6 deletions
|
@ -14,8 +14,8 @@ var formats = exports;
|
|||
// Standard JSON format which pretty prints `.stringify()`.
|
||||
//
|
||||
formats.json = {
|
||||
stringify: function (obj) {
|
||||
return JSON.stringify(obj, null, 2)
|
||||
stringify: function (obj, replacer, spacing) {
|
||||
return JSON.stringify(obj, replacer || null, spacing || 2)
|
||||
},
|
||||
parse: JSON.parse
|
||||
};
|
||||
|
@ -25,4 +25,4 @@ formats.json = {
|
|||
// Standard INI format supplied from the `ini` module
|
||||
// http://en.wikipedia.org/wiki/INI_file
|
||||
//
|
||||
formats.ini = ini;
|
||||
formats.ini = ini;
|
||||
|
|
|
@ -29,6 +29,7 @@ var File = exports.File = function (options) {
|
|||
this.file = options.file;
|
||||
this.dir = options.dir || process.cwd();
|
||||
this.format = options.format || formats.json;
|
||||
this.json_spacing = options.json_spacing || 2;
|
||||
|
||||
if (options.search) {
|
||||
this.search(this.dir);
|
||||
|
@ -51,7 +52,7 @@ File.prototype.save = function (value, callback) {
|
|||
value = null;
|
||||
}
|
||||
|
||||
fs.writeFile(this.file, this.format.stringify(this.store), function (err) {
|
||||
fs.writeFile(this.file, this.format.stringify(this.store, null, this.json_spacing), function (err) {
|
||||
return err ? callback(err) : callback();
|
||||
});
|
||||
};
|
||||
|
@ -65,7 +66,7 @@ File.prototype.save = function (value, callback) {
|
|||
//
|
||||
File.prototype.saveSync = function (value) {
|
||||
try {
|
||||
fs.writeFileSync(this.file, this.format.stringify(this.store));
|
||||
fs.writeFileSync(this.file, this.format.stringify(this.store, null, this.json_spacing));
|
||||
}
|
||||
catch (ex) {
|
||||
throw(ex);
|
||||
|
@ -224,4 +225,3 @@ File.prototype.search = function (base) {
|
|||
|
||||
return fullpath;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue