UNPKG

1.81 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.isString = exports.isFunction = exports.isError = exports.isArray = exports.isPlainObject = exports.isObject = exports.getTag = void 0;
4const getTag = (value) => {
5 const toString = Object.prototype.toString;
6 if (value == null) {
7 return value === undefined ? "[object Undefined]" : "[object Null]";
8 }
9 return toString.call(value);
10};
11exports.getTag = getTag;
12const isObject = (value) => {
13 return typeof value === "object" && value !== null;
14};
15exports.isObject = isObject;
16const isPlainObject = (value) => {
17 if (!exports.isObject(value) || exports.getTag(value) != "[object Object]") {
18 return false;
19 }
20 if (Object.getPrototypeOf(value) === null) {
21 return true;
22 }
23 let proto = value;
24 while (Object.getPrototypeOf(proto) !== null) {
25 proto = Object.getPrototypeOf(proto);
26 }
27 return Object.getPrototypeOf(value) === proto;
28};
29exports.isPlainObject = isPlainObject;
30const isArray = (value) => {
31 return value && Array.isArray(value);
32};
33exports.isArray = isArray;
34const isError = (value) => {
35 if (!exports.isObject(value)) {
36 return false;
37 }
38 const tag = exports.getTag(value);
39 return tag == "[object Error]" || tag == "[object DOMException]" || (typeof value.message === "string" && typeof value.name === "string" && !exports.isPlainObject(value));
40};
41exports.isError = isError;
42const isFunction = (value) => {
43 return typeof value === "function";
44};
45exports.isFunction = isFunction;
46const isString = (value) => {
47 const type = typeof value;
48 return type === "string" || (type === "object" && value != null && !Array.isArray(value) && exports.getTag(value) == "[object String]");
49};
50exports.isString = isString;