Very small Javascript library to validate objects, similar to prop-types.
import { getErrors, validate } from "./fastidious.js";
getErrors({ value: true }, { value: validate.boolean }); // []
const schema = {
match: validate.oneOf([validate.string, validate.function(), validate.regex]).isRequired
};
getErrors({}, schema); // [ 'Error: Expected "config.match" to be oneOf: [string,function,regex]' ]
getErrors({ match: "test" }, schema); // []
validate.boolean
validate.string
validate.number
validate.function([argNames])
validate.regex
validate.value(expectedValue)
validate.shape(schema)
validate.arrayOf(validator)
validate.oneOf([validators]))
Used in Finicky to validate config file
const schema = {
defaultBrowser: validate.string.isRequired,
options: validate.shape({
hideIcon: validate.boolean,
urlShorteners: validate.arrayOf(validate.string)
}),
rewrite: validate.arrayOf(
validate.shape({
match: validate.oneOf([validate.string, validate.function("options"), validate.regex])
.isRequired,
url: validate.oneOf([validate.string, validate.function("options")]).isRequired
}).isRequired
),
handlers: validate.arrayOf(
validate.shape({
match: validate.oneOf([
validate.string,
validate.function("options"),
validate.regex,
validate.arrayOf(
validate.oneOf([validate.string, validate.function("options"), validate.regex])
)
]).isRequired,
browser: validate.oneOf([
validate.string,
validate.shape({
name: validate.string.isRequired,
type: validate.oneOf(["name", "bundleIdentifier"]).isRequired
})
]).isRequired
})
)
};
Icon made by Smashicons from www.flaticon.com is licensed by CC 3.0 BY