Can't disable indentation completely
Opened this issue · 5 comments
andybarron commented
empty strings are treated as falsey and ignored.
to fix, this line:
opts.indent = opts.indent || '\t';
could look something like this:
opts.indent = (typeof opts.indent == 'string') ? opts.indent : '\t';
sindresorhus commented
It was an intentional decision. Why do you need to disable indentation?
andybarron commented
because of lack of quotes, resulting output can be much smaller than JSON.stringify
(pre-populating redux state on the server in a script tag), which saves bandwidth and reduces time to first render. but forcing indentation nullifies that advantage.
sindresorhus commented
Interesting use-case. I never thought of using this for anything other than presentation. PR welcome :)
PowerKiKi commented
According to #47 (comment), this should be rejected, or alternatively #47 should be revived. Which one would it be ?
cimak commented
workaround:
const opts = {
indent: new String(''),
};
const code = stringifyObject(obj, opts).replace(/\n/g, '');