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

fix: support for Infinity && NaN #26

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/

import util from 'util';
import JSON5 from 'json5';

function Json5Loader(source) {
Expand All @@ -13,7 +15,7 @@ function Json5Loader(source) {
throw new Error('Error parsing JSON5', (e));
}

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

export default Json5Loader;
14 changes: 13 additions & 1 deletion test/json5-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe(PROJECT_NAME, () => {

test('should convert to requires', (done) => {
const content = Json5Loader.call({}, staticJson5);
expect(content).toBe('module.exports = {\n\t"name": "test"\n}');
expect(content).toBe('module.exports = { name: \'test\' }');
done();
});

Expand All @@ -22,4 +22,16 @@ describe(PROJECT_NAME, () => {
}).toThrow('Error parsing JSON5');
done();
});

test('should preserve Infinity', (done) => {
const content = Json5Loader.call({}, '{to : Infinity}');
expect(content).toBe('module.exports = { to: Infinity }');
done();
});

test('should preserve NaN', (done) => {
const content = Json5Loader.call({}, '{nan : NaN}');
expect(content).toBe('module.exports = { nan: NaN }');
done();
});
});