@pawover/kit 0.0.0-alpha.24 → 0.0.0-alpha.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks-react.d.ts +5 -6
- package/dist/hooks-react.d.ts.map +1 -1
- package/dist/hooks-react.js +57 -29
- package/dist/hooks-react.js.map +1 -1
- package/dist/index.d.ts +60 -47
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +134 -110
- package/dist/index.js.map +1 -1
- package/metadata.json +4 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/utils/typeof/types.ts
|
|
2
|
-
const
|
|
2
|
+
const PROTOTYPE_TAGS = {
|
|
3
3
|
string: "[object String]",
|
|
4
4
|
number: "[object Number]",
|
|
5
5
|
boolean: "[object Boolean]",
|
|
@@ -8,8 +8,9 @@ const prototypeStrings = {
|
|
|
8
8
|
bigInt: "[object BigInt]",
|
|
9
9
|
symbol: "[object Symbol]",
|
|
10
10
|
function: "[object Function]",
|
|
11
|
-
generatorFunction: "[object GeneratorFunction]",
|
|
12
11
|
asyncFunction: "[object AsyncFunction]",
|
|
12
|
+
generatorFunction: "[object GeneratorFunction]",
|
|
13
|
+
asyncGeneratorFunction: "[object AsyncGeneratorFunction]",
|
|
13
14
|
promise: "[object Promise]",
|
|
14
15
|
null: "[object Null]",
|
|
15
16
|
undefined: "[object Undefined]",
|
|
@@ -25,6 +26,19 @@ const prototypeStrings = {
|
|
|
25
26
|
webSocket: "[object WebSocket]",
|
|
26
27
|
URLSearchParams: "[object URLSearchParams]"
|
|
27
28
|
};
|
|
29
|
+
const TYPED_ARRAY_TAGS = new Set([
|
|
30
|
+
"[object Int8Array]",
|
|
31
|
+
"[object Uint8Array]",
|
|
32
|
+
"[object Uint8ClampedArray]",
|
|
33
|
+
"[object Int16Array]",
|
|
34
|
+
"[object Uint16Array]",
|
|
35
|
+
"[object Int32Array]",
|
|
36
|
+
"[object Uint32Array]",
|
|
37
|
+
"[object Float32Array]",
|
|
38
|
+
"[object Float64Array]",
|
|
39
|
+
"[object BigInt64Array]",
|
|
40
|
+
"[object BigUint64Array]"
|
|
41
|
+
]);
|
|
28
42
|
function resolvePrototypeString(value) {
|
|
29
43
|
return Object.prototype.toString.call(value);
|
|
30
44
|
}
|
|
@@ -32,43 +46,67 @@ function resolvePrototypeString(value) {
|
|
|
32
46
|
//#endregion
|
|
33
47
|
//#region src/utils/typeof/isArray.ts
|
|
34
48
|
function isArray(value) {
|
|
35
|
-
return
|
|
49
|
+
return Array.isArray(value);
|
|
36
50
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
//#region src/utils/typeof/isAsyncFunction.ts
|
|
40
|
-
function isAsyncFunction(value) {
|
|
41
|
-
return resolvePrototypeString(value) === prototypeStrings.asyncFunction;
|
|
51
|
+
function isTypedArray(value) {
|
|
52
|
+
return typeof value === "object" && value !== null && TYPED_ARRAY_TAGS.has(resolvePrototypeString(value));
|
|
42
53
|
}
|
|
43
54
|
|
|
44
55
|
//#endregion
|
|
45
56
|
//#region src/utils/typeof/isBigInt.ts
|
|
46
57
|
function isBigInt(value) {
|
|
47
|
-
return
|
|
58
|
+
return typeof value === "bigint";
|
|
48
59
|
}
|
|
49
60
|
|
|
50
61
|
//#endregion
|
|
51
62
|
//#region src/utils/typeof/isBoolean.ts
|
|
52
63
|
function isBoolean(value) {
|
|
53
|
-
return
|
|
64
|
+
return typeof value === "boolean";
|
|
54
65
|
}
|
|
55
66
|
|
|
56
67
|
//#endregion
|
|
57
68
|
//#region src/utils/typeof/isClass.ts
|
|
69
|
+
function isConstructable(fn) {
|
|
70
|
+
try {
|
|
71
|
+
Reflect.construct(fn, []);
|
|
72
|
+
return true;
|
|
73
|
+
} catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
58
77
|
function isClass(value) {
|
|
59
|
-
return
|
|
78
|
+
return isFunction(value) && !isAsyncFunction(value) && Function.prototype.toString.call(value).startsWith("class ") && isConstructable(value) && value.prototype !== void 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/utils/typeof/isObject.ts
|
|
83
|
+
/**
|
|
84
|
+
* 判断是否为对象类型
|
|
85
|
+
* - 可选是否检查原型为 `Object.prototype`,防止原型链污染
|
|
86
|
+
*
|
|
87
|
+
* @param value - 待检查值
|
|
88
|
+
* @param prototypeCheck - 是否进行原型检查,默认 `true`
|
|
89
|
+
*/
|
|
90
|
+
function isObject(value, prototypeCheck = true) {
|
|
91
|
+
const check = resolvePrototypeString(value) === PROTOTYPE_TAGS.object;
|
|
92
|
+
return prototypeCheck ? check && Object.getPrototypeOf(value) === Object.prototype : check;
|
|
60
93
|
}
|
|
61
94
|
|
|
62
95
|
//#endregion
|
|
63
96
|
//#region src/utils/typeof/isDate.ts
|
|
64
97
|
function isDate(value) {
|
|
65
|
-
|
|
98
|
+
if (!isObject(value)) return false;
|
|
99
|
+
try {
|
|
100
|
+
return resolvePrototypeString(value) === PROTOTYPE_TAGS.date && typeof value["getTime"] === "function";
|
|
101
|
+
} catch (error) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
66
104
|
}
|
|
67
105
|
|
|
68
106
|
//#endregion
|
|
69
107
|
//#region src/utils/typeof/isEqual.ts
|
|
70
108
|
/**
|
|
71
|
-
*
|
|
109
|
+
* 检查给定的值是否相等
|
|
72
110
|
* @reference https://github.com/radashi-org/radashi/blob/main/src/typed/isEqual.ts
|
|
73
111
|
*
|
|
74
112
|
* @param {T} x
|
|
@@ -76,8 +114,8 @@ function isDate(value) {
|
|
|
76
114
|
*/
|
|
77
115
|
function isEqual(x, y) {
|
|
78
116
|
if (Object.is(x, y)) return true;
|
|
79
|
-
if (x
|
|
80
|
-
if (x
|
|
117
|
+
if (isDate(x) && isDate(y)) return x.getTime() === y.getTime();
|
|
118
|
+
if (isRegExp(x) && isRegExp(y)) return x.toString() === y.toString();
|
|
81
119
|
if (typeof x !== "object" || x === null || typeof y !== "object" || y === null) return false;
|
|
82
120
|
const keysX = Reflect.ownKeys(x);
|
|
83
121
|
const keysY = Reflect.ownKeys(y);
|
|
@@ -92,92 +130,39 @@ function isEqual(x, y) {
|
|
|
92
130
|
//#endregion
|
|
93
131
|
//#region src/utils/typeof/isError.ts
|
|
94
132
|
function isError(value) {
|
|
95
|
-
return resolvePrototypeString(value) ===
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
//#endregion
|
|
99
|
-
//#region src/utils/typeof/isNaN.ts
|
|
100
|
-
function isNaN(value) {
|
|
101
|
-
return Number.isNaN(value);
|
|
133
|
+
return value instanceof Error || resolvePrototypeString(value) === PROTOTYPE_TAGS.error;
|
|
102
134
|
}
|
|
103
135
|
|
|
104
136
|
//#endregion
|
|
105
137
|
//#region src/utils/typeof/isFalsy.ts
|
|
106
138
|
function isFalsy(value) {
|
|
107
|
-
if (isNaN(value)) return true;
|
|
108
|
-
return
|
|
109
|
-
null,
|
|
110
|
-
void 0,
|
|
111
|
-
false,
|
|
112
|
-
0,
|
|
113
|
-
0n,
|
|
114
|
-
""
|
|
115
|
-
].includes(value);
|
|
139
|
+
if (isNaN(value) || isNull(value) || isUndefined(value)) return true;
|
|
140
|
+
return value === false || value === 0 || value === 0n || value === "";
|
|
116
141
|
}
|
|
117
142
|
function isFalsyLike(value) {
|
|
118
|
-
return
|
|
119
|
-
|
|
120
|
-
"undefined",
|
|
121
|
-
"false",
|
|
122
|
-
"NaN"
|
|
123
|
-
].includes(value);
|
|
143
|
+
if (isFalsy(value)) return true;
|
|
144
|
+
return typeof value === "string" && (value === "null" || value === "undefined" || value === "NaN" || value === "false" || value === "0" || value === "0n");
|
|
124
145
|
}
|
|
125
146
|
|
|
126
147
|
//#endregion
|
|
127
148
|
//#region src/utils/typeof/isFile.ts
|
|
128
149
|
function isFile(value) {
|
|
129
|
-
return resolvePrototypeString(value) ===
|
|
150
|
+
return resolvePrototypeString(value) === PROTOTYPE_TAGS.file;
|
|
130
151
|
}
|
|
131
152
|
|
|
132
153
|
//#endregion
|
|
133
154
|
//#region src/utils/typeof/isFunction.ts
|
|
134
155
|
function isFunction(value) {
|
|
135
|
-
return
|
|
136
|
-
prototypeStrings.function,
|
|
137
|
-
prototypeStrings.generatorFunction,
|
|
138
|
-
prototypeStrings.asyncFunction
|
|
139
|
-
].includes(resolvePrototypeString(value));
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
//#endregion
|
|
143
|
-
//#region src/utils/typeof/isGeneratorFunction.ts
|
|
144
|
-
function isGeneratorFunction(value) {
|
|
145
|
-
return resolvePrototypeString(value) === prototypeStrings.generatorFunction;
|
|
156
|
+
return typeof value === "function";
|
|
146
157
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
//#region src/utils/typeof/isInfinity.ts
|
|
150
|
-
function isInfinity(value) {
|
|
151
|
-
if (isNaN(value)) return true;
|
|
152
|
-
return [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY].includes(value);
|
|
158
|
+
function isAsyncFunction(value) {
|
|
159
|
+
return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.asyncFunction;
|
|
153
160
|
}
|
|
154
|
-
function
|
|
155
|
-
return
|
|
156
|
-
"Infinity",
|
|
157
|
-
"-Infinity",
|
|
158
|
-
"NaN"
|
|
159
|
-
].includes(value);
|
|
161
|
+
function isGeneratorFunction(value) {
|
|
162
|
+
return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.generatorFunction;
|
|
160
163
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
//#region src/utils/typeof/isInteger.ts
|
|
164
|
-
function isInteger(value) {
|
|
165
|
-
return Number.isInteger(value);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
//#endregion
|
|
169
|
-
//#region src/utils/typeof/isObject.ts
|
|
170
|
-
/**
|
|
171
|
-
* 判断是否为对象类型
|
|
172
|
-
* - 可选是否检查原型为 `Object.prototype`,防止原型链污染
|
|
173
|
-
*
|
|
174
|
-
* @param value - 待检查值
|
|
175
|
-
* @param prototypeCheck - 是否进行原型检查,默认 `true`
|
|
176
|
-
*/
|
|
177
|
-
function isObject(value, prototypeCheck = true) {
|
|
178
|
-
const checkValue = resolvePrototypeString(value) === prototypeStrings.object;
|
|
179
|
-
if (prototypeCheck && checkValue) return Object.getPrototypeOf(value) === Object.prototype;
|
|
180
|
-
else return checkValue;
|
|
164
|
+
function isAsyncGeneratorFunction(value) {
|
|
165
|
+
return isFunction(value) && resolvePrototypeString(value) === PROTOTYPE_TAGS.asyncGeneratorFunction;
|
|
181
166
|
}
|
|
182
167
|
|
|
183
168
|
//#endregion
|
|
@@ -189,29 +174,71 @@ function isIterable(value) {
|
|
|
189
174
|
//#endregion
|
|
190
175
|
//#region src/utils/typeof/isMap.ts
|
|
191
176
|
function isMap(value) {
|
|
192
|
-
return resolvePrototypeString(value) ===
|
|
177
|
+
return resolvePrototypeString(value) === PROTOTYPE_TAGS.map;
|
|
178
|
+
}
|
|
179
|
+
function isWeakMap(value) {
|
|
180
|
+
return resolvePrototypeString(value) === PROTOTYPE_TAGS.weakMap;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/utils/typeof/isNaN.ts
|
|
185
|
+
function isNaN(value) {
|
|
186
|
+
return Number.isNaN(value);
|
|
193
187
|
}
|
|
194
188
|
|
|
195
189
|
//#endregion
|
|
196
190
|
//#region src/utils/typeof/isNull.ts
|
|
197
191
|
function isNull(value) {
|
|
198
|
-
return
|
|
192
|
+
return value === null;
|
|
199
193
|
}
|
|
200
194
|
|
|
201
195
|
//#endregion
|
|
202
196
|
//#region src/utils/typeof/isNumber.ts
|
|
203
197
|
function isNumber(value) {
|
|
204
|
-
return
|
|
198
|
+
return typeof value === "number";
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* 检查 value 是否为整数
|
|
202
|
+
*
|
|
203
|
+
* @param value - 待检查值
|
|
204
|
+
* @param safeCheck - 是否附加安全数检查
|
|
205
|
+
*/
|
|
206
|
+
function isInteger(value, safeCheck = true) {
|
|
207
|
+
const check = Number.isInteger(value);
|
|
208
|
+
return safeCheck ? check && Number.isSafeInteger(value) : check;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* 检查 value 是否为正整数
|
|
212
|
+
* - 未考虑 value 为 0 的情况
|
|
213
|
+
*
|
|
214
|
+
* @param value - 待检查值
|
|
215
|
+
* @param safeCheck - 是否附加安全数检查
|
|
216
|
+
*/
|
|
217
|
+
function isPositiveInteger(value, safeCheck = true) {
|
|
218
|
+
return isInteger(value, safeCheck) && value > 0;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* 检查 value 是否为负整数
|
|
222
|
+
* - 未考虑 value 为 0 的情况
|
|
223
|
+
*
|
|
224
|
+
* @param value - 待检查值
|
|
225
|
+
* @param safeCheck - 是否附加安全数检查
|
|
226
|
+
*/
|
|
227
|
+
function isNegativeInteger(value, safeCheck = true) {
|
|
228
|
+
return isInteger(value, safeCheck) && value < 0;
|
|
229
|
+
}
|
|
230
|
+
function isInfinity(value) {
|
|
231
|
+
return isNumber(value) && (Number.POSITIVE_INFINITY === value || Number.NEGATIVE_INFINITY === value);
|
|
232
|
+
}
|
|
233
|
+
function isInfinityLike(value) {
|
|
234
|
+
return isInfinity(value) && typeof value === "string" && (value === "Infinity" || value === "-Infinity" || value === "+Infinity");
|
|
205
235
|
}
|
|
206
236
|
|
|
207
237
|
//#endregion
|
|
208
238
|
//#region src/utils/typeof/isPromise.ts
|
|
209
239
|
function isPromise(value) {
|
|
210
|
-
return resolvePrototypeString(value) ===
|
|
240
|
+
return resolvePrototypeString(value) === PROTOTYPE_TAGS.promise;
|
|
211
241
|
}
|
|
212
|
-
|
|
213
|
-
//#endregion
|
|
214
|
-
//#region src/utils/typeof/isPromiseLike.ts
|
|
215
242
|
function isPromiseLike(value) {
|
|
216
243
|
return isPromise(value) || isObject(value) && isFunction(value["then"]);
|
|
217
244
|
}
|
|
@@ -219,61 +246,58 @@ function isPromiseLike(value) {
|
|
|
219
246
|
//#endregion
|
|
220
247
|
//#region src/utils/typeof/isRegExp.ts
|
|
221
248
|
function isRegExp(value) {
|
|
222
|
-
|
|
249
|
+
if (!isObject(value)) return false;
|
|
250
|
+
try {
|
|
251
|
+
const regex = value;
|
|
252
|
+
return resolvePrototypeString(value) === PROTOTYPE_TAGS.regExp && isString(regex.source) && isString(regex.flags) && isBoolean(regex.global) && isFunction(regex.test);
|
|
253
|
+
} catch (error) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
223
256
|
}
|
|
224
257
|
|
|
225
258
|
//#endregion
|
|
226
259
|
//#region src/utils/typeof/isSet.ts
|
|
227
260
|
function isSet(value) {
|
|
228
|
-
return resolvePrototypeString(value) ===
|
|
261
|
+
return resolvePrototypeString(value) === PROTOTYPE_TAGS.set;
|
|
262
|
+
}
|
|
263
|
+
function isWeakSet(value) {
|
|
264
|
+
return resolvePrototypeString(value) === PROTOTYPE_TAGS.weakSet;
|
|
229
265
|
}
|
|
230
266
|
|
|
231
267
|
//#endregion
|
|
232
268
|
//#region src/utils/typeof/isString.ts
|
|
233
269
|
function isString(value) {
|
|
234
|
-
return
|
|
270
|
+
return typeof value === "string";
|
|
235
271
|
}
|
|
236
272
|
|
|
237
273
|
//#endregion
|
|
238
274
|
//#region src/utils/typeof/isSymbol.ts
|
|
239
275
|
function isSymbol(value) {
|
|
240
|
-
return
|
|
276
|
+
return typeof value === "symbol";
|
|
241
277
|
}
|
|
242
278
|
|
|
243
279
|
//#endregion
|
|
244
280
|
//#region src/utils/typeof/isUndefined.ts
|
|
245
281
|
function isUndefined(value) {
|
|
246
|
-
return
|
|
282
|
+
return typeof value === "undefined";
|
|
247
283
|
}
|
|
248
284
|
|
|
249
285
|
//#endregion
|
|
250
286
|
//#region src/utils/typeof/isURLSearchParams.ts
|
|
251
287
|
function isURLSearchParams(value) {
|
|
252
|
-
return resolvePrototypeString(value) ===
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
//#endregion
|
|
256
|
-
//#region src/utils/typeof/isWeakMap.ts
|
|
257
|
-
function isWeakMap(value) {
|
|
258
|
-
return resolvePrototypeString(value) === prototypeStrings.weakMap;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
//#endregion
|
|
262
|
-
//#region src/utils/typeof/isWeakSet.ts
|
|
263
|
-
function isWeakSet(value) {
|
|
264
|
-
return resolvePrototypeString(value) === prototypeStrings.weakSet;
|
|
288
|
+
return resolvePrototypeString(value) === PROTOTYPE_TAGS.URLSearchParams;
|
|
265
289
|
}
|
|
266
290
|
|
|
267
291
|
//#endregion
|
|
268
292
|
//#region src/utils/typeof/isWebSocket.ts
|
|
269
293
|
function isWebSocket(value) {
|
|
270
|
-
return resolvePrototypeString(value) ===
|
|
294
|
+
return resolvePrototypeString(value) === PROTOTYPE_TAGS.webSocket;
|
|
271
295
|
}
|
|
272
296
|
|
|
273
297
|
//#endregion
|
|
274
298
|
//#region src/utils/typeof/isWindow.ts
|
|
275
299
|
function isWindow(value) {
|
|
276
|
-
return resolvePrototypeString(value) ===
|
|
300
|
+
return resolvePrototypeString(value) === PROTOTYPE_TAGS.window;
|
|
277
301
|
}
|
|
278
302
|
|
|
279
303
|
//#endregion
|
|
@@ -552,7 +576,7 @@ function stringToNumber(value) {
|
|
|
552
576
|
*/
|
|
553
577
|
function toMathBignumber(mathJsInstance, value, saveValue) {
|
|
554
578
|
const errorValue = saveValue ?? mathJsInstance.bignumber(0);
|
|
555
|
-
if (
|
|
579
|
+
if (isFalsyLike(value) || isInfinityLike(value)) return errorValue;
|
|
556
580
|
try {
|
|
557
581
|
return mathJsInstance.bignumber(stringToNumber(`${value}`));
|
|
558
582
|
} catch (error) {
|
|
@@ -1243,5 +1267,5 @@ function treeToRows(tree, options = {}) {
|
|
|
1243
1267
|
}
|
|
1244
1268
|
|
|
1245
1269
|
//#endregion
|
|
1246
|
-
export { arrayCast, arrayCompete, arrayCounting, arrayDifference, arrayFirst, arrayFork, arrayIntersection, arrayLast, arrayMerge, arrayPick, arrayReplace, arraySplit, cloneDeep, enumEntries, enumKeys, enumTypeCheck, enumValues, isArray, isAsyncFunction, isBigInt, isBoolean, isClass, isDate, isEqual, isError, isFalsy, isFalsyLike, isFile, isFunction, isGeneratorFunction, isInfinity, isInfinityLike, isInteger, isIterable, isMap, isNaN, isNull, isNumber, isObject, isPromise, isPromiseLike, isRegExp, isSet, isString, isSymbol, isURLSearchParams, isUndefined, isWeakMap, isWeakSet, isWebSocket, isWindow, mapEntries, objectAssign, objectEntries, objectKeys, objectPick, objectSwitch, objectValues, rowsToTree, stringInitialCase, stringReplace, stringToJson, stringToNumber, stringToValues, to, toMathBignumber, toMathDecimal, toMathEvaluate, treeFilter, treeFind, treeForEach, treeMap, treeToRows };
|
|
1270
|
+
export { arrayCast, arrayCompete, arrayCounting, arrayDifference, arrayFirst, arrayFork, arrayIntersection, arrayLast, arrayMerge, arrayPick, arrayReplace, arraySplit, cloneDeep, enumEntries, enumKeys, enumTypeCheck, enumValues, isArray, isAsyncFunction, isAsyncGeneratorFunction, isBigInt, isBoolean, isClass, isDate, isEqual, isError, isFalsy, isFalsyLike, isFile, isFunction, isGeneratorFunction, isInfinity, isInfinityLike, isInteger, isIterable, isMap, isNaN, isNegativeInteger, isNull, isNumber, isObject, isPositiveInteger, isPromise, isPromiseLike, isRegExp, isSet, isString, isSymbol, isTypedArray, isURLSearchParams, isUndefined, isWeakMap, isWeakSet, isWebSocket, isWindow, mapEntries, objectAssign, objectEntries, objectKeys, objectPick, objectSwitch, objectValues, rowsToTree, stringInitialCase, stringReplace, stringToJson, stringToNumber, stringToValues, to, toMathBignumber, toMathDecimal, toMathEvaluate, treeFilter, treeFind, treeForEach, treeMap, treeToRows };
|
|
1247
1271
|
//# sourceMappingURL=index.js.map
|