Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80542 views
1
// Copyright Joyent, Inc. and other Node contributors.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a
4
// copy of this software and associated documentation files (the
5
// "Software"), to deal in the Software without restriction, including
6
// without limitation the rights to use, copy, modify, merge, publish,
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
8
// persons to whom the Software is furnished to do so, subject to the
9
// following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22
// NOTE: These type checking functions intentionally don't use `instanceof`
23
// because it is fragile and can be easily faked with `Object.create()`.
24
function isArray(ar) {
25
return Array.isArray(ar);
26
}
27
exports.isArray = isArray;
28
29
function isBoolean(arg) {
30
return typeof arg === 'boolean';
31
}
32
exports.isBoolean = isBoolean;
33
34
function isNull(arg) {
35
return arg === null;
36
}
37
exports.isNull = isNull;
38
39
function isNullOrUndefined(arg) {
40
return arg == null;
41
}
42
exports.isNullOrUndefined = isNullOrUndefined;
43
44
function isNumber(arg) {
45
return typeof arg === 'number';
46
}
47
exports.isNumber = isNumber;
48
49
function isString(arg) {
50
return typeof arg === 'string';
51
}
52
exports.isString = isString;
53
54
function isSymbol(arg) {
55
return typeof arg === 'symbol';
56
}
57
exports.isSymbol = isSymbol;
58
59
function isUndefined(arg) {
60
return arg === void 0;
61
}
62
exports.isUndefined = isUndefined;
63
64
function isRegExp(re) {
65
return isObject(re) && objectToString(re) === '[object RegExp]';
66
}
67
exports.isRegExp = isRegExp;
68
69
function isObject(arg) {
70
return typeof arg === 'object' && arg !== null;
71
}
72
exports.isObject = isObject;
73
74
function isDate(d) {
75
return isObject(d) && objectToString(d) === '[object Date]';
76
}
77
exports.isDate = isDate;
78
79
function isError(e) {
80
return isObject(e) && objectToString(e) === '[object Error]';
81
}
82
exports.isError = isError;
83
84
function isFunction(arg) {
85
return typeof arg === 'function';
86
}
87
exports.isFunction = isFunction;
88
89
function isPrimitive(arg) {
90
return arg === null ||
91
typeof arg === 'boolean' ||
92
typeof arg === 'number' ||
93
typeof arg === 'string' ||
94
typeof arg === 'symbol' || // ES6 symbol
95
typeof arg === 'undefined';
96
}
97
exports.isPrimitive = isPrimitive;
98
99
function isBuffer(arg) {
100
return arg instanceof Buffer;
101
}
102
exports.isBuffer = isBuffer;
103
104
function objectToString(o) {
105
return Object.prototype.toString.call(o);
106
}
107
108