UNPKG

json-schema-to-yup

Version:

Build a Yup schema from a JSON Schema. Also supports custom/alternative schema models such as GraphQL type defs

37 lines (28 loc) 661 B
import { Constraint } from './base'; function createRegExpConstraint(typer, map) { return new RegExpConstraint(typer, map); } class RegExpConstraint extends Constraint { constructor(typer, map = {}) { super(typer, map); } transform(value) { return this.toRegExp(value); } isValidConstraint(value) { return this.isRegExpLike(value); } toRegExp(value) { return new RegExp(value); } isRegExpLike(value) { return value instanceof RegExp || this.isStringType(value); } get explainConstraintValidMsg() { return `Must be either a RegExp or String`; } } export { createRegExpConstraint, RegExpConstraint };