arri-validate
Advanced tools
Comparing version 0.1.0-beta.10 to 0.1.0-beta.11
{ | ||
"name": "arri-validate", | ||
"version": "0.1.0-beta.10", | ||
"version": "0.1.0-beta.11", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.cjs", |
@@ -5,6 +5,16 @@ # Arri Validate | ||
A type builder and validation library built on top of the [Json Type Definition (RFC 8927)](https://jsontypedef.com) . It uses [AJV](https://ajv.js.org/guide/typescript.html) for parsing and serialization. This library is pretty similar to [Typebox](https://github.com/sinclairzx81/typebox) except that it creates Json Type Definition (JTD) objects instead of Json Schema objects. | ||
A type builder and validation library built on top of the [Json Type Definition (RFC 8927)](https://jsontypedef.com) This library is pretty similar to [Typebox](https://github.com/sinclairzx81/typebox) except that it creates Json Type Definition (JTD) objects instead of Json Schema objects. | ||
A lot of inspiration was taken from both [Typebox](https://github.com/sinclairzx81/typebox) and [Zod](https://github.com/colinhacks/zod) when designing this library | ||
## Installation | ||
```bash | ||
# npm | ||
npm install arri-validate | ||
# pnpm | ||
pnpm install arri-validate | ||
``` | ||
## Example | ||
@@ -22,6 +32,14 @@ | ||
// passes | ||
const result = a.parse(User, `{"id": "1", "name": "john doe"}`); | ||
// fails | ||
const result = a.parse(User, `{"id": "1", "name": null}`); | ||
// passes and returns User | ||
a.parse(User, `{"id": "1", "name": "John Doe"}`); | ||
// throws error | ||
a.parse(User, `{"id": "1", "name": null}`); | ||
// returns true | ||
a.validate(User, { id: "1", name: "John Doe" }); | ||
// returns false | ||
a.validate(User, { id: "1", name: null }); | ||
// outputs valid json | ||
a.serialize(User, { id: "1", name: "John Doe" }); | ||
``` | ||
@@ -28,0 +46,0 @@ |
250987
52