UNPKG

1.31 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.callOrNothingAtAll = callOrNothingAtAll;
7
8function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
9
10function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
11
12function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
13
14function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
15
16/**
17 * Call a value with optional arguments if it is a function.
18 *
19 * @param {*} callback
20 * A value that is called if it is a function.
21 * @param {Array|Function} [argumentList=[]]
22 * The optional arguments for the callback.
23 * @returns {*}
24 * The return value of the function if it is called or undefined.
25 */
26function callOrNothingAtAll(callback) {
27 var argumentList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
28
29 if (typeof callback === 'function') {
30 return callback.apply(void 0, _toConsumableArray(typeof argumentList === 'function' ? argumentList() : argumentList));
31 }
32}
\No newline at end of file