Skip to content

Commit

Permalink
docs: add example usage of throwOnLimitExceeded for arrayLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
IamLizu committed Nov 17, 2024
1 parent c5e0117 commit af3a625
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,18 @@ var withArrayLimit = qs.parse('a[1]=b', { arrayLimit: 0 });
assert.deepEqual(withArrayLimit, { a: { '1': 'b' } });
```

If you want to throw an error whenever the array limit is exceeded, set the `throwOnLimitExceeded` option to `true`. This option will generate a descriptive error if the query string exceeds a configured limit.
```javascript
try {
qs.parse('a[1]=b', { arrayLimit: 0, throwOnLimitExceeded: true });
} catch (err) {
assert(err instanceof Error);
assert.strictEqual(err.message, 'Array limit exceeded. Only 0 array members allowed.');
}
```

When `throwOnLimitExceeded` is set to `false` (default), **qs** will parse up to the specified `arrayLimit` and ignore the rest without throwing an error.

To disable array parsing entirely, set `parseArrays` to `false`.

```javascript
Expand Down

0 comments on commit af3a625

Please sign in to comment.