File tree 3 files changed +28
-4
lines changed
3 files changed +28
-4
lines changed Original file line number Diff line number Diff line change 1
1
exports . parse = exports . decode = decode
2
+
2
3
exports . stringify = exports . encode = encode
3
4
4
5
exports . safe = safe
5
6
exports . unsafe = unsafe
6
7
7
- var eol = typeof process !== 'undefined' && process . platform === 'win32' ? '\r\n' : '\n'
8
+ var eol = typeof process !== 'undefined' &&
9
+ process . platform === 'win32' ? '\r\n' : '\n'
8
10
9
11
function encode ( obj , opt ) {
10
12
var children = [ ]
@@ -82,7 +84,7 @@ function decode (str) {
82
84
return
83
85
}
84
86
var key = unsafe ( match [ 2 ] )
85
- var value = match [ 3 ] ? unsafe ( ( match [ 4 ] || '' ) ) : true
87
+ var value = match [ 3 ] ? unsafe ( match [ 4 ] ) : true
86
88
switch ( value ) {
87
89
case 'true' :
88
90
case 'false' :
@@ -186,7 +188,7 @@ function unsafe (val, doUnesc) {
186
188
if ( esc ) {
187
189
unesc += '\\'
188
190
}
189
- return unesc
191
+ return unesc . trim ( )
190
192
}
191
193
return val
192
194
}
Original file line number Diff line number Diff line change 10
10
"main" : " ini.js" ,
11
11
"scripts" : {
12
12
"pretest" : " standard ini.js" ,
13
- "test" : " tap test/*.js"
13
+ "test" : " tap test/*.js --100 "
14
14
},
15
15
"engines" : {
16
16
"node" : " *"
Original file line number Diff line number Diff line change
1
+ var t = require ( 'tap' )
2
+ Object . defineProperty ( process , 'platform' , { value : 'win32' } )
3
+ const ini = require ( '../ini.js' )
4
+
5
+ const res = ini . encode ( { foo : { bar : 'baz' } } )
6
+ t . equal ( res , "[foo]\r\nbar=baz\r\n" )
7
+
8
+ t . equal ( ini . encode ( { bar : 'baz' } , 'foo' ) , '[foo]\r\nbar=baz\r\n' )
9
+
10
+ t . same ( ini . decode ( '=just junk!\r\n[foo]\r\nbar\r\n' ) ,
11
+ { foo : { bar : true } } )
12
+
13
+ t . same ( ini . decode ( '[x]\r\ny=1\r\ny[]=2\r\n' ) , {
14
+ x : {
15
+ y : [ 1 , 2 ]
16
+ }
17
+ } )
18
+
19
+ t . equal ( ini . unsafe ( '' ) , '' )
20
+ t . equal ( ini . unsafe ( 'x;y' ) , 'x' )
21
+ t . equal ( ini . unsafe ( 'x # y' ) , 'x' )
22
+ t . equal ( ini . unsafe ( 'x "\\' ) , 'x "\\' )
You can’t perform that action at this time.
0 commit comments