a2r
Version:
A2R Framework
26 lines (25 loc) • 869 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const getApiObjectText = (namespace, level = 0) => {
const { key, methods, namespaces } = namespace;
const lines = [
`${Array(level * 2)
.fill(' ')
.join('')}${!level ? 'const ' : ''}${key}${!level ? ' =' : ':'} {`,
];
if (namespaces.length) {
lines.push(...namespaces.map(n => getApiObjectText(n, level + 1)));
}
if (methods.length) {
lines.push(...methods.map((m) => {
return `${Array((level + 1) * 2)
.fill(' ')
.join('')}${m.key === m.methodName ? m.key : `${m.key}: ${m.methodName}`},`;
}));
}
lines.push(`${Array(level * 2)
.fill(' ')
.join('')}}${level ? ',' : ';'}`);
return lines.join('\n');
};
exports.default = getApiObjectText;