1 | /* eslint-disable @typescript-eslint/no-explicit-any */
|
2 | /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | /**
|
5 | * Checks whether given value's type is one of a few Error or Error-like
|
6 | * {@link isError}.
|
7 | *
|
8 | * @param wat A value to be checked.
|
9 | * @returns A boolean representing the result.
|
10 | */
|
11 | function isError(wat) {
|
12 | switch (Object.prototype.toString.call(wat)) {
|
13 | case '[object Error]':
|
14 | return true;
|
15 | case '[object Exception]':
|
16 | return true;
|
17 | case '[object DOMException]':
|
18 | return true;
|
19 | default:
|
20 | return isInstanceOf(wat, Error);
|
21 | }
|
22 | }
|
23 | exports.isError = isError;
|
24 | /**
|
25 | * Checks whether given value's type is ErrorEvent
|
26 | * {@link isErrorEvent}.
|
27 | *
|
28 | * @param wat A value to be checked.
|
29 | * @returns A boolean representing the result.
|
30 | */
|
31 | function isErrorEvent(wat) {
|
32 | return Object.prototype.toString.call(wat) === '[object ErrorEvent]';
|
33 | }
|
34 | exports.isErrorEvent = isErrorEvent;
|
35 | /**
|
36 | * Checks whether given value's type is DOMError
|
37 | * {@link isDOMError}.
|
38 | *
|
39 | * @param wat A value to be checked.
|
40 | * @returns A boolean representing the result.
|
41 | */
|
42 | function isDOMError(wat) {
|
43 | return Object.prototype.toString.call(wat) === '[object DOMError]';
|
44 | }
|
45 | exports.isDOMError = isDOMError;
|
46 | /**
|
47 | * Checks whether given value's type is DOMException
|
48 | * {@link isDOMException}.
|
49 | *
|
50 | * @param wat A value to be checked.
|
51 | * @returns A boolean representing the result.
|
52 | */
|
53 | function isDOMException(wat) {
|
54 | return Object.prototype.toString.call(wat) === '[object DOMException]';
|
55 | }
|
56 | exports.isDOMException = isDOMException;
|
57 | /**
|
58 | * Checks whether given value's type is a string
|
59 | * {@link isString}.
|
60 | *
|
61 | * @param wat A value to be checked.
|
62 | * @returns A boolean representing the result.
|
63 | */
|
64 | function isString(wat) {
|
65 | return Object.prototype.toString.call(wat) === '[object String]';
|
66 | }
|
67 | exports.isString = isString;
|
68 | /**
|
69 | * Checks whether given value's is a primitive (undefined, null, number, boolean, string, bigint, symbol)
|
70 | * {@link isPrimitive}.
|
71 | *
|
72 | * @param wat A value to be checked.
|
73 | * @returns A boolean representing the result.
|
74 | */
|
75 | function isPrimitive(wat) {
|
76 | return wat === null || (typeof wat !== 'object' && typeof wat !== 'function');
|
77 | }
|
78 | exports.isPrimitive = isPrimitive;
|
79 | /**
|
80 | * Checks whether given value's type is an object literal
|
81 | * {@link isPlainObject}.
|
82 | *
|
83 | * @param wat A value to be checked.
|
84 | * @returns A boolean representing the result.
|
85 | */
|
86 | function isPlainObject(wat) {
|
87 | return Object.prototype.toString.call(wat) === '[object Object]';
|
88 | }
|
89 | exports.isPlainObject = isPlainObject;
|
90 | /**
|
91 | * Checks whether given value's type is an Event instance
|
92 | * {@link isEvent}.
|
93 | *
|
94 | * @param wat A value to be checked.
|
95 | * @returns A boolean representing the result.
|
96 | */
|
97 | function isEvent(wat) {
|
98 | return typeof Event !== 'undefined' && isInstanceOf(wat, Event);
|
99 | }
|
100 | exports.isEvent = isEvent;
|
101 | /**
|
102 | * Checks whether given value's type is an Element instance
|
103 | * {@link isElement}.
|
104 | *
|
105 | * @param wat A value to be checked.
|
106 | * @returns A boolean representing the result.
|
107 | */
|
108 | function isElement(wat) {
|
109 | return typeof Element !== 'undefined' && isInstanceOf(wat, Element);
|
110 | }
|
111 | exports.isElement = isElement;
|
112 | /**
|
113 | * Checks whether given value's type is an regexp
|
114 | * {@link isRegExp}.
|
115 | *
|
116 | * @param wat A value to be checked.
|
117 | * @returns A boolean representing the result.
|
118 | */
|
119 | function isRegExp(wat) {
|
120 | return Object.prototype.toString.call(wat) === '[object RegExp]';
|
121 | }
|
122 | exports.isRegExp = isRegExp;
|
123 | /**
|
124 | * Checks whether given value has a then function.
|
125 | * @param wat A value to be checked.
|
126 | */
|
127 | function isThenable(wat) {
|
128 | // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
129 | return Boolean(wat && wat.then && typeof wat.then === 'function');
|
130 | }
|
131 | exports.isThenable = isThenable;
|
132 | /**
|
133 | * Checks whether given value's type is a SyntheticEvent
|
134 | * {@link isSyntheticEvent}.
|
135 | *
|
136 | * @param wat A value to be checked.
|
137 | * @returns A boolean representing the result.
|
138 | */
|
139 | function isSyntheticEvent(wat) {
|
140 | return isPlainObject(wat) && 'nativeEvent' in wat && 'preventDefault' in wat && 'stopPropagation' in wat;
|
141 | }
|
142 | exports.isSyntheticEvent = isSyntheticEvent;
|
143 | /**
|
144 | * Checks whether given value's type is an instance of provided constructor.
|
145 | * {@link isInstanceOf}.
|
146 | *
|
147 | * @param wat A value to be checked.
|
148 | * @param base A constructor to be used in a check.
|
149 | * @returns A boolean representing the result.
|
150 | */
|
151 | function isInstanceOf(wat, base) {
|
152 | try {
|
153 | return wat instanceof base;
|
154 | }
|
155 | catch (_e) {
|
156 | return false;
|
157 | }
|
158 | }
|
159 | exports.isInstanceOf = isInstanceOf;
|
160 | //# sourceMappingURL=is.js.map |
\ | No newline at end of file |