File tree 2 files changed +5
-2
lines changed
2 files changed +5
-2
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
module . exports = stringify ;
4
- function stringify ( obj ) {
4
+ function stringify ( obj , indentation ) {
5
5
if ( obj instanceof Date ) {
6
6
return 'new Date(' + stringify ( obj . toISOString ( ) ) + ')' ;
7
7
}
8
8
if ( obj === undefined ) {
9
9
return 'undefined' ;
10
10
}
11
- return JSON . stringify ( obj )
11
+ return JSON . stringify ( obj , undefined , indentation )
12
12
. replace ( / \u2028 / g, '\\u2028' )
13
13
. replace ( / \u2029 / g, '\\u2029' )
14
14
. replace ( / < / g, '\\u003C' )
Original file line number Diff line number Diff line change @@ -7,6 +7,9 @@ assert(stringify('foo') === '"foo"');
7
7
assert ( stringify ( 'foo\u2028bar\u2029baz' ) === '"foo\\u2028bar\\u2029baz"' ) ;
8
8
assert ( stringify ( new Date ( '2014-12-19T03:42:00.000Z' ) ) === 'new Date("2014-12-19T03:42:00.000Z")' ) ;
9
9
assert ( stringify ( { foo : 'bar' } ) === '{"foo":"bar"}' ) ;
10
+ assert ( stringify ( { foo : 'bar' } , undefined ) === '{"foo":"bar"}' ) ;
11
+ assert ( stringify ( { foo : 'bar' } , 3 ) === '{\n "foo": "bar"\n}' ) ;
12
+ assert ( stringify ( { foo : 'bar' } , ' \t' ) === '{\n \t"foo": "bar"\n}' ) ;
10
13
assert ( stringify ( undefined ) === 'undefined' ) ;
11
14
assert ( stringify ( null ) === 'null' ) ;
12
15
assert (
You can’t perform that action at this time.
0 commit comments