dilswer
Version:
Blazingly fast data validation library with TypeScript integration.
49 lines (47 loc) • 1.62 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/ts-type-generator/type-builders/intersection-builder.ts
import { TemplateBuilder } from "../template-builder.mjs";
import { TsBaseBuilder } from "./base-builder.mjs";
var INTERSECTION_TEMPLATE = new TemplateBuilder("{{types}}");
var EXPORT_INTERSECTION_TEMPLATE = new TemplateBuilder(
`{{description}}
{{export}}type {{name}} = {{types}};`
);
var TsIntersectionBuilder = class extends TsBaseBuilder {
constructor() {
super(...arguments);
__publicField(this, "types", /* @__PURE__ */ new Set());
}
getIntersectedTypes(indent) {
const types = [];
for (const type of this.types) {
types.push(type.build(indent));
}
return types;
}
/** Sets types that are part of the intersection. */
setTypes(type) {
this.types = new Set(type);
}
build(indent) {
const types = this.getIntersectedTypes(indent);
return INTERSECTION_TEMPLATE.build({
types: types.join(" & ")
});
}
buildExport(type) {
var _a;
const types = this.getIntersectedTypes("");
return EXPORT_INTERSECTION_TEMPLATE.build({
types: types.join(" & "),
description: this.description,
name: (_a = this.name) != null ? _a : this.generateName("Intersection"),
export: this.parseExportType(type)
});
}
};
export {
TsIntersectionBuilder
};