sveltejs/devalue
TL;DR. devalue is JSON serialization for real JavaScript state: cycles, weird primitives, rich built-ins, custom types, and even promises.
Takeaways
- Built for cases where
JSON.stringifybreaks: circular/repeated refs,undefined,NaN,BigInt,Map,Set, typed arrays, URLs, Temporal, and custom classes. - Useful when shipping server data to client code, especially in Svelte-ish environments where compact, XSS-aware serialization matters.
- Two modes:
unevalemits compact JS code, whilestringify/parseavoideval;stringifyAsyncalso awaits promises before serializing. - Non-obvious constraint: serialization format is not stable across versions, so don’t serialize with one version and parse with another.
- Source type: GitHub repository
- Title: sveltejs/devalue
- URL: https://github.com/sveltejs/devalue