github.com/jfrog/frogbot@v1.1.1-0.20231221090046-821a26f50338/action/node_modules/before-after-hook/lib/register.js (about) 1 module.exports = register; 2 3 function register(state, name, method, options) { 4 if (typeof method !== "function") { 5 throw new Error("method for before hook must be a function"); 6 } 7 8 if (!options) { 9 options = {}; 10 } 11 12 if (Array.isArray(name)) { 13 return name.reverse().reduce(function (callback, name) { 14 return register.bind(null, state, name, callback, options); 15 }, method)(); 16 } 17 18 return Promise.resolve().then(function () { 19 if (!state.registry[name]) { 20 return method(options); 21 } 22 23 return state.registry[name].reduce(function (method, registered) { 24 return registered.hook.bind(null, method, options); 25 }, method)(); 26 }); 27 }