source: node_modules/es-toolkit/dist/compat/function/before.js@ a762898

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

Added visualizations

  • Property mode set to 100644
File size: 550 bytes
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const toInteger = require('../util/toInteger.js');
6
7function before(n, func) {
8 if (typeof func !== 'function') {
9 throw new TypeError('Expected a function');
10 }
11 let result;
12 n = toInteger.toInteger(n);
13 return function (...args) {
14 if (--n > 0) {
15 result = func.apply(this, args);
16 }
17 if (n <= 1 && func) {
18 func = undefined;
19 }
20 return result;
21 };
22}
23
24exports.before = before;
Note: See TracBrowser for help on using the repository browser.