nbubna / store

A better way to use localStorage and sessionStorage
MIT License
1.91k stars 110 forks source link

Q: Is there any way to bypass JSON.stringfy on .set() #111

Closed Davinasc closed 2 years ago

Davinasc commented 2 years ago

Hello 😄 great lib! Have been using this lib for some time now and it's working wonders, now we're dealing with a scenario where setting a string value set('value') and it's been a bit hard to not add double quotes at both ends of the string.

Is there a way to bypass JSON.stringfy on .set() or to use replace function to overwrite this behavior?

Thank you

nbubna commented 2 years ago

I'm not sure i understand the context for your question.

So far as avoiding stringification goes, you can always just not use the library and do: localStorage.setItem("key", "value") directly. You will still be able to get that value out using store("key"), because the parsing is set up to return raw strings when JSON.parse fails on the value.

Davinasc commented 2 years ago

Thanks 🙃 avoiding stringification is exactly what is needed. The thing is that for some reason (99.99% my fault) am not being able to use localStorage.setItem directly, but i'll try again!

nbubna commented 2 years ago

Mind if i ask what the use case for this is? Do you need to interact with some other consumer of localStorage or something?

As long as this library has been out there, no one has asked to avoid stringification before.

Davinasc commented 2 years ago

In our case, we got some MFEs including some old ones that need to consume it from localstorage directly. The main issue is that we don't want to touch this big monster heheh