Skip to content
Open
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
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ function configure (options) {
if (arguments.length > 1) {
let spacer = ''
if (typeof space === 'number') {
spacer = ' '.repeat(Math.min(space, 10))
spacer = ' '.repeat(Math.max(0, Math.min(space, 10)))
} else if (typeof space === 'string') {
spacer = space.slice(0, 10)
}
Expand Down
9 changes: 9 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,15 @@ test('maximum spacer length', function (assert) {
assert.end()
})

test('negative spacer length', function (assert) {
const input = { a: 0 }
// A negative number means no indentation, same as JSON.stringify (not a throw).
assert.equal(stringify(input, null, -1), JSON.stringify(input, null, -1))
assert.equal(stringify(input, null, -1e5), JSON.stringify(input, null, -1e5))
assert.equal(stringify(input, null, -Infinity), JSON.stringify(input, null, -Infinity))
assert.end()
})

test('indent properly; regression test for issue #16', function (assert) {
const o = {
collections: {},
Expand Down