Skip to content

Commit f25b2c4

Browse files
committed
Modified write and writeSync to accept replacer and space argument (just as JSON.stringify does)
1 parent 9f84103 commit f25b2c4

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lib/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@ File.prototype._processJson = function(json) {
4444
this.indent = determineWhitespace(json);
4545
};
4646

47-
File.prototype.write = function(callback) {
48-
var json = JSON.stringify(this.data, null, this.indent);
47+
File.prototype.write = function(callback, replacer, space) {
48+
var space = space || this.indent,
49+
json = JSON.stringify(this.data, replacer, space);
4950
fs.writeFile(this.path, json, callback);
5051
};
5152

52-
File.prototype.writeSync = function() {
53-
var json = JSON.stringify(this.data, null, this.indent);
53+
File.prototype.writeSync = function(replacer, space) {
54+
var space = space || this.indent,
55+
json = JSON.stringify(this.data, replacer, space);
5456
fs.writeFileSync(this.path, json);
5557
};
5658

@@ -97,6 +99,6 @@ function determineWhitespace(contents) {
9799
whitespace = match[1].length;
98100
}
99101
}
100-
}
102+
}z
101103
}
102104

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-file",
3-
"version": "0.0.0",
3+
"version": "0.1.0",
44
"description": "A module for modifiying JSON files",
55
"main": "lib/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)