diff --git a/src/index.js b/src/index.js index efe0454..d654d95 100644 --- a/src/index.js +++ b/src/index.js @@ -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) { @@ -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; diff --git a/test/json5-loader.test.js b/test/json5-loader.test.js index 75d9e3f..e1199fb 100644 --- a/test/json5-loader.test.js +++ b/test/json5-loader.test.js @@ -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(); }); @@ -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(); + }); });