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

handling "htmlized" objects #68

Closed
renatodeleao opened this issue Dec 26, 2019 · 2 comments
Closed

handling "htmlized" objects #68

renatodeleao opened this issue Dec 26, 2019 · 2 comments

Comments

@renatodeleao
Copy link

renatodeleao commented Dec 26, 2019

Hello!
this might be a weird usecase but, for a request inspector UI i am building and "htmlized" output of the responses, not only for some simple styling but also for interactive purposes. The result is then appended to a dom node. A simplified version can be described as bellow

{
  "key": 123,
  "<span>specialKey</span>": "<a role='button'>specialValue</a>"
}

The package still works, but keys are being treated as required for "quotify" probably due the special html chars used. Is it out of scope of the package to include a condition to strip quotes from htmlized keys?

At the moment i'm striping quotes with some regex but not sure how battle tested this is and therefore if something like this could be included. Also other beautifiers output the same result as yours so i expect that this might not be trivial.

Thanks for the package anyways,
Keep shipping :shipit:

@sindresorhus
Copy link
Member

It wouldn't strip quotes as stringify-object is the one adding the quotes. We could have an option to just not quote object keys, but what if the key is foo bar? I assume you would want <span>"foo bar"</span>: and not <span>foo bar</span>:, as the latter is invalid JS when the HTML is rendered. So leaving out the quotes is not a good way to solve this problem.

We could potentially add a hook that lets you wrap certain things like object keys.

@renatodeleao
Copy link
Author

renatodeleao commented May 9, 2020

Hey, a lot went on after this, sry for the delay.
So yes your assumptions are correct.

I think it's safe to close this issue, as this seem to be an edge case specific derived from a UI decision on the project i was workin on and not relevant feature for the package purpose anyways. If i recall it correctly, i did the risky regex thing after the stringify process, since it was particular case, not a generic thing.

Thanks for the time to answer ✌

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

2 participants