Skip to content

Commit

Permalink
improve undefined handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Bessonov committed Apr 22, 2024
1 parent a9759d6 commit 7e5166c
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 140 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,16 @@ router.addRoute({

Validators set expectations on the input and convert values. Currently, they work with `RegExpPathnameMatcher`, `EndpointMatcher`, and `QueryStringMatcher`. The following validators are available:

Validator | Array | Value | Description
----------------|-------|-------|------------
`trueVal` | ✓ | ✓ | It's a wildcard validator mainly used for optional parameters.
`requiredVal` | ✓ | ✓ | Validator to mark required parameters.
`getNthVal` | ✓ | | Returns the n-th element of an array. A negative value returns the element counting from the end of the array.
`mapToNumVal` | ✓ | | Ensures that a string array can be converted to a number array.
`toNumVal` | | ✓ | Ensures that a single value can be converted to a number.
`atLeastOneVal` | ✓ | | Filters the passed values based on the listed options. If `undefined` is included in the option list, it indicates that the passed value is optional.
`oneOfVal` | | ✓ | Ensures that the passed value is one of the listed options.
`minCountVal` | ✓ | | Ensures that the passed array has a minimal length.
Validator | Array | Value | Ignores `undefined` | Description
----------------|-------|-------|---------------------|------------
`trueVal` | ✓ | ✓ | ✓ | It's a wildcard validator mainly used for optional parameters.
`requiredVal` | ✓ | ✓ | | Validator to mark required parameters.
`getNthVal` | ✓ | | ✓ | Returns the n-th element of an array. A negative value returns the element counting from the end of the array.
`mapToNumVal` | ✓ | | ✓ | Ensures that a string array can be converted to a number array.
`toNumVal` | | ✓ | ✓ | Ensures that a single value can be converted to a number.
`atLeastOneVal` | ✓ | | With `undefined` | Filters the passed values based on the listed options. If `undefined` is included in the option list, it indicates that the passed value is optional.
`oneOfVal` | | ✓ | ✓ | Ensures that the passed value is one of the listed options.
`minCountVal` | ✓ | | | Ensures that the passed array has a minimal length.

Validators can be chained with the `chain` function.

Expand Down
137 changes: 80 additions & 57 deletions dist/__tests__/validators.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7e5166c

Please sign in to comment.