DieselDepot-APP/node_modules/es-toolkit/dist/compat/function/after.js
SJCoetz def597c157 chore: add generated build artifacts and node module type files
add all Next.js build outputs and third-party dependency type declaration files
2026-07-20 01:18:42 +02:00

32 lines
1 KiB
JavaScript

const require_toInteger = require("../util/toInteger.js");
//#region src/compat/function/after.ts
/**
* The opposite of `_.before`; this method creates a function that invokes
* `func` once it's called `n` or more times.
*
* @template TFunc - The type of the function to be invoked.
* @param n - The number of calls before `func` is invoked.
* @param func - The function to restrict.
* @returns Returns the new restricted function.
* @throws {TypeError} - If `func` is not a function.
*
* @example
* const saves = ['profile', 'settings'];
* const done = after(saves.length, () => {
* console.log('done saving!');
* });
*
* saves.forEach(type => {
* asyncSave({ 'type': type, 'complete': done });
* });
* // => Logs 'done saving!' after the two async saves have completed.
*/
function after(n, func) {
if (typeof func !== "function") throw new TypeError("Expected a function");
n = require_toInteger.toInteger(n);
return function(...args) {
if (--n < 1) return func.apply(this, args);
};
}
//#endregion
exports.after = after;