Skip to content

Instantly share code, notes, and snippets.

@Raynos
Last active August 18, 2022 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Raynos/4358110 to your computer and use it in GitHub Desktop.
Save Raynos/4358110 to your computer and use it in GitHub Desktop.
Different schema apis
var validate = require("valid-schema")
var Email = require("valid-schema/email")
var schema = validate().
prop("name", String).
prop("email", Email).
prop("number").
maybe().
range({ start: 1, end: 99 }).
is(Number).
schema("address").
prop("street").
maybe().
is(String).
prop("city", String).
prop("zip").
maybe().
range({ size: 8 }).
is(String).
end().
list("array").
maybe().
range({ start: 1 }).
value(Number)
var validate = require("valid-schema")
var Email = require("valid-schema/email")
var Range = require("valid-schema/range")
var Maybe = require("valid-schema/maybe")
var schema = validate({
name: String
, email: Email
, number: Maybe(Range(Number, {
start: 1
, end: 99
}))
, address: {
street: Maybe(String)
, city: String
, zip: Maybe(Range(String, {
size: 8
}))
}
, array: Maybe(Range([Number], {
start: 1
}))
})
var validate = require("valid-schema")
var schema = validate({
name: {
type: "string"
, required: true
}
, email: {
type: "email"
, required: true
}
, number: {
type: "number"
, start: 1
, end: 99
}
, address: {
street: {
type: "string"
}
, city: {
type: "string"
, required: true
}
, zip: {
type: "string"
, size: 8
}
}
, array: {
type: "array"
, start: 1
, values: {
type: "number"
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment