Project Init

This commit is contained in:
Muluhabt
2026-05-29 15:23:46 +03:00
commit 2fbc557aac
67387 changed files with 6063341 additions and 0 deletions

26
node_modules/es-toolkit/dist/compat/function/rearg.js generated vendored Normal file
View File

@@ -0,0 +1,26 @@
const require_flatten = require("../array/flatten.js");
//#region src/compat/function/rearg.ts
/**
* Creates a function that invokes `func` with arguments arranged according to the specified `indices`
* where the argument value at the first index is provided as the first argument,
* the argument value at the second index is provided as the second argument, and so on.
*
* @param {(...args: any[]) => any} func The function to rearrange arguments for.
* @param {Array<number | number[]>} indices The arranged argument indices.
* @returns {(...args: any[]) => any} Returns the new function.
*
* @example
* const greet = (greeting: string, name: string) => `${greeting}, ${name}!`;
* const rearrangedGreet = rearg(greet, 1, 0);
* console.log(rearrangedGreet('World', 'Hello')); // Output: "Hello, World!"
*/
function rearg(func, ...indices) {
const flattenIndices = require_flatten.flatten(indices);
return function(...args) {
const reorderedArgs = flattenIndices.map((i) => args[i]).slice(0, args.length);
for (let i = reorderedArgs.length; i < args.length; i++) reorderedArgs.push(args[i]);
return func.apply(this, reorderedArgs);
};
}
//#endregion
exports.rearg = rearg;