first commit

This commit is contained in:
2025-10-26 23:10:15 +08:00
commit 8f0345b7be
14961 changed files with 2356381 additions and 0 deletions

46
node_modules/before-after-hook/lib/add.js generated vendored Normal file
View File

@@ -0,0 +1,46 @@
// @ts-check
export function addHook(state, kind, name, hook) {
const orig = hook;
if (!state.registry[name]) {
state.registry[name] = [];
}
if (kind === "before") {
hook = (method, options) => {
return Promise.resolve()
.then(orig.bind(null, options))
.then(method.bind(null, options));
};
}
if (kind === "after") {
hook = (method, options) => {
let result;
return Promise.resolve()
.then(method.bind(null, options))
.then((result_) => {
result = result_;
return orig(result, options);
})
.then(() => {
return result;
});
};
}
if (kind === "error") {
hook = (method, options) => {
return Promise.resolve()
.then(method.bind(null, options))
.catch((error) => {
return orig(error, options);
});
};
}
state.registry[name].push({
hook: hook,
orig: orig,
});
}

27
node_modules/before-after-hook/lib/register.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
// @ts-check
export function register(state, name, method, options) {
if (typeof method !== "function") {
throw new Error("method for before hook must be a function");
}
if (!options) {
options = {};
}
if (Array.isArray(name)) {
return name.reverse().reduce((callback, name) => {
return register.bind(null, state, name, callback, options);
}, method)();
}
return Promise.resolve().then(() => {
if (!state.registry[name]) {
return method(options);
}
return state.registry[name].reduce((method, registered) => {
return registered.hook.bind(null, method, options);
}, method)();
});
}

19
node_modules/before-after-hook/lib/remove.js generated vendored Normal file
View File

@@ -0,0 +1,19 @@
// @ts-check
export function removeHook(state, name, method) {
if (!state.registry[name]) {
return;
}
const index = state.registry[name]
.map((registered) => {
return registered.orig;
})
.indexOf(method);
if (index === -1) {
return;
}
state.registry[name].splice(index, 1);
}