Skip to content

Commit

Permalink
docs: fix opts argument and embed code sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenrui committed Oct 16, 2023
1 parent f0bc181 commit b3e06ad
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions docs/pages/docs/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ Then you can create your own validators such as validators for `email`, `minLeng
</Callout>

```js
const email = string.create((value: string, { message }: { message?: string } = {}) => {
const email = string.create((value: string, opts: { message?: string } = {}) => {
if (!value.includes("@"))
throw new Error(message ?? "Invalid email");
throw new Error(opts.message ?? "Invalid email");
});

const minLength = string.create((value: string, minLength: number, opts: { message?: string } = {}) => {
if (value.length < minLength)
throw new Error(message ?? `Must be at least ${minLength} characters`);
throw new Error(opts.message ?? `Must be at least ${minLength} characters`);
});

const maxLength = string.create((value: string, maxLength: number, opts: { message?: string } = {}) => {
if (value.length > maxLength)
throw new Error(message ?? `Must be at most ${maxLength} characters`);
throw new Error(opts.message ?? `Must be at most ${maxLength} characters`);
});
```
Expand All @@ -66,3 +66,7 @@ try {
console.log(error.message); // Must be at least 3 characters
}
```
## Code Sandbox Example
<iframe style={{ border: '1px solid rgba(0, 0, 0, 0.1)', borderRadius: '2px' }} width="800" height="450" src="https://codesandbox.io/p/sandbox/cevali-example-k7ttt9?embed=1" allowfullscreen></iframe>

0 comments on commit b3e06ad

Please sign in to comment.