sindresorhus/stringify-object

Can't disable indentation completely

Opened this issue · 5 comments

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';

It was an intentional decision. Why do you need to disable indentation?

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.

Interesting use-case. I never thought of using this for anything other than presentation. PR welcome :)

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, '');