Skip to content

Commit f150de0

Browse files
committed
docs: add circularValue set to undefined example and improve readme
This adds an example in the changelog how `circularValue` impacts the output, if set to `undefined` and improves the readme by specifying the detailed behavior further.
1 parent 7472f80 commit f150de0

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@
22

33
## v2.2.0
44

5-
- Accept `undefined` as `circularValue` option to remove circular values from the serialized output
5+
- Accept `undefined` as `circularValue` option to remove circular properties from the serialized output:
6+
7+
```js
8+
import { configure } from 'safe-stable-stringify'
9+
10+
const object = { array: [] }
11+
object.circular = object;
12+
object.array.push(object)
13+
14+
configure({ circularValue: undefined })(object)
15+
// '{"array":[null]}'
16+
```
617

718
## v2.1.0
819

readme.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ stringify(circular, ['a', 'b'], 2)
4444

4545
* `bigint` {boolean} If `true`, bigint values are converted to a number. Otherwise
4646
they are ignored. **Default:** `true`.
47-
* `circularValue` {string|null|undefined} Define the value for circular
48-
references. Circular values are not serialized, if set to `undefined`.
49-
**Default:** `[Circular]`.
47+
* `circularValue` {string|null|undefined} Defines the value for circular
48+
references. Set to `undefined`, circular properties are not serialized (array
49+
entries are replaced with `null`). **Default:** `[Circular]`.
5050
* `deterministic` {boolean} If `true`, guarantee a deterministic key order
5151
instead of relying on the insertion order. **Default:** `true`.
5252
* `maximumBreadth` {number} Maximum number of entries to serialize per object
@@ -93,10 +93,10 @@ console.log(stringified)
9393

9494
## Differences to JSON.stringify
9595

96-
1. Replace circular structures with the string `[Circular]` (the value may be changed).
97-
1. Sorted keys instead of using the insertion order (it is possible to deactivate this).
98-
1. BigInt values are stringified as regular number instead of throwing a TypeError.
99-
1. Boxed primitives (e.g., `Number(5)`) are not unboxed and are handled as
96+
1. _Circular values_ are replaced with the string `[Circular]` (the value may be changed).
97+
1. _Object keys_ are sorted instead of using the insertion order (it is possible to deactivate this).
98+
1. _BigInt_ values are stringified as regular number instead of throwing a TypeError.
99+
1. _Boxed primitives_ (e.g., `Number(5)`) are not unboxed and are handled as
100100
regular object.
101101

102102
Those are the only differences to `JSON.stringify()`. This is a side effect free
@@ -105,8 +105,8 @@ with `JSON.stringify()`.
105105

106106
## Performance / Benchmarks
107107

108-
Currently this is by far the fastest known stable stringify implementation.
109-
This is especially important for big objects and TypedArrays.
108+
Currently this is by far the fastest known stable (deterministic) stringify
109+
implementation. This is especially important for big objects and TypedArrays.
110110

111111
(Dell Precision 5540, i7-9850H CPU @ 2.60GHz, Node.js 16.11.1)
112112

0 commit comments

Comments
 (0)