UNPKG

dilswer

Version:

Blazingly fast data validation library with TypeScript integration.

33 lines (32 loc) 869 B
// src/ts-type-generator/type-builders/literal-builder.ts import { TemplateBuilder } from "../template-builder.mjs"; import { TsBaseBuilder } from "./base-builder.mjs"; var LITERAL_EXPORT_TEMPLATE = new TemplateBuilder(`{{description}} {{export}}type {{name}} = {{type}};`); var TsLiteralBuilder = class extends TsBaseBuilder { constructor(value) { super(); this.value = value; } getType() { if (typeof this.value === "string") { return `"${this.value}"`; } return this.value.toString(); } build() { return this.getType(); } buildExport(type) { var _a; return LITERAL_EXPORT_TEMPLATE.build({ description: this.description, name: (_a = this.name) != null ? _a : this.generateName("String"), type: this.getType(), export: this.parseExportType(type) }); } }; export { TsLiteralBuilder };