Fork of safe-stable-stringify with an ESM fix.
This is a fork of BridgeAR/safe-stable-stringify incorporating some minor fixes that I needed in other projects:
- Support direct-to-browser ESM imports. (Fixes an upstream issue from 2022.)
- Drop the CJS export.
- Match upstream 3.0.0 serialization behavior, including
"[Circular: N]"markers with ancestor depth starting at 0 for the root. The 3.0.0 release adopts upstream's breaking changes. - Port to TypeScript.
- Repository project template aligned with kitschpatrol/create-project. (Massive diff, but simplifies management on my end.)
Please see the upstream readme for more details and documentation.
Add it to your project:
npm install @kitschpatrol/safe-stable-stringifyPerformance tracks upstream.
As tested on an Apple M3 Max + Node.js 26:
Values show the throughput of @kitschpatrol/safe-stable-stringify vs. the upstream safe-stable-stringify. 1.00× means equal throughput; higher means this repo is faster.
| Task | Simple object | Circular | Deep | Deep circular |
|---|---|---|---|---|
| Simple | 1.01× | 1.02× | 1.00× | 1.01× |
| Function replacer | 0.99× | 0.99× | 1.00× | 0.97× |
| Array replacer | 0.99× | 1.00× | 0.98× | 0.99× |
| Function replacer with indentation | 0.99× | 0.98× | 0.98× | 0.99× |
| Array replacer with indentation | 1.00× | 1.00× | 1.00× | 0.98× |
| Indentation | 1.01× | 0.99× | 0.97× | 0.99× |
Values show the throughput of @kitschpatrol/safe-stable-stringify relative to each named implementation. 1.00× means equal throughput; higher means this repo is faster.
| Compared with | Relative speed |
|---|---|
fast-json-stable-stringify |
0.99× |
fast-safe-stringify |
1.13× |
fast-stable-stringify |
0.92× |
faster-stable-stringify |
1.03× |
fastest-stable-stringify |
0.91× |
json-stable-stringify |
1.31× |
json-stringify-deterministic |
1.43× |
safe-stable-stringify (upstream) |
1.00× |
The original implementation was created by Ruben Bridgewater.
The upstream project is sponsored by MaibornWolff and nearForm.