formik-validator-zod 2.0.1 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -18
- package/dist/index.js +9 -1
- package/package.json +4 -1
- package/jsr.json +0 -6
package/README.md
CHANGED
|
@@ -3,37 +3,25 @@
|
|
|
3
3
|
Allows you to easily validate [Formik](https://github.com/jaredpalmer/formik)
|
|
4
4
|
forms with the power of [Zod](https://github.com/colinhacks/zod) schemas.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
[dynamic import](https://v8.dev/features/dynamic-import) function
|
|
9
|
-
this package.
|
|
6
|
+
As of v2.0, this package uses ESM and no longer provides a CommonJS export. If
|
|
7
|
+
this is something you need, you should be able to use the
|
|
8
|
+
[dynamic import](https://v8.dev/features/dynamic-import) function.
|
|
10
9
|
|
|
11
10
|
## Installation
|
|
12
11
|
|
|
13
|
-
This package is published both on [NPM](https://www.npmjs.com) and
|
|
14
|
-
[JSR](https://jsr.io/).
|
|
15
|
-
|
|
16
12
|
To install from NPM:
|
|
17
13
|
|
|
18
14
|
```sh
|
|
19
15
|
npm install formik-validator-zod
|
|
20
16
|
|
|
17
|
+
pnpm add formik-validator-zod
|
|
18
|
+
|
|
21
19
|
yarn add formik-validator-zod
|
|
22
20
|
|
|
23
21
|
bun add formik-validator-zod
|
|
24
22
|
```
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
```sh
|
|
29
|
-
npx jsr add @glazy/formik-validator-zod
|
|
30
|
-
|
|
31
|
-
yarn dlx jsr add @glazy/formik-validator-zod
|
|
32
|
-
|
|
33
|
-
bunx jsr add @glazy/formik-validator-zod
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Example
|
|
24
|
+
## Usage
|
|
37
25
|
|
|
38
26
|
```jsx
|
|
39
27
|
import { Formik } from 'formik'
|
|
@@ -54,3 +42,12 @@ const MyForm = () => {
|
|
|
54
42
|
)
|
|
55
43
|
}
|
|
56
44
|
```
|
|
45
|
+
|
|
46
|
+
## Is this library still maintained?
|
|
47
|
+
|
|
48
|
+
Yes! This library is used in a couple of production codebases that I'm aware of,
|
|
49
|
+
including my current employers.
|
|
50
|
+
|
|
51
|
+
I don't expect the library will need a lot of active maintenance going forwards.
|
|
52
|
+
This is due to its limited scope and the fact Formik itself seems to be
|
|
53
|
+
abandoned.
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import merge from 'deepmerge';
|
|
1
2
|
/**
|
|
2
3
|
* Allows you to easily use Zod schemas with the <Formik /> component `validate`
|
|
3
4
|
* prop.
|
|
@@ -11,7 +12,14 @@ export const withZodSchema = (schema, params) => (values) => {
|
|
|
11
12
|
if (result.success)
|
|
12
13
|
return {};
|
|
13
14
|
return result.error.issues.reduce((acc, curr) => {
|
|
14
|
-
|
|
15
|
+
if (curr.path.length) {
|
|
16
|
+
return merge(acc, curr.path.reduceRight((errors, pathSegment) => ({
|
|
17
|
+
[pathSegment]: !Object.keys(errors).length
|
|
18
|
+
? curr.message
|
|
19
|
+
: errors,
|
|
20
|
+
}), {}));
|
|
21
|
+
}
|
|
22
|
+
const key = curr.path[0];
|
|
15
23
|
return Object.assign(Object.assign({}, acc), { [key]: curr.message });
|
|
16
24
|
}, {});
|
|
17
25
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formik-validator-zod",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Helper to simplify validating Formik values with Zod",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -34,5 +34,8 @@
|
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"formik": "^2.2.9",
|
|
36
36
|
"zod": "^3.19.1"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"deepmerge": "^4.3.1"
|
|
37
40
|
}
|
|
38
41
|
}
|