-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Options | ||
|
||
## Default options | ||
|
||
You can set options for the validator. | ||
|
||
```ts | ||
import { validate, setLocales, setOptions } from "robust-validator"; | ||
import en from "robust-validator/dist/i18n/en.json"; | ||
|
||
setLocales(en); | ||
|
||
// Setting the default options | ||
setOptions({ | ||
stopOnFail: true, | ||
language: "en", | ||
}); | ||
``` | ||
|
||
## Active options | ||
|
||
You can override the default options for a validate action like the following example: | ||
|
||
```ts | ||
import { validate, setLocales, setOptions } from "robust-validator"; | ||
import en from "robust-validator/dist/i18n/en.json"; | ||
|
||
setLocales(en); | ||
|
||
// Setting the default options | ||
setOptions({ | ||
stopOnFail: true, | ||
language: "en", | ||
}); | ||
|
||
await validate( | ||
data, | ||
{ email: "required" }, | ||
{ stopOnFail: false, language: "de" }, // Override | ||
); | ||
``` |