Skip to content

Commit

Permalink
feat: added samples and README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
robertLichtnow committed Aug 16, 2021
1 parent a6399bd commit 7eb1dac
Show file tree
Hide file tree
Showing 8 changed files with 3,115 additions and 47 deletions.
9 changes: 9 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
coverage
node_modules
samples
tests
*.ts
!*.d.ts
jest.config.js
tsconfig.json
yarn.lock
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# zod-formik-adapter

This library adapts a [zod](https://www.npmjs.com/package/zod) schema to work as a `validationSchema` prop on [Formik](https://www.npmjs.com/package/formik)

## Install

```sh
# npm
$ npm install zod-formik-adapter

# yarn
$ yarn add zod-formik-adapter
```

## Usage

```JSX
const { z } = require('zod');
const { Formik } = require('formik');
const { toFormikValidationSchema } = require('zod-formik-adapter');


const Schema = z.object({
name: z.string(),
age: z.number(),
});

function Component = () => (
<Formik
validationSchema={toFormikValidationSchema(Schema)}
>
{...}
</Formik>
)

```
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
"name": "zod-formik-adapter",
"version": "1.0.0",
"description": "An adapter of zod object validation to Formik validation schema",
"main": "dist/index.js",
"main": "./dist/index.js",
"author": "Matheus Robert Lichtnow <matheusrobert8@gmail.com>",
"license": "MIT",
"scripts": {
"build": "tsc",
"test": "jest --coverage"
"test": "jest --coverage",
"build:clean": "rm -rf dist && yarn build"
},
"devDependencies": {
"@types/jest": "^27.0.1",
"formik": "~2.2.9",
"jest": "^27.0.6",
"react": "~17.0.2",
"semantic-release": "^17.4.5",
"ts-jest": "^27.0.4",
"typescript": "~4.3.5",
"zod": "~3.7.2"
Expand Down
33 changes: 33 additions & 0 deletions samples/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { Formik } = require("formik");
const { z } = require("zod");
const { toFormikValidationSchema } = require("zod-formik-adapter");

const Schema = z.object({
name: z.string(),
age: z.number(),
});

const initialValues = {
name: "",
age: 1,
}

export function SampleForm() {
return (
<Formik
initialValues={initialValues}
validationSchema={toFormikValidationSchema(Schema)}
onSubmit={console.log}
>
{({ errors, values, handleChange }) => (
<form>
<input value={values.name} onChange={handleChange("name")} />
<span>{errors.name}</span>

<input value={values.age} onChange={handleChange("age")} />
<span>{errors.age}</span>
</form>
)}
</Formik>
)
}
11 changes: 11 additions & 0 deletions samples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "samples",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"formik": "^2.2.9",
"react": "^17.0.2",
"zod-formik-adapter": "file:../"
}
}
86 changes: 86 additions & 0 deletions samples/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


deepmerge@^2.1.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-2.2.1.tgz#5d3ff22a01c00f645405a2fbc17d0778a1801170"
integrity sha512-R9hc1Xa/NOBi9WRVUWg19rl1UB7Tt4kuPd+thNJgFZoxXsTz7ncaPaeIm+40oSGuP33DfMb4sZt1QIGiJzC4EA==

formik@^2.2.9:
version "2.2.9"
resolved "https://registry.yarnpkg.com/formik/-/formik-2.2.9.tgz#8594ba9c5e2e5cf1f42c5704128e119fc46232d0"
integrity sha512-LQLcISMmf1r5at4/gyJigGn0gOwFbeEAlji+N9InZF6LIMXnFNkO42sCI8Jt84YZggpD4cPWObAZaxpEFtSzNA==
dependencies:
deepmerge "^2.1.1"
hoist-non-react-statics "^3.3.0"
lodash "^4.17.21"
lodash-es "^4.17.21"
react-fast-compare "^2.0.1"
tiny-warning "^1.0.2"
tslib "^1.10.0"

hoist-non-react-statics@^3.3.0:
version "3.3.2"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45"
integrity sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==
dependencies:
react-is "^16.7.0"

"js-tokens@^3.0.0 || ^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==

lodash-es@^4.17.21:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee"
integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==

lodash@^4.17.21:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==

loose-envify@^1.1.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
dependencies:
js-tokens "^3.0.0 || ^4.0.0"

object-assign@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=

react-fast-compare@^2.0.1:
version "2.0.4"
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-2.0.4.tgz#e84b4d455b0fec113e0402c329352715196f81f9"
integrity sha512-suNP+J1VU1MWFKcyt7RtjiSWUjvidmQSlqu+eHslq+342xCbGTYmC0mEhPCOHxlW0CywylOC1u2DFAT+bv4dBw==

react-is@^16.7.0:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==

react@^17.0.2:
version "17.0.2"
resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"
integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"

tiny-warning@^1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/tiny-warning/-/tiny-warning-1.0.3.tgz#94a30db453df4c643d0fd566060d60a875d84754"
integrity sha512-lBN9zLN/oAf68o3zNXYrdCt1kP8WsiGW8Oo2ka41b2IM5JL/S1CTyX1rW0mb/zSuJun0ZUrDxx4sqvYS2FWzPA==

tslib@^1.10.0:
version "1.14.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

"zod-formik-adapter@file:..":
version "1.0.0"
8 changes: 6 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"declaration": true,
"outDir": "./dist",
"lib": ["ES2019"],
"skipDefaultLibCheck": true
"skipDefaultLibCheck": true,

},
"include": ["./"],
"exclude": [
"node_modules",
"samples",
"tests"
"tests",
"dist",
"coverage",
]
}
Loading

0 comments on commit 7eb1dac

Please sign in to comment.