From 0c5675ff01df958571138b2a536c29fa113bb21e Mon Sep 17 00:00:00 2001 From: Nick Reiley Date: Thu, 12 Sep 2019 09:23:25 +0500 Subject: [PATCH] fix: strict comparison PR-URL: https://github.com/npm/stringify-package/pull/2 Credit: @bl00mber Close: #2 Reviewed-by: @isaacs --- index.js | 3 ++- test/nonformatted.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/nonformatted.js 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() +})