-
Notifications
You must be signed in to change notification settings - Fork 163
String types are not preserved #277
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
Comments
Hi. Yes this is the default behavior as we try to keep native JSON types. I think we might support an option to opt-out from this feature but in the meantime you can use |
Line 35 in 95da940
The error is caused by the String(value) method in stringify. Should the behavior of stringify be consistent with JSON.stringify? String(): String('1') // '1'
String(true) // 'true'
String(null) // 'null'
String('[]') // '[]' JSON.stringify & JSON.parse : JSON.stringify('1') // '"1"'
JSON.stringify(true) // 'true'
JSON.stringify(null) // 'null'
JSON.stringify('[]') // '"[]"'
JSON.parse(JSON.stringify('1')) // '1'
JSON.parse(JSON.stringify(true)) // true
JSON.parse(JSON.stringify(null)) // null
JSON.parse(JSON.stringify('[]')) // '[]' idb-keyval: import { set, get } from 'idb-keyval'
await set('foo', '[]')
await get('foo') // '[]'
await set('bar', null)
await get('bar') // null Inconsistent behavior of String() and JSON.stringify() will lead to confusion, which makes it impossible to migrate directly from idb-keyval to unstorage I use jsonr to store the compressed json into storage. Because the value obtained by getItem is not the value originally stored, an error is reported. |
I tried using JSON.stringify to handle the string value, but this broke too many test cases |
Following up on #591, I think we can at least expose a new option for |
Uh oh!
There was an error while loading. Please reload this page.
Environment
nodejs
v1.8.0
Reproduction
Describe the bug
Storage convert string into number for no reason
EDIT:After investigation, it's probably due to destr
https://github.com/unjs/unstorage/blob/main/src/storage.ts#L173C9-L173C21
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: