1 | const 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 | * @param {Array} [argumentList]
|
9 | * @return {*}
|
10 | */
|
11 | function passOrGet(value, argumentList = []) {
|
12 | if (typeof value === 'function') {
|
13 | return value(...argumentList);
|
14 | }
|
15 |
|
16 | return value;
|
17 | }
|
18 |
|
19 | /**
|
20 | * Call a value with optional arguments if it is a function.
|
21 | *
|
22 | * @param {*} callback
|
23 | * A value that is called if it is a function.
|
24 | * @param {Array|Function} [argumentList=[]]
|
25 | * The optional arguments for the callback.
|
26 | * @returns {*}
|
27 | * The return value of the function if it is called or undefined.
|
28 | */
|
29 | function callOrNothingAtAll(callback, argumentList = []) {
|
30 | if (typeof callback === 'function') {
|
31 | return callback(...passOrGet(argumentList));
|
32 | }
|
33 | }
|
34 |
|
35 | module.exports = expose({
|
36 | callOrNothingAtAll,
|
37 | passOrGet,
|
38 | });
|