dilswer
Version:
Blazingly fast data validation library with TypeScript integration.
46 lines (44 loc) • 1.41 kB
JavaScript
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/intersection.ts
import { BaseType } from "../base-type.mjs";
import { getStandardSchemaProps } from "../generate-standard-schema.mjs";
var IntersectionType = class extends BaseType {
constructor(allOf) {
super();
this.allOf = allOf;
__publicField(this, "kind", "intersection");
Object.freeze(this.allOf);
Object.freeze(this);
}
/** @internal */
_acceptVisitor(visitor) {
const children = [];
for (let i = 0; i < this.allOf.length; i++) {
children.push(this.allOf[i]._acceptVisitor(visitor));
}
return visitor.visit(this, children);
}
get ["~standard"]() {
return getStandardSchemaProps(this);
}
["~validate"](path, value) {
for (let i = 0; i < this.allOf.length; i++) {
const dataType = this.allOf[i];
dataType["~validate"](path, value);
}
}
["~matches"](value) {
for (let i = 0; i < this.allOf.length; i++) {
const dataType = this.allOf[i];
if (!dataType["~matches"](value)) {
return false;
}
}
return true;
}
};
export {
IntersectionType
};