|
1 | 1 | 'use strict' |
2 | 2 |
|
3 | 3 | const stringify = main() |
| 4 | + |
4 | 5 | stringify.configure = main |
| 6 | +stringify.stringify = stringify |
| 7 | + |
5 | 8 | stringify.default = stringify |
6 | 9 |
|
| 10 | +exports.stringify = stringify |
| 11 | +exports.configure = main |
| 12 | + |
7 | 13 | module.exports = stringify |
8 | 14 |
|
9 | 15 | // eslint-disable-next-line |
@@ -122,30 +128,20 @@ function getCircularValueOption (options) { |
122 | 128 | return circularValue === undefined ? '"[Circular]"' : circularValue |
123 | 129 | } |
124 | 130 |
|
125 | | -function getBigIntOption (options) { |
126 | | - if (options && Object.prototype.hasOwnProperty.call(options, 'bigint')) { |
127 | | - var bigint = options.bigint |
128 | | - if (typeof bigint !== 'boolean') { |
129 | | - throw new TypeError('The "bigint" argument must be of type boolean') |
130 | | - } |
131 | | - } |
132 | | - return bigint === undefined ? true : bigint |
133 | | -} |
134 | | - |
135 | | -function getDeterministicOption (options) { |
136 | | - if (options && Object.prototype.hasOwnProperty.call(options, 'deterministic')) { |
137 | | - var deterministic = options.deterministic |
138 | | - if (typeof deterministic !== 'boolean') { |
139 | | - throw new TypeError('The "deterministic" argument must be of type boolean') |
| 131 | +function getBooleanOption (options, key) { |
| 132 | + if (options && Object.prototype.hasOwnProperty.call(options, key)) { |
| 133 | + var value = options[key] |
| 134 | + if (typeof value !== 'boolean') { |
| 135 | + throw new TypeError(`The "${key}" argument must be of type boolean`) |
140 | 136 | } |
141 | 137 | } |
142 | | - return deterministic === undefined ? true : deterministic |
| 138 | + return value === undefined ? true : value |
143 | 139 | } |
144 | 140 |
|
145 | 141 | function main (options) { |
146 | 142 | const circularValue = getCircularValueOption(options) |
147 | | - const bigint = getBigIntOption(options) |
148 | | - const deterministic = getDeterministicOption(options) |
| 143 | + const bigint = getBooleanOption(options, 'bigint') |
| 144 | + const deterministic = getBooleanOption(options, 'deterministic') |
149 | 145 |
|
150 | 146 | // Full version: supports all options |
151 | 147 | function stringifyFullFn (key, parent, stack, replacer, spacer, indentation) { |
@@ -480,9 +476,9 @@ function main (options) { |
480 | 476 | if (arguments.length > 1) { |
481 | 477 | let spacer = '' |
482 | 478 | if (typeof space === 'number') { |
483 | | - spacer = ' '.repeat(space) |
| 479 | + spacer = ' '.repeat(Math.min(space, 10)) |
484 | 480 | } else if (typeof space === 'string') { |
485 | | - spacer = space |
| 481 | + spacer = space.slice(0, 10) |
486 | 482 | } |
487 | 483 | if (replacer != null) { |
488 | 484 | if (typeof replacer === 'function') { |
|
0 commit comments