UNPKG

dilswer

Version:

Blazingly fast data validation library with TypeScript integration.

48 lines (46 loc) 1.47 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/ts-type-generator/type-builders/set-builder.ts import { TemplateBuilder } from "../template-builder.mjs"; import { TsBaseBuilder } from "./base-builder.mjs"; var SET_TEMPLATE = new TemplateBuilder("Set<{{types}}>"); var EXPORT_SET_TEMPLATE = new TemplateBuilder( `{{description}} {{export}}type {{name}} = Set<{{types}}>;` ); var TsSetBuilder = class extends TsBaseBuilder { constructor() { super(...arguments); __publicField(this, "types", /* @__PURE__ */ new Set()); } getTypes(indent) { const types = []; for (const type of this.types) { types.push(type.build(indent)); } return types; } setTypes(type) { this.types = new Set(type); } build(indent) { const types = this.getTypes(indent); return SET_TEMPLATE.build({ types: types.join(" | ") }); } buildExport(type) { var _a; const types = this.getTypes(""); return EXPORT_SET_TEMPLATE.build({ types: types.join(" | "), description: this.description, name: (_a = this.name) != null ? _a : this.generateName("Set"), export: this.parseExportType(type) }); } }; export { TsSetBuilder };