formik-validator-zod 1.0.2 → 2.0.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 +22 -0
- package/dist/index.js +8 -26
- package/jsr.json +6 -0
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -3,12 +3,34 @@
|
|
|
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
|
+
WARNING: As of v2, this package uses native ESM and no longer provides a
|
|
7
|
+
CommonJS export. If this is something you need, you should be able to use the
|
|
8
|
+
[dynamic import](https://v8.dev/features/dynamic-import) function or use v1 of
|
|
9
|
+
this package.
|
|
10
|
+
|
|
6
11
|
## Installation
|
|
7
12
|
|
|
13
|
+
This package is published both on [NPM](https://www.npmjs.com) and
|
|
14
|
+
[JSR](https://jsr.io/).
|
|
15
|
+
|
|
16
|
+
To install from NPM:
|
|
17
|
+
|
|
8
18
|
```sh
|
|
9
19
|
npm install formik-validator-zod
|
|
10
20
|
|
|
11
21
|
yarn add formik-validator-zod
|
|
22
|
+
|
|
23
|
+
bun add formik-validator-zod
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
To install from JSR:
|
|
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
|
|
12
34
|
```
|
|
13
35
|
|
|
14
36
|
## Example
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.withZodSchema = void 0;
|
|
15
1
|
/**
|
|
16
2
|
* Allows you to easily use Zod schemas with the <Formik /> component `validate`
|
|
17
3
|
* prop.
|
|
@@ -20,16 +6,12 @@ exports.withZodSchema = void 0;
|
|
|
20
6
|
* <Formik {...} validate={withZodSchema(yourSchema)}>
|
|
21
7
|
* ```
|
|
22
8
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return __assign(__assign({}, acc), (_a = {}, _a[key] = curr.message, _a));
|
|
32
|
-
}, {});
|
|
33
|
-
};
|
|
9
|
+
export const withZodSchema = (schema, params) => (values) => {
|
|
10
|
+
const result = schema.safeParse(values, params);
|
|
11
|
+
if (result.success)
|
|
12
|
+
return {};
|
|
13
|
+
return result.error.issues.reduce((acc, curr) => {
|
|
14
|
+
const key = curr.path.join('.');
|
|
15
|
+
return Object.assign(Object.assign({}, acc), { [key]: curr.message });
|
|
16
|
+
}, {});
|
|
34
17
|
};
|
|
35
|
-
exports.withZodSchema = withZodSchema;
|
package/jsr.json
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formik-validator-zod",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Helper to simplify validating Formik values with Zod",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
7
8
|
"scripts": {
|
|
@@ -16,19 +17,19 @@
|
|
|
16
17
|
"schema",
|
|
17
18
|
"validation"
|
|
18
19
|
],
|
|
19
|
-
"author": "Luke Glazebrook <Glazy@users.noreply.github.com>
|
|
20
|
+
"author": "Luke Glazebrook <Glazy@users.noreply.github.com>",
|
|
20
21
|
"repository": {
|
|
21
22
|
"type": "git",
|
|
22
23
|
"url": "https://github.com/glazy/formik-validator-zod.git"
|
|
23
24
|
},
|
|
24
25
|
"license": "MIT",
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"formik": "
|
|
27
|
+
"formik": "^2.2.9",
|
|
27
28
|
"husky": "^8.0.0",
|
|
28
29
|
"pretty-quick": "^3.1.3",
|
|
29
30
|
"typescript": "^4.8.4",
|
|
30
31
|
"vitest": "^0.24.3",
|
|
31
|
-
"zod": "
|
|
32
|
+
"zod": "^3.19.1"
|
|
32
33
|
},
|
|
33
34
|
"peerDependencies": {
|
|
34
35
|
"formik": "^2.2.9",
|