Serializes objects for string-safe stashing in WebStorage, Cache, etc. Uses compact tagged strings (~n, ~t, ~u, ~y) by default for primitive types, or oneKey object envelopes when compact: false.
~n
~t
~u
~y
compact: false
The object to stringify
Optional
Optional serialization options (e.g. { signed: true, secret: 'key', compact: true })
{ signed: true, secret: 'key', compact: true }
The safely stringified representation
stringify(123n); // '"~n123"'stringify(new Date()); // '"~t1704067200000"'stringify(Symbol.for('app')); // '"~y@@(app)"'stringify(data, { signed: true, secret: 'my-secret' }); // '$sig:e8b7...:{"id":"~n123"}' Copy
stringify(123n); // '"~n123"'stringify(new Date()); // '"~t1704067200000"'stringify(Symbol.for('app')); // '"~y@@(app)"'stringify(data, { signed: true, secret: 'my-secret' }); // '$sig:e8b7...:{"id":"~n123"}'
Serializes objects for string-safe stashing in WebStorage, Cache, etc. Uses compact tagged strings (
~n,~t,~u,~y) by default for primitive types, or oneKey object envelopes whencompact: false.