chained-schema
v1.0.0
Published
Concise JSON Schema type builders.
Downloads
2
Readme
chained-schema
Concise JSON Schema type builders.
Install
npm install chained-schema
Usage
import { object, array, number, boolean, string } from 'chained-schema';
const phoneNumber = string.pattern(/\(?\d\d\d\)?-?\d\d\d-?\d\d\d\d/);
const user = object
.required('firstName', 'lastName')
.props({
firstName: string,
lastName: string,
email: string.nullable,
phoneNumber: phoneNumber.nullable,
password: string.default('secret').minLength(5),
});
API
Properties that require inputs are called as functions. Properties that don't require inputs are just chained as getters.
For example number.maximum
takes an argument, but number.nullable
doesn't, so it's a getter instead of a method.
number.minimum(0).nullable.maximum(10)
array
items(items)
additionalItems(additionalItems)
get uniqueItems
object
props(p)
properties(properties)
dependencies(dependencies)
patternProperties(patternProperties)
additionalProperties(additionalProperties)
propertyNames(propertyNames)
minProperties(minProperties)
maxProperties(maxProperties)
string
minLength(minLength)
maxLength(maxLength)
format(format)
pattern(regex)
number
minimum(minimum)
maximum(maximum)
exclusiveMinimum(exclusiveMinimum)
exclusiveMaximum(exclusiveMaximum)
multipleOf(multipleOf)
integer
Same as number
.
boolean
No custom boolean options.
nill
(null)
No custom null options.