diff --git a/index.js b/index.js index 0cc9de0..cd291f2 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,8 @@ const CRLF = '\r\n' const LF = '\n' function stringifyPackage (data, indent, newline) { - const json = JSON.stringify(data, null, indent || DEFAULT_INDENT) + indent = indent || (indent === 0 ? 0 : DEFAULT_INDENT) + const json = JSON.stringify(data, null, indent) if (newline === CRLF) { return json.replace(/\n/g, CRLF) + CRLF diff --git a/test/nonformatted.js b/test/nonformatted.js new file mode 100644 index 0000000..b7372fe --- /dev/null +++ b/test/nonformatted.js @@ -0,0 +1,11 @@ +'use strict' + +const stringifyPackage = require('../index') +const test = require('tap').test + +const dummy = { name: 'dummy' } + +test('stringify-package', function (t) { + t.equal(stringifyPackage(dummy, 0).split(/\r\n|\r|\n/).length, 2, '0 works') + t.end() +})