UNPKG

helene

Version:
49 lines 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ns = ns; function ns(namespace, submodules) { function add(methodName, fnOrSubmodule, options) { const isMethodFunction = (value) => { return typeof value === 'function'; }; if (isMethodFunction(fnOrSubmodule)) { const nameWithPrefix = namespace ? `${namespace}.${methodName}` : methodName; return ns(namespace, { ...submodules, [nameWithPrefix]: [fnOrSubmodule, options], }); } return ns(namespace, { ...submodules, [methodName]: { ...(submodules?.[methodName] ?? {}), ...fnOrSubmodule, }, }); } const registerMethods = (methods, prefix = '') => { Object.entries(methods).forEach(([key, value]) => { if (Array.isArray(value)) { Helene.addMethod(prefix ? `${prefix}.${key}` : key, value[0], value[1]); return; } registerMethods(value, prefix ? `${prefix}.${key}` : key); }); }; const build = () => { return submodules; }; const register = () => { registerMethods(submodules); return submodules; }; return { add, build, submodules, register, }; } //# sourceMappingURL=ns.js.map