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

String instances are transformed into objects #74

Open
iplanwebsites opened this issue Apr 12, 2022 · 0 comments
Open

String instances are transformed into objects #74

iplanwebsites opened this issue Apr 12, 2022 · 0 comments

Comments

@iplanwebsites
Copy link

Stumbled upon this one when attempting to use this library to normalize API outputs.
I'm not sure if it's an expected behavior.

stringify({ a: new String('hello') })
//    {"a":{"0":"h","1":"e","2":"l","3":"l","4":"o"}} 

While using JSON.stringify({ a: new String('hello') }) returns {"a":"hello"}.

String instances, created using new String() shouldn't usually be returned in place of strings, but some poor function in some codebases returns string instances using new String. For these cases, it'd be nice if the output would produce symmetrical rendering of Strings than JSON.stringify() for user looking for a drop-in replacement.

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

No branches or pull requests

1 participant