a2r
Version:
A2R Framework
32 lines (31 loc) • 1.11 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const cleanText_1 = __importDefault(require("../../tools/cleanText"));
const updateApiObject = (structure, keys, methodName) => {
const newApiObject = Object.assign({}, structure);
const lastIndex = keys.length - 1;
return keys.reduce((t, key, i) => {
const cleanKey = (0, cleanText_1.default)(key, false, true, true, true, '-');
if (i === lastIndex) {
t.methods.push({
key: cleanKey,
methodName,
});
return newApiObject;
}
let namespace = t.namespaces.find((n) => n.key === cleanKey);
if (!namespace) {
namespace = {
key: cleanKey,
namespaces: [],
methods: [],
};
t.namespaces.push(namespace);
}
return namespace;
}, newApiObject);
};
exports.default = updateApiObject;