/// // @ts-ignore Leaf = require("../../dist/leaf") const model = { name: "MyNabdo", password: "12345678ABC", age: 20, meta: { premium: true }, complex: { CA: { big: 100 }, CB: { small: 5 } }, friends: [{ name: "MyFriend", age: 18 }] } let validator = new Leaf.Validator("Model") .with("name", (name) => { name .reason("Name must be string between 6 ~ 10 char") .has() .field("length").gte(6).lte(10).parent }) // .with("meta", (meta) => { // meta.field("premium").exists() // }) // .with("complex", (complex) => { // complex.field("CB").field("small").exists() // complex.field("CA").field("big").custom((big, root) => { // if (big < root.complex.CB.small) { // throw new Error("Big should be bigger than small") // } // }) // }) try { validator.check(model) } catch (e) { console.error(e.path) console.error(e.code) console.error(e) }