-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add content to parser and safeParser API reference on website
- Loading branch information
1 parent
3e14db4
commit 07cf66b
Showing
58 changed files
with
486 additions
and
4 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
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
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 |
---|---|---|
@@ -1,10 +1,120 @@ | ||
--- | ||
title: parser | ||
description: Returns a function that parses an unknown input based on a schema. | ||
source: /methods/parser/parser.ts | ||
contributors: | ||
- fabian-hiller | ||
--- | ||
|
||
import { ApiList, Property } from '~/components'; | ||
import { properties } from './properties'; | ||
|
||
# parser | ||
|
||
> The content of this page is not yet ready. Until then, please use the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/methods/parser/parser.ts) or take a look at [issue #287](https://github.com/fabian-hiller/valibot/issues/287) to help us extend the API reference. | ||
Returns a function that parses an unknown input based on a schema. | ||
|
||
```ts | ||
const parser = v.parser<TSchema, TConfig>(schema, config); | ||
``` | ||
|
||
## Generics | ||
|
||
- `TSchema` <Property {...properties.TSchema} /> | ||
- `TConfig` <Property {...properties.TConfig} /> | ||
|
||
## Parameters | ||
|
||
- `schema` <Property {...properties.schema} /> | ||
- `config` <Property {...properties.config} /> | ||
|
||
## Returns | ||
|
||
- `parser` <Property {...properties.parser} /> | ||
|
||
## Example | ||
|
||
The following example show how `parser` can be used. | ||
|
||
```ts | ||
try { | ||
const EmailSchema = v.pipe(v.string(), v.email()); | ||
const emailParser = v.parser(EmailSchema); | ||
const email = emailParser('[email protected]'); | ||
|
||
// Handle errors if one occurs | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
``` | ||
|
||
## Related | ||
|
||
The following APIs can be combined with `parser`. | ||
|
||
### Schemas | ||
|
||
<ApiList | ||
items={[ | ||
'any', | ||
'array', | ||
'bigint', | ||
'blob', | ||
'boolean', | ||
'custom', | ||
'date', | ||
'enum', | ||
'file', | ||
'function', | ||
'instance', | ||
'intersect', | ||
'lazy', | ||
'literal', | ||
'looseObject', | ||
'looseTuple', | ||
'map', | ||
'nan', | ||
'never', | ||
'nonNullable', | ||
'nonNullish', | ||
'nonOptional', | ||
'null', | ||
'nullable', | ||
'nullish', | ||
'number', | ||
'object', | ||
'objectWithRest', | ||
'optional', | ||
'picklist', | ||
'promise', | ||
'record', | ||
'set', | ||
'strictObject', | ||
'strictTuple', | ||
'string', | ||
'symbol', | ||
'tuple', | ||
'tupleWithRest', | ||
'undefined', | ||
'union', | ||
'unknown', | ||
'variant', | ||
'void', | ||
]} | ||
/> | ||
|
||
### Methods | ||
|
||
<ApiList | ||
items={[ | ||
'config', | ||
'fallback', | ||
'flatten', | ||
'keyof', | ||
'omit', | ||
'partial', | ||
'pick', | ||
'pipe', | ||
'required', | ||
'unwrap', | ||
]} | ||
/> |
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,78 @@ | ||
import type { PropertyProps } from '~/components'; | ||
|
||
export const properties: Record<string, PropertyProps> = { | ||
TSchema: { | ||
modifier: 'extends', | ||
type: { | ||
type: 'custom', | ||
name: 'BaseSchema', | ||
href: '../BaseSchema/', | ||
generics: [ | ||
'unknown', | ||
'unknown', | ||
{ | ||
type: 'custom', | ||
name: 'BaseIssue', | ||
href: '../BaseIssue/', | ||
generics: ['unknown'], | ||
}, | ||
], | ||
}, | ||
}, | ||
TConfig: { | ||
modifier: 'extends', | ||
type: { | ||
type: 'union', | ||
options: [ | ||
{ | ||
type: 'custom', | ||
name: 'Config', | ||
href: '../Config/', | ||
generics: [ | ||
{ | ||
type: 'custom', | ||
name: 'InferIssue', | ||
href: '../InferIssue/', | ||
generics: [ | ||
{ | ||
type: 'custom', | ||
name: 'TSchema', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
'undefined', | ||
], | ||
}, | ||
}, | ||
schema: { | ||
type: { | ||
type: 'custom', | ||
name: 'TSchema', | ||
}, | ||
}, | ||
config: { | ||
type: { | ||
type: 'custom', | ||
name: 'TConfig', | ||
}, | ||
}, | ||
parser: { | ||
type: { | ||
type: 'custom', | ||
name: 'Parser', | ||
href: '../Parser/', | ||
generics: [ | ||
{ | ||
type: 'custom', | ||
name: 'TSchema', | ||
}, | ||
{ | ||
type: 'custom', | ||
name: 'TConfig', | ||
}, | ||
], | ||
}, | ||
}, | ||
}; |
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
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
Oops, something went wrong.