Skip to content

Commit

Permalink
Added options doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ozziest committed Dec 23, 2023
1 parent 03c8c3f commit 79b25f1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default defineConfig({
items: [
{ text: "Rules", link: "/rules" },
{ text: "i18n", link: "/i18n" },
{ text: "Options", link: "/options" },
],
},
],
Expand Down
41 changes: 41 additions & 0 deletions docs/options.md
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
);
```

0 comments on commit 79b25f1

Please sign in to comment.