@semo/core
Version:
The core of Semo
41 lines • 1.28 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Hook = void 0;
const lodash_1 = __importDefault(require("lodash"));
class Hook {
mappings = {};
scriptName = 'semo';
constructor(name, handler = null) {
if (lodash_1.default.isString(name)) {
name = this.convertName(name);
this.mappings[name] = handler;
}
else if (lodash_1.default.isObject(name)) {
const newMappings = {};
Object.keys(name).forEach(n => {
const nn = this.convertName(n);
newMappings[nn] = name[n];
});
this.mappings = newMappings;
}
else {
throw new Error('Invalid hook');
}
}
getHook(name) {
name = this.convertName(name);
return this.mappings[name] || {};
}
convertName(name) {
if (name !== this.scriptName &&
name.indexOf(`${this.scriptName}-plugin-`) === -1) {
name = this.scriptName + '-plugin-' + name;
}
return name;
}
}
exports.Hook = Hook;
//# sourceMappingURL=hook.js.map