File tree Expand file tree Collapse file tree 6 files changed +2
-140
lines changed Expand file tree Collapse file tree 6 files changed +2
-140
lines changed Original file line number Diff line number Diff line change
1
+ - ** BREAKING:** Remove global ` spaces ` option.
1
2
- Added ` EOL ` override option to ` writeFile ` when using ` spaces ` . [ #89 ]
2
3
3
4
3.0.1 / 2017-07-05
Original file line number Diff line number Diff line change @@ -160,48 +160,6 @@ var obj = {name: 'JP'}
160
160
jsonfile .writeFileSync (file, obj, {flag: ' a' })
161
161
```
162
162
163
- ### spaces
164
-
165
- Global configuration to set spaces to indent JSON files.
166
-
167
- ** default:** ` null `
168
-
169
- ``` js
170
- var jsonfile = require (' jsonfile' )
171
-
172
- jsonfile .spaces = 4
173
-
174
- var file = ' /tmp/data.json'
175
- var obj = {name: ' JP' }
176
-
177
- // json file has four space indenting now
178
- jsonfile .writeFile (file, obj, function (err ) {
179
- console .error (err)
180
- })
181
- ```
182
-
183
- Note, it's bound to ` this.spaces ` . So, if you do this:
184
-
185
- ``` js
186
- var myObj = {}
187
- myObj .writeJsonSync = jsonfile .writeFileSync
188
- // => this.spaces = null
189
- ```
190
-
191
- Could do the following:
192
-
193
- ``` js
194
- var jsonfile = require (' jsonfile' )
195
- jsonfile .spaces = 4
196
- jsonfile .writeFileSync (file, obj) // will have 4 spaces indentation
197
-
198
- var myCrazyObj = {spaces: 32 }
199
- myCrazyObj .writeJsonSync = jsonfile .writeFileSync
200
- myCrazyObj .writeJsonSync (file, obj) // will have 32 space indentation
201
- myCrazyObj .writeJsonSync (file, obj, {spaces: 2 }) // will have only 2
202
- ```
203
-
204
-
205
163
License
206
164
-------
207
165
Original file line number Diff line number Diff line change @@ -78,10 +78,7 @@ function readFileSync (file, options) {
78
78
}
79
79
80
80
function stringify ( obj , options ) {
81
- // `jsonfile` and not `this` because people might destructure
82
- // and use `writeFile` instead of `fs.writeFile`, in which case
83
- // `this` would be `undefined`
84
- var spaces = jsonfile . spaces
81
+ var spaces
85
82
var EOL = '\n'
86
83
if ( typeof options === 'object' && options !== null ) {
87
84
if ( options . spaces ) {
@@ -134,7 +131,6 @@ function stripBom (content) {
134
131
}
135
132
136
133
var jsonfile = {
137
- spaces : null ,
138
134
readFile : readFile ,
139
135
readFileSync : readFileSync ,
140
136
writeFile : writeFile ,
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -34,35 +34,6 @@ describe('+ writeFileSync()', function () {
34
34
assert . equal ( data , '{"name":"JP"}\n' )
35
35
} )
36
36
37
- describe ( '> when global spaces is set' , function ( ) {
38
- it ( 'should write JSON with spacing' , function ( ) {
39
- var file = path . join ( TEST_DIR , 'somefile.json' )
40
- var obj = { name : 'JP' }
41
- jf . spaces = 2
42
- jf . writeFileSync ( file , obj )
43
-
44
- var data = fs . readFileSync ( file , 'utf8' )
45
- assert . equal ( data , '{\n "name": "JP"\n}\n' )
46
-
47
- // restore default
48
- jf . spaces = null
49
- } )
50
-
51
- it ( 'still uses global when context lost' , function ( ) {
52
- var file = path . join ( TEST_DIR , 'somefile.json' )
53
- var obj = { name : 'JP' }
54
- jf . spaces = 2
55
- var writeFileSync = jf . writeFileSync
56
- writeFileSync ( file , obj )
57
-
58
- var data = fs . readFileSync ( file , 'utf8' )
59
- assert . equal ( data , '{\n "name": "JP"\n}\n' )
60
-
61
- // restore default
62
- jf . spaces = null
63
- } )
64
- } )
65
-
66
37
describe ( '> when JSON replacer is set' , function ( ) {
67
38
it ( 'should replace JSON' , function ( ) {
68
39
var file = path . join ( TEST_DIR , 'somefile.json' )
Original file line number Diff line number Diff line change @@ -39,41 +39,6 @@ describe('+ writeFile()', function () {
39
39
} )
40
40
} )
41
41
42
- describe ( '> when global spaces is set' , function ( ) {
43
- it ( 'should write JSON with spacing' , function ( done ) {
44
- var file = path . join ( TEST_DIR , 'somefile.json' )
45
- var obj = { name : 'JP' }
46
- jf . spaces = 2
47
- jf . writeFile ( file , obj , function ( err ) {
48
- assert . ifError ( err )
49
-
50
- var data = fs . readFileSync ( file , 'utf8' )
51
- assert . equal ( data , '{\n "name": "JP"\n}\n' )
52
-
53
- // restore default
54
- jf . spaces = null
55
- done ( )
56
- } )
57
- } )
58
-
59
- it ( 'still uses global when context lost' , function ( done ) {
60
- var file = path . join ( TEST_DIR , 'somefile.json' )
61
- var obj = { name : 'JP' }
62
- jf . spaces = 2
63
- var writeFile = jf . writeFile
64
- writeFile ( file , obj , function ( err ) {
65
- assert . ifError ( err )
66
-
67
- var data = fs . readFileSync ( file , 'utf8' )
68
- assert . equal ( data , '{\n "name": "JP"\n}\n' )
69
-
70
- // restore default
71
- jf . spaces = null
72
- done ( )
73
- } )
74
- } )
75
- } )
76
-
77
42
describe ( '> when JSON replacer is set' , function ( ) {
78
43
it ( 'should replace JSON' , function ( done ) {
79
44
var file = path . join ( TEST_DIR , 'somefile.json' )
You can’t perform that action at this time.
0 commit comments