@5alid/schema 中文文档教程
Installation
npm <代码>npm i @5alid/schema yarn yarn 添加@5alid/schema
Usage
import createSchema from '@5alidz/schema';
const Person = createSchema({
name: {
type: 'string',
minLength: 5,
maxLength: 20,
},
age: {
type: 'number',
min: 13,
max: 120,
},
pets: {
type: 'array',
optional: true,
of: {
type: 'object',
shape: {
name: {
type: 'string',
},
animal: {
type: 'string',
},
},
},
},
});
const errors = Person.validate({
name: 'John Doe',
age: 42,
pets: [
{ name: 'fluffy', animal: 'dog' },
{ name: 'pirate', animal: 'parrot' },
],
});
console.log(errors); // -> null
const errors2 = Person.validate({
name: true,
age: '42',
});
console.log(errors2); // -> [ { key: 'name', message: 'expected string but received "boolean"' }, { key: 'age', message: 'expected number but received "string"' }]
Installation
npm npm i @5alid/schema
yarn yarn add @5alid/schema
Usage
import createSchema from '@5alidz/schema';
const Person = createSchema({
name: {
type: 'string',
minLength: 5,
maxLength: 20,
},
age: {
type: 'number',
min: 13,
max: 120,
},
pets: {
type: 'array',
optional: true,
of: {
type: 'object',
shape: {
name: {
type: 'string',
},
animal: {
type: 'string',
},
},
},
},
});
const errors = Person.validate({
name: 'John Doe',
age: 42,
pets: [
{ name: 'fluffy', animal: 'dog' },
{ name: 'pirate', animal: 'parrot' },
],
});
console.log(errors); // -> null
const errors2 = Person.validate({
name: true,
age: '42',
});
console.log(errors2); // -> [ { key: 'name', message: 'expected string but received "boolean"' }, { key: 'age', message: 'expected number but received "string"' }]
更多
你可能也喜欢
- 99voices_npm_tyk_client 中文文档教程
- @0xcert/ethereum-http-provider 中文文档教程
- @0xsequence/relayer 中文文档教程
- @128technology/netconfetti 中文文档教程
- @1hive/gardens-dao-list 中文文档教程
- @36node/weather-sdk 中文文档教程
- @3dexpress/starwar-names 中文文档教程
- @47nordmedia/k2-systems-ui-library 中文文档教程
- @4geit/rct-text-selector-component 中文文档教程
- @5alid/schema 中文文档教程