args.js
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"use strict";
/**
* The purpose of this function is
* to handle back-backwards compatibility
* @param {Object} args
* @returns {{config: {}, cb: *}}
*/
module.exports = function (args) {
var config = {};
var cb;
switch (args.length) {
case 1:
if (isFilesArg(args[0])) {
config.files = args[0];
}
else if (typeof args[0] === "function") {
cb = args[0];
}
else {
config = args[0];
}
break;
case 2:
// if second is a function, first MUST be config
if (typeof args[1] === "function") {
config = args[0] || {};
cb = args[1];
}
else {
if (args[1] === null || args[1] === undefined) {
config = args[0];
}
else {
// finally, second arg could be a plain object for config
config = args[1] || {};
if (!config.files) {
config.files = args[0];
}
}
}
break;
case 3:
config = args[1] || {};
if (!config.files) {
config.files = args[0];
}
cb = args[2];
}
return {
config: config,
cb: cb
};
};
/**
* Files args were only ever strings or arrays
* @param arg
* @returns {*|boolean}
*/
function isFilesArg(arg) {
return Array.isArray(arg) || typeof arg === "string";
}
//# sourceMappingURL=args.js.map