@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
28 lines • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToMappingObject = ToMappingObject;
const ts_morph_1 = require("ts-morph");
function ToMappingObject(input, options = {}) {
const { baseProperty, aliasFnc, } = options;
const mapping = {};
for (const [key, value] of Object.entries(input)) {
if (typeof value === 'object') {
mapping[key.includes('-') ? `"${key}"` : key] = ToMappingObject(value, options);
}
else if (typeof value === 'string') {
let accessKey = value;
if (aliasFnc) {
accessKey = aliasFnc(key, value);
}
if (baseProperty) {
accessKey = `${baseProperty}.${accessKey}`;
}
mapping[key.includes('-') ? `"${key}"` : key] = accessKey;
}
else {
throw new Error(`Invalid value type ${typeof value}`);
}
}
return ts_morph_1.Writers.object(mapping);
}
//# sourceMappingURL=to-mapping-object.js.map