inspect.js
2.85 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
import { RX_NUMBER } from '../constants/regex';
import { File } from '../constants/safe-types'; // --- Convenience inspection utilities ---
export var toType = function toType(value) {
return _typeof(value);
};
export var toRawType = function toRawType(value) {
return Object.prototype.toString.call(value).slice(8, -1);
};
export var toRawTypeLC = function toRawTypeLC(value) {
return toRawType(value).toLowerCase();
};
export var isUndefined = function isUndefined(value) {
return value === undefined;
};
export var isNull = function isNull(value) {
return value === null;
};
export var isEmptyString = function isEmptyString(value) {
return value === '';
};
export var isUndefinedOrNull = function isUndefinedOrNull(value) {
return isUndefined(value) || isNull(value);
};
export var isUndefinedOrNullOrEmpty = function isUndefinedOrNullOrEmpty(value) {
return isUndefinedOrNull(value) || isEmptyString(value);
};
export var isFunction = function isFunction(value) {
return toType(value) === 'function';
};
export var isBoolean = function isBoolean(value) {
return toType(value) === 'boolean';
};
export var isString = function isString(value) {
return toType(value) === 'string';
};
export var isNumber = function isNumber(value) {
return toType(value) === 'number';
};
export var isNumeric = function isNumeric(value) {
return RX_NUMBER.test(String(value));
};
export var isPrimitive = function isPrimitive(value) {
return isBoolean(value) || isString(value) || isNumber(value);
};
export var isArray = function isArray(value) {
return Array.isArray(value);
}; // Quick object check
// This is primarily used to tell Objects from primitive values
// when we know the value is a JSON-compliant type
// Note object could be a complex type like array, Date, etc.
export var isObject = function isObject(obj) {
return obj !== null && _typeof(obj) === 'object';
}; // Strict object type check
// Only returns true for plain JavaScript objects
export var isPlainObject = function isPlainObject(obj) {
return Object.prototype.toString.call(obj) === '[object Object]';
};
export var isDate = function isDate(value) {
return value instanceof Date;
};
export var isEvent = function isEvent(value) {
return value instanceof Event;
};
export var isFile = function isFile(value) {
return value instanceof File;
};
export var isRegExp = function isRegExp(value) {
return toRawType(value) === 'RegExp';
};
export var isPromise = function isPromise(value) {
return !isUndefinedOrNull(value) && isFunction(value.then) && isFunction(value.catch);
};