API Reference

devalue

Serializes JavaScript values including Map, Set, Date, and cyclic references into an XSS-safe string.

Official Documentation ↗
CompatibilityThis documentation covers version v6.0.3. Check the official docs for the latest API surface.

Installation

npmnpm install devalue

Methods

devalue strands cyclical structures into a string that can be embedded in HTML and parsed back.

Key Features

  • Handles Map, Set, Date, RegExp, and BigInt
  • Preserves cyclic references
  • Escapes HTML-sensitive characters

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Security notes

Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/Rich-Harris/devalue@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:14.898Z.

FAQ

Why not JSON.stringify?
JSON.stringify drops Map and Set, turns Date into a string, and breaks on cycles. devalue preserves these and escapes HTML-sensitive characters.
Is devalue safe to embed in a script tag?
Yes. It escapes characters that could close a script tag, preventing XSS when injecting serialized state into HTML.
Does devalue support cyclic objects?
Yes. It assigns indices to references, so self-referential graphs round-trip correctly.