Skip to content

Commit 6d7ceac

Browse files
committed
Improve README
1 parent 0f4c080 commit 6d7ceac

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

README.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,17 @@ Object with the following properties.
7777
_Type_: `number`\
7878
_Default_: `Number.POSITIVE_INFINITY` (no maximum size)
7979

80-
Maximum `JSON.stringify(value).length`. Additional properties beyond the size
81-
limit [are omitted](#big-output).
80+
Big JSON strings can make a process, filesystem operation or network request
81+
crash. `maxSize` prevents it by setting a maximum
82+
`JSON.stringify(value).length`.
83+
84+
Additional properties beyond the size limit [are omitted](#big-output). They are
85+
completely removed, not truncated (including strings).
86+
87+
```js
88+
const input = { one: true, two: 'a'.repeat(1e6) }
89+
JSON.stringify(safeJsonValue(input, { maxSize: 1e5 }).value) // '{"one":true}"
90+
```
8291

8392
### Return value
8493

@@ -134,7 +143,8 @@ _Type_: `string`
134143
Reason for the change among:
135144

136145
- [Exceptions](#exceptions): [`"unsafeCycle"`](#cycles),
137-
[`"unsafeException"`](#infinite-recursion), [`"unsafeBigInt"`](#bigint),
146+
[`"unsafeBigInt"`](#bigint), [`"unsafeSize"`](#big-output),
147+
[`"unsafeException"`](#infinite-recursion),
138148
[`"unsafeToJSON"`](#exceptions-in-tojson),
139149
[`"unsafeGetter"`](#exceptions-in-getters)
140150
- [Invalid descriptors](#invalid-descriptors):
@@ -149,7 +159,6 @@ Reason for the change among:
149159
[`"ignoredArrayProperty"`](#array-properties)
150160
- [Unresolved values](#unresolved-values): [`"unresolvedToJSON"`](#tojson),
151161
[`"unresolvedClass"`](#classes), [`"unresolvedGetter"`](#getters)
152-
- [Big output](#big-output): [`"unsafeSize"`](#big-output)
153162

154163
##### changes[*].error
155164

@@ -195,6 +204,14 @@ JSON.stringify(input) // Throws due to BigInt
195204
JSON.stringify(safeJsonValue(input).value) // '{"one":true}"
196205
```
197206

207+
### Big output
208+
209+
```js
210+
const input = { one: true, two: '\n'.repeat(5e8) }
211+
JSON.stringify(input) // Throws due to max string length
212+
JSON.stringify(safeJsonValue(input).value) // '{"one":true}"
213+
```
214+
198215
### Exceptions in `toJSON()`
199216

200217
```js
@@ -440,19 +457,6 @@ JSON.parse(JSON.stringify(input)) // { one: true }
440457
safeJsonValue(input).value // { one: true }
441458
```
442459

443-
## Big output
444-
445-
Big JSON strings can make a process, filesystem operation or network request
446-
crash.
447-
448-
When using the [`maxSize` option](#maxsize), properties that are too large are
449-
omitted. Large values (including strings) are completely removed, not truncated.
450-
451-
```js
452-
const input = { one: true, two: 'a'.repeat(1e6) }
453-
JSON.stringify(safeJsonValue(input, { maxSize: 1e5 }).value) // '{"one":true}"
454-
```
455-
456460
# Support
457461

458462
For any question, _don't hesitate_ to [submit an issue on GitHub](../../issues).

src/main.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
*/
44
export interface Options {
55
/**
6-
* Maximum `JSON.stringify(value).length`.
6+
* Big JSON strings can make a process, filesystem operation or network
7+
* request crash.
8+
* `maxSize` prevents it by setting a maximum `JSON.stringify(value).length`.
9+
*
710
* Additional properties beyond the size limit are omitted.
11+
* They are completely removed, not truncated (including strings).
812
*
913
* @default Number.POSITIVE_INFINITY (no maximum size)
1014
*

0 commit comments

Comments
 (0)