Intro
Vality offers a simple and intuitive way to describe your schema:
Describe it
ts
import {v } from "vality";// Models are defined like this:constPerson = () => ({name :v .string ,age :v .number ,address : {street :v .string ,city :v .string ,country :v .string ,},});
ts
import {v } from "vality";// Models are defined like this:constPerson = () => ({name :v .string ,age :v .number ,address : {street :v .string ,city :v .string ,country :v .string ,},});
Type it
ts
import type {Parse } from "vality";// And can easily be converted into a type:typePersonModel =Parse <typeofPerson >;
ts
import type {Parse } from "vality";// And can easily be converted into a type:typePersonModel =Parse <typeofPerson >;
Validate it
ts
import {validate } from "vality";// Or used directly in a validation function:result =validate (Person , {name : "Max",age : "look ma no number",address : {street : "Main Street",// city: "Dummytown",country : "USA",},});// Which yields the following result:result = {valid : false,data :undefined ,errors : [{message : "vality.number.base",path : ["age"],value : "look ma no number",meta : { ... }}, {message : "vality.string.base",path : ["address", "city"],value :undefined ,meta : { ... }}]};
ts
import {validate } from "vality";// Or used directly in a validation function:result =validate (Person , {name : "Max",age : "look ma no number",address : {street : "Main Street",// city: "Dummytown",country : "USA",},});// Which yields the following result:result = {valid : false,data :undefined ,errors : [{message : "vality.number.base",path : ["age"],value : "look ma no number",meta : { ... }}, {message : "vality.string.base",path : ["address", "city"],value :undefined ,meta : { ... }}]};