'a'
mh-two-thousand-and-two
2024-04-12 44d2c92345cd156a59fc327b3060292a282d2893
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
63
64
65
66
67
68
var startWith = require('./startWith');
var last = require('./last');
var lowerCase = require('./lowerCase');
var isObj = require('./isObj');
var type = require('./type');
exports = function(types, args) {
    var argsLen = args.length;
    var typesLen = types.length;
    var minLen = typesLen;
    var maxLen = typesLen;
    for (var i = 0; i < typesLen; i++) {
        var _type = types[i].split('|');
        if (startWith(_type[0], '?')) {
            _type[0] = _type[0].slice(1);
            if (minLen === typesLen) {
                minLen = i;
            }
        }
        if (i === typesLen - 1 && startWith(_type[0], '...')) {
            maxLen = Infinity;
            _type[0] = _type[0].slice(3);
            if (minLen === typesLen) {
                minLen = i;
            }
        }
        types[i] = _type;
    }
    if (argsLen < minLen) {
        throw Error(
            'Expected at least '
                .concat(minLen, ' args but got ')
                .concat(argsLen)
        );
    } else if (argsLen > maxLen) {
        throw Error(
            'Expected at most '.concat(maxLen, ' args but got ').concat(argsLen)
        );
    }
    for (var _i = 0; _i < argsLen; _i++) {
        var arg = args[_i];
        if (_i >= typesLen) {
            validateArg(arg, last(types), _i);
        } else {
            validateArg(arg, types[_i], _i);
        }
    }
};
function validateArg(value, types, num) {
    var isValid = false;
    for (var i = 0, len = types.length; i < len; i++) {
        var t = lowerCase(types[i]);
        if (
            t === 'any' ||
            (t === 'object' && isObj(value)) ||
            type(value) === t
        ) {
            isValid = true;
            break;
        }
    }
    if (!isValid) {
        throw TypeError(
            'Argument '.concat(num, ' should be type ').concat(types.join('|'))
        );
    }
}
 
module.exports = exports;