Skip to content
This repository was archived by the owner on Dec 22, 2020. It is now read-only.

Commit 5a8ca43

Browse files
fix: support for Infinity && NaN (#26)
1 parent ebb370d commit 5a8ca43

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5+
6+
import util from 'util';
57
import JSON5 from 'json5';
68

79
function Json5Loader(source) {
@@ -13,7 +15,7 @@ function Json5Loader(source) {
1315
throw new Error('Error parsing JSON5', (e));
1416
}
1517

16-
return `module.exports = ${JSON.stringify(value, null, '\t')}`;
18+
return `module.exports = ${util.inspect(value, { depth: null })}`;
1719
}
1820

1921
export default Json5Loader;

test/json5-loader.test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe(PROJECT_NAME, () => {
1111

1212
test('should convert to requires', (done) => {
1313
const content = Json5Loader.call({}, staticJson5);
14-
expect(content).toBe('module.exports = {\n\t"name": "test"\n}');
14+
expect(content).toBe('module.exports = { name: \'test\' }');
1515
done();
1616
});
1717

@@ -22,4 +22,16 @@ describe(PROJECT_NAME, () => {
2222
}).toThrow('Error parsing JSON5');
2323
done();
2424
});
25+
26+
test('should preserve Infinity', (done) => {
27+
const content = Json5Loader.call({}, '{to : Infinity}');
28+
expect(content).toBe('module.exports = { to: Infinity }');
29+
done();
30+
});
31+
32+
test('should preserve NaN', (done) => {
33+
const content = Json5Loader.call({}, '{nan : NaN}');
34+
expect(content).toBe('module.exports = { nan: NaN }');
35+
done();
36+
});
2537
});

0 commit comments

Comments
 (0)