UNPKG

848 BJavaScriptView Raw
1const expose = require('./expose');
2
3/**
4 * Get the return value of the argument if
5 * it is a function or pass it through.
6 *
7 * @param {*} value
8 * @return {*}
9 */
10function passOrGet(value, argumentList = []) {
11 if (typeof value === 'function') {
12 return value(...argumentList);
13 }
14
15 return value;
16}
17
18/**
19 * Call a value with optional arguments if it is a function.
20 *
21 * @param {*} callback
22 * A value that is called if it is a function.
23 * @param {Array|Function} [argumentList=[]]
24 * The optional arguments for the callback.
25 * @returns {*}
26 * The return value of the function if it is called or undefined.
27 */
28function callOrNothingAtAll(callback, argumentList = []) {
29 if (typeof callback === 'function') {
30 return callback(...passOrGet(argumentList));
31 }
32}
33
34module.exports = expose({
35 callOrNothingAtAll,
36 passOrGet,
37});