Skip to content

Commit 31054ca

Browse files
committed
doc: add jsdoc
1 parent 6053a6d commit 31054ca

File tree

28 files changed

+2244
-100
lines changed

28 files changed

+2244
-100
lines changed

README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,27 @@ Install your preferred validation library alongside `@hookform/resolvers`.
2828
<details>
2929
<summary>Resolver Comparison</summary>
3030

31-
| resolver | Infer values <br /> from schema |
32-
|---|---|
33-
| AJV ||
34-
| Arktype ||
35-
| class-validator ||
36-
| computed-types ||
37-
| Effect ||
38-
| fluentvalidation-ts ||
39-
| io-ts ||
40-
| joi ||
41-
| Nope ||
42-
| Standard Schema ||
43-
| Superstruct ||
44-
| typanion ||
45-
| typebox ||
46-
| typeschema ||
47-
| valibot ||
48-
| vest ||
49-
| vine ||
50-
| yup ||
51-
| zod ||
31+
| resolver | Infer values <br /> from schema | [criteriaMode](https://react-hook-form.com/docs/useform#criteriaMode) |
32+
|---|---|---|
33+
| AJV || `firstError | all` |
34+
| Arktype || `firstError` |
35+
| class-validator || `firstError | all` |
36+
| computed-types || `firstError` |
37+
| Effect || `firstError | all` |
38+
| fluentvalidation-ts || `firstError` |
39+
| io-ts || `firstError` |
40+
| joi || `firstError | all` |
41+
| Nope || `firstError` |
42+
| Standard Schema || `firstError | all` |
43+
| Superstruct || `firstError` |
44+
| typanion || `firstError` |
45+
| typebox || `firstError | all` |
46+
| typeschema || `firstError | all` |
47+
| valibot || `firstError | all` |
48+
| vest || `firstError | all` |
49+
| vine || `firstError | all` |
50+
| yup || `firstError | all` |
51+
| zod || `firstError | all` |
5252
</details>
5353

5454
## Links

ajv/src/ajv.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,26 @@ const parseErrorSchema = (
5858
return parsedErrors;
5959
};
6060

61+
/**
62+
* Creates a resolver for react-hook-form using Ajv schema validation
63+
* @param {Schema} schema - The Ajv schema to validate against
64+
* @param {Object} schemaOptions - Additional schema validation options
65+
* @param {Object} resolverOptions - Additional resolver configuration
66+
* @param {string} [resolverOptions.mode='async'] - Validation mode
67+
* @returns {Resolver<Schema>} A resolver function compatible with react-hook-form
68+
* @example
69+
* const schema = ajv.compile({
70+
* type: 'object',
71+
* properties: {
72+
* name: { type: 'string' },
73+
* age: { type: 'number' }
74+
* }
75+
* });
76+
*
77+
* useForm({
78+
* resolver: ajvResolver(schema)
79+
* });
80+
*/
6181
export const ajvResolver: Resolver =
6282
(schema, schemaOptions, resolverOptions = {}) =>
6383
async (values, _, options) => {

arktype/src/arktype.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,25 @@ function parseErrorSchema(arkErrors: ArkErrors): Record<string, FieldError> {
2020
return fieldsErrors;
2121
}
2222

23+
/**
24+
* Creates a resolver for react-hook-form using Arktype schema validation
25+
* @param {Schema} schema - The Arktype schema to validate against
26+
* @param {Object} resolverOptions - Additional resolver configuration
27+
* @param {string} [resolverOptions.mode='raw'] - Return the raw input values rather than the parsed values
28+
* @returns {Resolver<Schema['inferOut']>} A resolver function compatible with react-hook-form
29+
* @example
30+
* const schema = type({
31+
* username: 'string>2'
32+
* });
33+
*
34+
* useForm({
35+
* resolver: arktypeResolver(schema)
36+
* });
37+
*/
2338
export function arktypeResolver<Schema extends Type<any, any>>(
2439
schema: Schema,
2540
_schemaOptions?: never,
2641
resolverOptions: {
27-
/**
28-
* Return the raw input values rather than the parsed values.
29-
* @default false
30-
*/
3142
raw?: boolean;
3243
} = {},
3344
): Resolver<Schema['inferOut']> {

bun.lock

Lines changed: 1593 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bun.lockb

-321 KB
Binary file not shown.

class-validator/src/class-validator.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ function parseErrorSchema(
4242
}, parsedErrors);
4343
}
4444

45+
/**
46+
* Creates a resolver for react-hook-form using class-validator schema validation
47+
* @param {ClassConstructor<Schema>} schema - The class-validator schema to validate against
48+
* @param {Object} schemaOptions - Additional schema validation options
49+
* @param {Object} resolverOptions - Additional resolver configuration
50+
* @param {string} [resolverOptions.mode='async'] - Validation mode
51+
* @returns {Resolver<Schema>} A resolver function compatible with react-hook-form
52+
* @example
53+
* class Schema {
54+
* @Matches(/^\w+$/)
55+
* @Length(3, 30)
56+
* username: string;
57+
* age: number
58+
* }
59+
*
60+
* useForm({
61+
* resolver: classValidatorResolver(Schema)
62+
* });
63+
*/
4564
export function classValidatorResolver<Schema extends Record<string, any>>(
4665
schema: ClassConstructor<Schema>,
4766
schemaOptions: {

class-validator/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export * from './class-validator';
2-
export * from './types';

class-validator/src/types.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

computed-types/src/computed-types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ function parseErrorSchema(computedTypesError: ValidationError) {
1818
}, parsedErrors);
1919
}
2020

21+
/**
22+
* Creates a resolver for react-hook-form using computed-types schema validation
23+
* @param {Schema} schema - The computed-types schema to validate against
24+
* @returns {Resolver<Type<typeof schema>>} A resolver function compatible with react-hook-form
25+
* @example
26+
* const schema = Schema({
27+
* name: string,
28+
* age: number
29+
* });
30+
*
31+
* useForm({
32+
* resolver: computedTypesResolver(schema)
33+
* });
34+
*/
2135
export function computedTypesResolver<Schema extends FunctionType<any, any>>(
2236
schema: Schema,
2337
): Resolver<Type<typeof schema>> {

effect-ts/src/effect-ts.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ import {
99
appendErrors,
1010
} from 'react-hook-form';
1111

12+
/**
13+
* Creates a resolver for react-hook-form using Effect.ts schema validation
14+
* @param {Schema.Schema<TFieldValues, I>} schema - The Effect.ts schema to validate against
15+
* @param {ParseOptions} [schemaOptions] - Optional Effect.ts validation options
16+
* @returns {Resolver<Schema.Schema.Type<typeof schema>>} A resolver function compatible with react-hook-form
17+
* @example
18+
* const schema = Schema.Struct({
19+
* name: Schema.String,
20+
* age: Schema.Number
21+
* });
22+
*
23+
* useForm({
24+
* resolver: effectTsResolver(schema)
25+
* });
26+
*/
1227
export function effectTsResolver<TFieldValues extends FieldValues, I>(
1328
schema: Schema.Schema<TFieldValues, I>,
1429
schemaOptions: ParseOptions = { errors: 'all', onExcessProperty: 'ignore' },

0 commit comments

Comments
 (0)