UNPKG

dilswer

Version:

Blazingly fast data validation library with TypeScript integration.

44 lines (42 loc) 1.4 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); // src/data-types/types/instance.ts import { BaseType } from "../base-type.mjs"; import { getStandardSchemaProps } from "../generate-standard-schema.mjs"; import { ValidationError } from "../../validation-algorithms/validation-error/validation-error.mjs"; var InstanceOfType = class extends BaseType { constructor(instanceOf) { super(); __publicField(this, "instanceOf", instanceOf); __publicField(this, "kind", "instanceOf"); __publicField(this, "_t"); Object.freeze(this); } /** @internal */ _acceptVisitor(visitor, depth = 1) { return visitor.visit(this, void 0, depth); } get ["~standard"]() { return getStandardSchemaProps(this); } ["~validate"](path, value) { if (!(value instanceof this.instanceOf)) { throw new ValidationError( path, this, value, "not an instance of " + this.instanceOf.name ); } } ["~matches"](value) { return value instanceof this.instanceOf; } toString() { return `InstanceofSchema[ ${this.instanceOf.name}() ]`; } }; export { InstanceOfType };