-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
154 lines (125 loc) · 3.43 KB
/
index.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* eslint no-self-compare: off */
function isNull (a) {
return a === null;
}
function isUndefined (a) {
return typeof a === "undefined";
}
function isBoolean (a) {
return typeof a === "boolean";
}
function isNumber (a) {
return typeof a === "number";
}
function isFiniteNumber (a) {
return isNumber(a) && isFinite(a);
}
function isInfiniteNumber (a) {
return isNumber(a) && !isFinite(a);
}
function isInfinity (a) {
return isPositiveInfinity(a) || isNegativeInfinity(a);
}
function isPositiveInfinity (a) {
return a === Number.POSITIVE_INFINITY;
}
function isNegativeInfinity (a) {
return a === Number.NEGATIVE_INFINITY;
}
function isNaN (a) {
return a !== a;
}
//
// Checks if a number is an integer. Please note that there's currently no way
// to identify "x.000" and similar as either integer or float in JavaScript because
// those are automatically truncated to "x".
//
function isInteger (n) {
return isFiniteNumber(n) && n % 1 === 0;
}
function isFloat (n) {
return isFiniteNumber(n) && n % 1 !== 0;
}
function isString (a) {
return typeof a === "string";
}
function isChar (a) {
return isString(a) && a.length === 1;
}
function isCollection (a) {
return isObject(a) || isArray(a);
}
function isObject (a) {
return typeof a === "object" && a !== null;
}
function isArray (a) {
return Array.isArray(a);
}
function isArrayLike (a) {
return (isArray(a) || isString(a) || (
isObject(a) && ("length" in a) && isFiniteNumber(a.length) && (
(a.length > 0 && (a.length - 1) in a) ||
(a.length === 0)
)
));
}
function isFunction (a) {
return typeof a === "function";
}
function isPrimitive (a) {
return isNull(a) || isUndefined(a) || isNumber(a) || isString(a) || isBoolean(a);
}
function isDate (a) {
return isObject(a) && Object.prototype.toString.call(a) === "[object Date]";
}
function isRegExp (a) {
return isObject(a) && Object.prototype.toString.call(a) === "[object RegExp]";
}
function isError (a) {
return isObject(a) && Object.prototype.toString.call(a) === "[object Error]";
}
function isArgumentsObject (a) {
return isObject(a) && Object.prototype.toString.call(a) === "[object Arguments]";
}
function isMathObject (a) {
return a === Math;
}
function isType (a) {
return isDerivable(a) && a.$__type__ === "type" && isFunction(a.$__checker__);
}
function isDerivable (a) {
return isObject(a) && "$__children__" in a && Array.isArray(a.$__children__);
}
function isMethod (a) {
return isFunction(a) && a.$__type__ === "method" && isFunction(a.$__default__) &&
isArray(a.$__implementations__) && isArray(a.$__dispatchers__);
}
module.exports = {
isArgumentsObject: isArgumentsObject,
isArray: isArray,
isArrayLike: isArrayLike,
isBoolean: isBoolean,
isChar: isChar,
isCollection: isCollection,
isDate: isDate,
isDerivable: isDerivable,
isError: isError,
isFiniteNumber: isFiniteNumber,
isFloat: isFloat,
isFunction: isFunction,
isInfiniteNumber: isInfiniteNumber,
isInfinity: isInfinity,
isInteger: isInteger,
isMathObject: isMathObject,
isMethod: isMethod,
isNaN: isNaN,
isNegativeInfinity: isNegativeInfinity,
isNull: isNull,
isNumber: isNumber,
isPositiveInfinity: isPositiveInfinity,
isPrimitive: isPrimitive,
isRegExp: isRegExp,
isString: isString,
isType: isType,
isUndefined: isUndefined
};