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

Commit

Permalink
fix: support for Infinity && NaN (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-livingston authored and michael-ciniawsky committed Jul 12, 2017
1 parent ebb370d commit 5a8ca43
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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();
});
});

0 comments on commit 5a8ca43

Please sign in to comment.