is-what 4.1.15 → 4.1.16

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -1,109 +1,74 @@
1
1
  function getType(payload) {
2
2
  return Object.prototype.toString.call(payload).slice(8, -1);
3
3
  }
4
- function isUndefined(payload) {
5
- return getType(payload) === "Undefined";
4
+
5
+ function isAnyObject(payload) {
6
+ return getType(payload) === "Object";
6
7
  }
7
- function isNull(payload) {
8
- return getType(payload) === "Null";
8
+
9
+ function isArray(payload) {
10
+ return getType(payload) === "Array";
11
+ }
12
+
13
+ function isBlob(payload) {
14
+ return getType(payload) === "Blob";
15
+ }
16
+
17
+ function isBoolean(payload) {
18
+ return getType(payload) === "Boolean";
19
+ }
20
+
21
+ function isDate(payload) {
22
+ return getType(payload) === "Date" && !isNaN(payload);
23
+ }
24
+
25
+ function isEmptyArray(payload) {
26
+ return isArray(payload) && payload.length === 0;
9
27
  }
28
+
10
29
  function isPlainObject(payload) {
11
30
  if (getType(payload) !== "Object")
12
31
  return false;
13
32
  const prototype = Object.getPrototypeOf(payload);
14
33
  return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
15
34
  }
16
- function isObject(payload) {
17
- return isPlainObject(payload);
18
- }
35
+
19
36
  function isEmptyObject(payload) {
20
37
  return isPlainObject(payload) && Object.keys(payload).length === 0;
21
38
  }
22
- function isFullObject(payload) {
23
- return isPlainObject(payload) && Object.keys(payload).length > 0;
24
- }
25
- function isAnyObject(payload) {
26
- return getType(payload) === "Object";
27
- }
28
- function isObjectLike(payload) {
29
- return isAnyObject(payload);
39
+
40
+ function isEmptyString(payload) {
41
+ return payload === "";
30
42
  }
31
- function isFunction(payload) {
32
- return typeof payload === "function";
43
+
44
+ function isError(payload) {
45
+ return getType(payload) === "Error" || payload instanceof Error;
33
46
  }
34
- function isArray(payload) {
35
- return getType(payload) === "Array";
47
+
48
+ function isFile(payload) {
49
+ return getType(payload) === "File";
36
50
  }
51
+
37
52
  function isFullArray(payload) {
38
53
  return isArray(payload) && payload.length > 0;
39
54
  }
40
- function isEmptyArray(payload) {
41
- return isArray(payload) && payload.length === 0;
55
+
56
+ function isFullObject(payload) {
57
+ return isPlainObject(payload) && Object.keys(payload).length > 0;
42
58
  }
59
+
43
60
  function isString(payload) {
44
61
  return getType(payload) === "String";
45
62
  }
63
+
46
64
  function isFullString(payload) {
47
65
  return isString(payload) && payload !== "";
48
66
  }
49
- function isEmptyString(payload) {
50
- return payload === "";
51
- }
52
- function isNumber(payload) {
53
- return getType(payload) === "Number" && !isNaN(payload);
54
- }
55
- function isPositiveNumber(payload) {
56
- return isNumber(payload) && payload > 0;
57
- }
58
- function isNegativeNumber(payload) {
59
- return isNumber(payload) && payload < 0;
60
- }
61
- function isBoolean(payload) {
62
- return getType(payload) === "Boolean";
63
- }
64
- function isRegExp(payload) {
65
- return getType(payload) === "RegExp";
66
- }
67
- function isMap(payload) {
68
- return getType(payload) === "Map";
69
- }
70
- function isWeakMap(payload) {
71
- return getType(payload) === "WeakMap";
72
- }
73
- function isSet(payload) {
74
- return getType(payload) === "Set";
75
- }
76
- function isWeakSet(payload) {
77
- return getType(payload) === "WeakSet";
78
- }
79
- function isSymbol(payload) {
80
- return getType(payload) === "Symbol";
81
- }
82
- function isDate(payload) {
83
- return getType(payload) === "Date" && !isNaN(payload);
84
- }
85
- function isBlob(payload) {
86
- return getType(payload) === "Blob";
87
- }
88
- function isFile(payload) {
89
- return getType(payload) === "File";
90
- }
91
- function isPromise(payload) {
92
- return getType(payload) === "Promise";
93
- }
94
- function isError(payload) {
95
- return getType(payload) === "Error";
96
- }
97
- function isNaNValue(payload) {
98
- return getType(payload) === "Number" && isNaN(payload);
99
- }
100
- function isPrimitive(payload) {
101
- return isBoolean(payload) || isNull(payload) || isUndefined(payload) || isNumber(payload) || isString(payload) || isSymbol(payload);
102
- }
103
- const isNullOrUndefined = isOneOf(isNull, isUndefined);
104
- function isOneOf(a, b, c, d, e) {
105
- return (value) => a(value) || b(value) || !!c && c(value) || !!d && d(value) || !!e && e(value);
67
+
68
+ function isFunction(payload) {
69
+ return typeof payload === "function";
106
70
  }
71
+
107
72
  function isType(payload, type) {
108
73
  if (!(type instanceof Function)) {
109
74
  throw new TypeError("Type must be a function");
@@ -114,6 +79,7 @@ function isType(payload, type) {
114
79
  const name = type.name;
115
80
  return getType(payload) === name || Boolean(payload && payload.constructor === type);
116
81
  }
82
+
117
83
  function isInstanceOf(value, classOrClassName) {
118
84
  if (typeof classOrClassName === "function") {
119
85
  for (let p = value; p; p = Object.getPrototypeOf(p)) {
@@ -132,4 +98,74 @@ function isInstanceOf(value, classOrClassName) {
132
98
  }
133
99
  }
134
100
 
101
+ function isMap(payload) {
102
+ return getType(payload) === "Map";
103
+ }
104
+
105
+ function isNaNValue(payload) {
106
+ return getType(payload) === "Number" && isNaN(payload);
107
+ }
108
+
109
+ function isNumber(payload) {
110
+ return getType(payload) === "Number" && !isNaN(payload);
111
+ }
112
+
113
+ function isNegativeNumber(payload) {
114
+ return isNumber(payload) && payload < 0;
115
+ }
116
+
117
+ function isNull(payload) {
118
+ return getType(payload) === "Null";
119
+ }
120
+
121
+ function isOneOf(a, b, c, d, e) {
122
+ return (value) => a(value) || b(value) || !!c && c(value) || !!d && d(value) || !!e && e(value);
123
+ }
124
+
125
+ function isUndefined(payload) {
126
+ return getType(payload) === "Undefined";
127
+ }
128
+
129
+ const isNullOrUndefined = isOneOf(isNull, isUndefined);
130
+
131
+ function isObject(payload) {
132
+ return isPlainObject(payload);
133
+ }
134
+
135
+ function isObjectLike(payload) {
136
+ return isAnyObject(payload);
137
+ }
138
+
139
+ function isPositiveNumber(payload) {
140
+ return isNumber(payload) && payload > 0;
141
+ }
142
+
143
+ function isSymbol(payload) {
144
+ return getType(payload) === "Symbol";
145
+ }
146
+
147
+ function isPrimitive(payload) {
148
+ return isBoolean(payload) || isNull(payload) || isUndefined(payload) || isNumber(payload) || isString(payload) || isSymbol(payload);
149
+ }
150
+
151
+ function isPromise(payload) {
152
+ return getType(payload) === "Promise";
153
+ }
154
+
155
+ function isRegExp(payload) {
156
+ return getType(payload) === "RegExp";
157
+ }
158
+
159
+ function isSet(payload) {
160
+ return getType(payload) === "Set";
161
+ }
162
+
163
+ function isWeakMap(payload) {
164
+ return getType(payload) === "WeakMap";
165
+ }
166
+
167
+ function isWeakSet(payload) {
168
+ return getType(payload) === "WeakSet";
169
+ }
170
+
135
171
  export { getType, isAnyObject, isArray, isBlob, isBoolean, isDate, isEmptyArray, isEmptyObject, isEmptyString, isError, isFile, isFullArray, isFullObject, isFullString, isFunction, isInstanceOf, isMap, isNaNValue, isNegativeNumber, isNull, isNullOrUndefined, isNumber, isObject, isObjectLike, isOneOf, isPlainObject, isPositiveNumber, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isType, isUndefined, isWeakMap, isWeakSet };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "is-what",
3
- "version": "4.1.15",
3
+ "version": "4.1.16",
4
4
  "description": "JS type check (TypeScript supported) functions like `isPlainObject() isArray()` etc. A simple & small integration.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -65,29 +65,21 @@
65
65
  },
66
66
  "homepage": "https://github.com/mesqueeb/is-what#readme",
67
67
  "devDependencies": {
68
- "@typescript-eslint/eslint-plugin": "^5.59.6",
69
- "@typescript-eslint/parser": "^5.59.6",
70
- "del-cli": "^5.0.0",
71
- "eslint-config-prettier": "^8.8.0",
72
- "eslint-plugin-tree-shaking": "^1.10.0",
73
- "eslint": "^8.41.0",
74
- "np": "^8.0.2",
68
+ "@typescript-eslint/eslint-plugin": "^5.62.0",
69
+ "@typescript-eslint/parser": "^5.62.0",
70
+ "del-cli": "^5.1.0",
71
+ "eslint-config-prettier": "^8.10.0",
72
+ "eslint-plugin-tree-shaking": "^1.10.1",
73
+ "eslint": "^8.52.0",
74
+ "np": "^8.0.4",
75
75
  "prettier-plugin-jsdoc": "^0.4.2",
76
76
  "prettier": "^2.8.8",
77
- "rollup-plugin-dts": "^5.3.0",
77
+ "rollup-plugin-dts": "^5.3.1",
78
78
  "rollup-plugin-esbuild": "^5.0.0",
79
- "rollup": "^3.22.0",
80
- "typedoc": "^0.24.7",
81
- "typescript": "^5.0.4",
82
- "vitest": "^0.31.1"
83
- },
84
- "ava": {
85
- "extensions": {
86
- "ts": "module"
87
- },
88
- "nodeArguments": [
89
- "--loader=ts-node/esm"
90
- ]
79
+ "rollup": "^3.29.4",
80
+ "typedoc": "^0.25.2",
81
+ "typescript": "^5.2.2",
82
+ "vitest": "^0.34.6"
91
83
  },
92
84
  "np": {
93
85
  "branch": "production",