UNPKG

@rxap/ts-morph

Version:

Provides utilities for manipulating TypeScript code using the ts-morph library. It offers a fluent API to add, modify, and remove code elements such as classes, decorators, imports, and properties in both Angular and NestJS projects. This package simplifi

95 lines 4.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TypeNames = void 0; exports.IsTypeImport = IsTypeImport; exports.RequiresTypeImport = RequiresTypeImport; exports.TypeImportToImportStructure = TypeImportToImportStructure; exports.NormalizeTypeImport = NormalizeTypeImport; exports.NormalizeTypeImportList = NormalizeTypeImportList; var TypeNames; (function (TypeNames) { TypeNames["String"] = "string"; TypeNames["Number"] = "number"; TypeNames["Boolean"] = "boolean"; TypeNames["Any"] = "any"; TypeNames["Unknown"] = "unknown"; TypeNames["Self"] = "<self>"; TypeNames["Deferred"] = "<deferred>"; })(TypeNames || (exports.TypeNames = TypeNames = {})); function IsTypeImport(value) { return typeof value === 'object' && typeof value.name === 'string'; } function RequiresTypeImport(typeImport) { return !!typeImport.moduleSpecifier; } function TypeImportToImportStructure(typeImport) { if (!typeImport.moduleSpecifier) { throw new Error('The moduleSpecifier is required'); } const structure = { moduleSpecifier: typeImport.moduleSpecifier, }; if (!typeImport.namedImport && !typeImport.namespaceImport && !typeImport.defaultImport) { structure.namedImports = [typeImport.name]; } if (typeImport.namedImport) { structure.namedImports = [typeImport.namedImport]; } if (typeImport.namespaceImport) { structure.namespaceImport = typeImport.namespaceImport; } if (typeImport.defaultImport) { structure.defaultImport = typeImport.defaultImport; } return structure; } function NormalizeTypeImport(typeImport, defaultType = 'unknown') { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; let name; let moduleSpecifier = null; let namedImport = null; let namespaceImport = null; let isTypeOnly = false; let defaultImport = null; if (!typeImport) { if (typeof defaultType === 'string') { name = defaultType; } else { name = defaultType.name; moduleSpecifier = (_a = defaultType.moduleSpecifier) !== null && _a !== void 0 ? _a : moduleSpecifier; namedImport = (_b = defaultType.namedImport) !== null && _b !== void 0 ? _b : namedImport; namespaceImport = (_c = defaultType.namespaceImport) !== null && _c !== void 0 ? _c : namespaceImport; isTypeOnly = (_d = defaultType.isTypeOnly) !== null && _d !== void 0 ? _d : isTypeOnly; defaultImport = (_e = defaultType.defaultImport) !== null && _e !== void 0 ? _e : defaultImport; } } else if (typeof typeImport === 'string') { // name:moduleSpecifier:namedImport // IconConfig:@rxap/utilities const fragments = typeImport.split(':'); name = fragments[0] || 'unknown'; moduleSpecifier = fragments[1] || null; // use || instead of ?? because the moduleSpecifier can be an empty string namedImport = fragments[2] || null; // use || instead of ?? because the namedImport can be an empty string } else { name = typeImport.name; moduleSpecifier = (_f = typeImport.moduleSpecifier) !== null && _f !== void 0 ? _f : moduleSpecifier; namedImport = (_g = typeImport.namedImport) !== null && _g !== void 0 ? _g : namedImport; namespaceImport = (_h = typeImport.namespaceImport) !== null && _h !== void 0 ? _h : namespaceImport; isTypeOnly = (_j = typeImport.isTypeOnly) !== null && _j !== void 0 ? _j : isTypeOnly; defaultImport = (_k = typeImport.defaultImport) !== null && _k !== void 0 ? _k : defaultImport; } return { name, moduleSpecifier, namedImport, namespaceImport, isTypeOnly, defaultImport, }; } function NormalizeTypeImportList(typeImportList = [], defaultType = 'unknown') { return typeImportList.map(type => NormalizeTypeImport(type, defaultType)); } //# sourceMappingURL=type-import.js.map