source: node_modules/es-toolkit/dist/compat/function/overArgs.mjs

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 692 bytes
RevLine 
[a762898]1import { identity } from '../../function/identity.mjs';
2import { iteratee } from '../util/iteratee.mjs';
3
4function overArgs(func, ..._transforms) {
5 if (typeof func !== 'function') {
6 throw new TypeError('Expected a function');
7 }
8 const transforms = _transforms.flat();
9 return function (...args) {
10 const length = Math.min(args.length, transforms.length);
11 const transformedArgs = [...args];
12 for (let i = 0; i < length; i++) {
13 const transform = iteratee(transforms[i] ?? identity);
14 transformedArgs[i] = transform.call(this, args[i]);
15 }
16 return func.apply(this, transformedArgs);
17 };
18}
19
20export { overArgs };
Note: See TracBrowser for help on using the repository browser.