UNPKG

1.71 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.passOrGet = passOrGet;
7exports.callOrNothingAtAll = callOrNothingAtAll;
8
9function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
10
11function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
12
13function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
14
15function _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; } }
16
17/**
18 * Get the return value of the argument if
19 * it is a function or pass it through.
20 *
21 * @param {*} value
22 * @param {Array} [argumentList]
23 * @return {*}
24 */
25function passOrGet(value) {
26 var argumentList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
27
28 if (typeof value === 'function') {
29 return value.apply(void 0, _toConsumableArray(argumentList));
30 }
31
32 return value;
33}
34/**
35 * Call a value with optional arguments if it is a function.
36 *
37 * @param {*} callback
38 * A value that is called if it is a function.
39 * @param {Array|Function} [argumentList=[]]
40 * The optional arguments for the callback.
41 * @returns {*}
42 * The return value of the function if it is called or undefined.
43 */
44
45
46function callOrNothingAtAll(callback) {
47 var argumentList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
48
49 if (typeof callback === 'function') {
50 return callback.apply(void 0, _toConsumableArray(passOrGet(argumentList)));
51 }
52}
\No newline at end of file