Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't disable indentation completely #52

Open
andybarron opened this issue Sep 29, 2017 · 5 comments
Open

Can't disable indentation completely #52

andybarron opened this issue Sep 29, 2017 · 5 comments

Comments

@andybarron
Copy link

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
Copy link
Member

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

@andybarron
Copy link
Author

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
Copy link
Member

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

@sindresorhus sindresorhus changed the title can't disable indentation completely Can't disable indentation completely Oct 2, 2017
@PowerKiKi
Copy link

According to #47 (comment), this should be rejected, or alternatively #47 should be revived. Which one would it be ?

@cimak
Copy link

cimak commented Feb 25, 2021

workaround:

const opts = {
     indent: new String(''),
};
const code = stringifyObject(obj, opts).replace(/\n/g, '');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants