@pawover/kit 0.0.1 → 0.1.1
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/package.json +42 -45
- package/packages/hooks/dist/alova.d.ts +3 -4
- package/packages/hooks/dist/metadata.json +0 -1
- package/packages/hooks/dist/react.d.ts +4 -13
- package/packages/hooks/dist/react.js +820 -244
- package/packages/utils/dist/index.d.ts +697 -70
- package/packages/utils/dist/index.js +216 -2
- package/packages/utils/dist/math.d.ts +4 -0
- package/packages/utils/dist/math.js +1 -1
- package/packages/utils/dist/{string-DCWqoW4P.js → string-p6hZ1Mjb.js} +174 -7
- package/packages/utils/dist/vite.d.ts +13 -0
- package/packages/utils/dist/vite.js +13 -0
|
@@ -1,240 +1,4 @@
|
|
|
1
1
|
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
2
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.46.1/node_modules/es-toolkit/dist/_internal/globalThis.mjs
|
|
3
|
-
const globalThis_ = typeof globalThis === "object" && globalThis || typeof window === "object" && window || typeof self === "object" && self || typeof global === "object" && global || (function() {
|
|
4
|
-
return this;
|
|
5
|
-
})() || Function("return this")();
|
|
6
|
-
//#endregion
|
|
7
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.46.1/node_modules/es-toolkit/dist/function/noop.mjs
|
|
8
|
-
function noop() {}
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.46.1/node_modules/es-toolkit/dist/predicate/isPrimitive.mjs
|
|
11
|
-
function isPrimitive(value) {
|
|
12
|
-
return value == null || typeof value !== "object" && typeof value !== "function";
|
|
13
|
-
}
|
|
14
|
-
//#endregion
|
|
15
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.46.1/node_modules/es-toolkit/dist/predicate/isTypedArray.mjs
|
|
16
|
-
function isTypedArray(x) {
|
|
17
|
-
return ArrayBuffer.isView(x) && !(x instanceof DataView);
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.46.1/node_modules/es-toolkit/dist/object/clone.mjs
|
|
21
|
-
function clone(obj) {
|
|
22
|
-
if (isPrimitive(obj)) return obj;
|
|
23
|
-
if (Array.isArray(obj) || isTypedArray(obj) || obj instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && obj instanceof SharedArrayBuffer) return obj.slice(0);
|
|
24
|
-
const prototype = Object.getPrototypeOf(obj);
|
|
25
|
-
if (prototype == null) return Object.assign(Object.create(prototype), obj);
|
|
26
|
-
const Constructor = prototype.constructor;
|
|
27
|
-
if (obj instanceof Date || obj instanceof Map || obj instanceof Set) return new Constructor(obj);
|
|
28
|
-
if (obj instanceof RegExp) {
|
|
29
|
-
const newRegExp = new Constructor(obj);
|
|
30
|
-
newRegExp.lastIndex = obj.lastIndex;
|
|
31
|
-
return newRegExp;
|
|
32
|
-
}
|
|
33
|
-
if (obj instanceof DataView) return new Constructor(obj.buffer.slice(0));
|
|
34
|
-
if (obj instanceof Error) {
|
|
35
|
-
let newError;
|
|
36
|
-
if (obj instanceof AggregateError) newError = new Constructor(obj.errors, obj.message, { cause: obj.cause });
|
|
37
|
-
else newError = new Constructor(obj.message, { cause: obj.cause });
|
|
38
|
-
newError.stack = obj.stack;
|
|
39
|
-
Object.assign(newError, obj);
|
|
40
|
-
return newError;
|
|
41
|
-
}
|
|
42
|
-
if (typeof File !== "undefined" && obj instanceof File) return new Constructor([obj], obj.name, {
|
|
43
|
-
type: obj.type,
|
|
44
|
-
lastModified: obj.lastModified
|
|
45
|
-
});
|
|
46
|
-
if (typeof obj === "object") return Object.assign(Object.create(prototype), obj);
|
|
47
|
-
return obj;
|
|
48
|
-
}
|
|
49
|
-
//#endregion
|
|
50
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.46.1/node_modules/es-toolkit/dist/compat/_internal/getSymbols.mjs
|
|
51
|
-
function getSymbols(object) {
|
|
52
|
-
return Object.getOwnPropertySymbols(object).filter((symbol) => Object.prototype.propertyIsEnumerable.call(object, symbol));
|
|
53
|
-
}
|
|
54
|
-
//#endregion
|
|
55
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.46.1/node_modules/es-toolkit/dist/compat/_internal/getTag.mjs
|
|
56
|
-
function getTag(value) {
|
|
57
|
-
if (value == null) return value === void 0 ? "[object Undefined]" : "[object Null]";
|
|
58
|
-
return Object.prototype.toString.call(value);
|
|
59
|
-
}
|
|
60
|
-
//#endregion
|
|
61
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.46.1/node_modules/es-toolkit/dist/compat/_internal/tags.mjs
|
|
62
|
-
const regexpTag = "[object RegExp]";
|
|
63
|
-
const stringTag = "[object String]";
|
|
64
|
-
const numberTag = "[object Number]";
|
|
65
|
-
const booleanTag = "[object Boolean]";
|
|
66
|
-
const symbolTag = "[object Symbol]";
|
|
67
|
-
const dateTag = "[object Date]";
|
|
68
|
-
const mapTag = "[object Map]";
|
|
69
|
-
const setTag = "[object Set]";
|
|
70
|
-
const arrayTag = "[object Array]";
|
|
71
|
-
const functionTag = "[object Function]";
|
|
72
|
-
const arrayBufferTag = "[object ArrayBuffer]";
|
|
73
|
-
const objectTag = "[object Object]";
|
|
74
|
-
const errorTag = "[object Error]";
|
|
75
|
-
const dataViewTag = "[object DataView]";
|
|
76
|
-
const uint8ArrayTag = "[object Uint8Array]";
|
|
77
|
-
const uint8ClampedArrayTag = "[object Uint8ClampedArray]";
|
|
78
|
-
const uint16ArrayTag = "[object Uint16Array]";
|
|
79
|
-
const uint32ArrayTag = "[object Uint32Array]";
|
|
80
|
-
const bigUint64ArrayTag = "[object BigUint64Array]";
|
|
81
|
-
const int8ArrayTag = "[object Int8Array]";
|
|
82
|
-
const int16ArrayTag = "[object Int16Array]";
|
|
83
|
-
const int32ArrayTag = "[object Int32Array]";
|
|
84
|
-
const bigInt64ArrayTag = "[object BigInt64Array]";
|
|
85
|
-
const float32ArrayTag = "[object Float32Array]";
|
|
86
|
-
const float64ArrayTag = "[object Float64Array]";
|
|
87
|
-
//#endregion
|
|
88
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.46.1/node_modules/es-toolkit/dist/predicate/isBuffer.mjs
|
|
89
|
-
function isBuffer(x) {
|
|
90
|
-
return typeof globalThis_.Buffer !== "undefined" && globalThis_.Buffer.isBuffer(x);
|
|
91
|
-
}
|
|
92
|
-
//#endregion
|
|
93
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.46.1/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs
|
|
94
|
-
function isPlainObject(value) {
|
|
95
|
-
if (!value || typeof value !== "object") return false;
|
|
96
|
-
const proto = Object.getPrototypeOf(value);
|
|
97
|
-
if (!(proto === null || proto === Object.prototype || Object.getPrototypeOf(proto) === null)) return false;
|
|
98
|
-
return Object.prototype.toString.call(value) === "[object Object]";
|
|
99
|
-
}
|
|
100
|
-
//#endregion
|
|
101
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.46.1/node_modules/es-toolkit/dist/_internal/isEqualsSameValueZero.mjs
|
|
102
|
-
function isEqualsSameValueZero(value, other) {
|
|
103
|
-
return value === other || Number.isNaN(value) && Number.isNaN(other);
|
|
104
|
-
}
|
|
105
|
-
//#endregion
|
|
106
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.46.1/node_modules/es-toolkit/dist/predicate/isEqualWith.mjs
|
|
107
|
-
function isEqualWith(a, b, areValuesEqual) {
|
|
108
|
-
return isEqualWithImpl(a, b, void 0, void 0, void 0, void 0, areValuesEqual);
|
|
109
|
-
}
|
|
110
|
-
function isEqualWithImpl(a, b, property, aParent, bParent, stack, areValuesEqual) {
|
|
111
|
-
const result = areValuesEqual(a, b, property, aParent, bParent, stack);
|
|
112
|
-
if (result !== void 0) return result;
|
|
113
|
-
if (typeof a === typeof b) switch (typeof a) {
|
|
114
|
-
case "bigint":
|
|
115
|
-
case "string":
|
|
116
|
-
case "boolean":
|
|
117
|
-
case "symbol":
|
|
118
|
-
case "undefined": return a === b;
|
|
119
|
-
case "number": return a === b || Object.is(a, b);
|
|
120
|
-
case "function": return a === b;
|
|
121
|
-
case "object": return areObjectsEqual(a, b, stack, areValuesEqual);
|
|
122
|
-
}
|
|
123
|
-
return areObjectsEqual(a, b, stack, areValuesEqual);
|
|
124
|
-
}
|
|
125
|
-
function areObjectsEqual(a, b, stack, areValuesEqual) {
|
|
126
|
-
if (Object.is(a, b)) return true;
|
|
127
|
-
let aTag = getTag(a);
|
|
128
|
-
let bTag = getTag(b);
|
|
129
|
-
if (aTag === "[object Arguments]") aTag = objectTag;
|
|
130
|
-
if (bTag === "[object Arguments]") bTag = objectTag;
|
|
131
|
-
if (aTag !== bTag) return false;
|
|
132
|
-
switch (aTag) {
|
|
133
|
-
case stringTag: return a.toString() === b.toString();
|
|
134
|
-
case numberTag: return isEqualsSameValueZero(a.valueOf(), b.valueOf());
|
|
135
|
-
case booleanTag:
|
|
136
|
-
case dateTag:
|
|
137
|
-
case symbolTag: return Object.is(a.valueOf(), b.valueOf());
|
|
138
|
-
case regexpTag: return a.source === b.source && a.flags === b.flags;
|
|
139
|
-
case functionTag: return a === b;
|
|
140
|
-
}
|
|
141
|
-
stack = stack ?? /* @__PURE__ */ new Map();
|
|
142
|
-
const aStack = stack.get(a);
|
|
143
|
-
const bStack = stack.get(b);
|
|
144
|
-
if (aStack != null && bStack != null) return aStack === b;
|
|
145
|
-
stack.set(a, b);
|
|
146
|
-
stack.set(b, a);
|
|
147
|
-
try {
|
|
148
|
-
switch (aTag) {
|
|
149
|
-
case mapTag:
|
|
150
|
-
if (a.size !== b.size) return false;
|
|
151
|
-
for (const [key, value] of a.entries()) if (!b.has(key) || !isEqualWithImpl(value, b.get(key), key, a, b, stack, areValuesEqual)) return false;
|
|
152
|
-
return true;
|
|
153
|
-
case setTag: {
|
|
154
|
-
if (a.size !== b.size) return false;
|
|
155
|
-
const aValues = Array.from(a.values());
|
|
156
|
-
const bValues = Array.from(b.values());
|
|
157
|
-
for (let i = 0; i < aValues.length; i++) {
|
|
158
|
-
const aValue = aValues[i];
|
|
159
|
-
const index = bValues.findIndex((bValue) => {
|
|
160
|
-
return isEqualWithImpl(aValue, bValue, void 0, a, b, stack, areValuesEqual);
|
|
161
|
-
});
|
|
162
|
-
if (index === -1) return false;
|
|
163
|
-
bValues.splice(index, 1);
|
|
164
|
-
}
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
|
-
case arrayTag:
|
|
168
|
-
case uint8ArrayTag:
|
|
169
|
-
case uint8ClampedArrayTag:
|
|
170
|
-
case uint16ArrayTag:
|
|
171
|
-
case uint32ArrayTag:
|
|
172
|
-
case bigUint64ArrayTag:
|
|
173
|
-
case int8ArrayTag:
|
|
174
|
-
case int16ArrayTag:
|
|
175
|
-
case int32ArrayTag:
|
|
176
|
-
case bigInt64ArrayTag:
|
|
177
|
-
case float32ArrayTag:
|
|
178
|
-
case float64ArrayTag:
|
|
179
|
-
if (isBuffer(a) !== isBuffer(b)) return false;
|
|
180
|
-
if (a.length !== b.length) return false;
|
|
181
|
-
for (let i = 0; i < a.length; i++) if (!isEqualWithImpl(a[i], b[i], i, a, b, stack, areValuesEqual)) return false;
|
|
182
|
-
return true;
|
|
183
|
-
case arrayBufferTag:
|
|
184
|
-
if (a.byteLength !== b.byteLength) return false;
|
|
185
|
-
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
|
|
186
|
-
case dataViewTag:
|
|
187
|
-
if (a.byteLength !== b.byteLength || a.byteOffset !== b.byteOffset) return false;
|
|
188
|
-
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
|
|
189
|
-
case errorTag: return a.name === b.name && a.message === b.message;
|
|
190
|
-
case objectTag: {
|
|
191
|
-
if (!(areObjectsEqual(a.constructor, b.constructor, stack, areValuesEqual) || isPlainObject(a) && isPlainObject(b))) return false;
|
|
192
|
-
const aKeys = [...Object.keys(a), ...getSymbols(a)];
|
|
193
|
-
const bKeys = [...Object.keys(b), ...getSymbols(b)];
|
|
194
|
-
if (aKeys.length !== bKeys.length) return false;
|
|
195
|
-
for (let i = 0; i < aKeys.length; i++) {
|
|
196
|
-
const propKey = aKeys[i];
|
|
197
|
-
const aProp = a[propKey];
|
|
198
|
-
if (!Object.hasOwn(b, propKey)) return false;
|
|
199
|
-
const bProp = b[propKey];
|
|
200
|
-
if (!isEqualWithImpl(aProp, bProp, propKey, a, b, stack, areValuesEqual)) return false;
|
|
201
|
-
}
|
|
202
|
-
return true;
|
|
203
|
-
}
|
|
204
|
-
default: return false;
|
|
205
|
-
}
|
|
206
|
-
} finally {
|
|
207
|
-
stack.delete(a);
|
|
208
|
-
stack.delete(b);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
//#endregion
|
|
212
|
-
//#region ../../node_modules/.pnpm/es-toolkit@1.46.1/node_modules/es-toolkit/dist/predicate/isEqual.mjs
|
|
213
|
-
function isEqual(a, b) {
|
|
214
|
-
return isEqualWith(a, b, noop);
|
|
215
|
-
}
|
|
216
|
-
//#endregion
|
|
217
|
-
//#region src/react/useCreation.ts
|
|
218
|
-
/**
|
|
219
|
-
* 确保实例不会被重复创建
|
|
220
|
-
*
|
|
221
|
-
* @param factory
|
|
222
|
-
* @param deps
|
|
223
|
-
*/
|
|
224
|
-
function useCreation(factory, deps) {
|
|
225
|
-
const { current } = useRef({
|
|
226
|
-
deps,
|
|
227
|
-
result: void 0,
|
|
228
|
-
isInitialized: false
|
|
229
|
-
});
|
|
230
|
-
if (current.isInitialized === false || !isEqual(current.deps, deps)) {
|
|
231
|
-
current.deps = deps;
|
|
232
|
-
current.result = factory();
|
|
233
|
-
current.isInitialized = true;
|
|
234
|
-
}
|
|
235
|
-
return current.result;
|
|
236
|
-
}
|
|
237
|
-
//#endregion
|
|
238
2
|
//#region src/react/useLatest.ts
|
|
239
3
|
/**
|
|
240
4
|
* 返回当前最新值的 Hook
|
|
@@ -247,7 +11,7 @@ function useLatest(value) {
|
|
|
247
11
|
return ref;
|
|
248
12
|
}
|
|
249
13
|
//#endregion
|
|
250
|
-
//#region ../utils/dist/string-
|
|
14
|
+
//#region ../utils/dist/string-p6hZ1Mjb.js
|
|
251
15
|
function _typeof(o) {
|
|
252
16
|
"@babel/helpers - typeof";
|
|
253
17
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -301,25 +65,29 @@ var TypeUtil = class {
|
|
|
301
65
|
}
|
|
302
66
|
/**
|
|
303
67
|
* 检查 value 是否为 string 类型
|
|
68
|
+
* - 当 `checkEmpty` 为 `true` 时,会先 trim 再判断是否为空
|
|
304
69
|
*
|
|
305
70
|
* @param value 待检查值
|
|
306
|
-
* @param checkEmpty
|
|
71
|
+
* @param checkEmpty 是否检查空字符串(含空白字符串),默认为 `false`
|
|
307
72
|
* @returns 是否为字符串
|
|
308
73
|
* @example
|
|
309
74
|
* ```ts
|
|
310
75
|
* TypeUtil.isString("abc"); // true
|
|
311
76
|
* TypeUtil.isString(""); // true
|
|
312
77
|
* TypeUtil.isString("", true); // false
|
|
78
|
+
* TypeUtil.isString(" ", true); // false
|
|
79
|
+
* TypeUtil.isString(" a ", true); // true
|
|
313
80
|
* ```
|
|
314
81
|
*/
|
|
315
82
|
static isString(value, checkEmpty = false) {
|
|
316
|
-
return typeof value === "string" && (!checkEmpty ||
|
|
83
|
+
return typeof value === "string" && (!checkEmpty || value.trim().length > 0);
|
|
317
84
|
}
|
|
318
85
|
/**
|
|
319
86
|
* 检查 value 是否为 number 类型
|
|
87
|
+
* - 默认会调用 `TypeUtil.isNaN`(内部基于 `Number.isNaN`)过滤掉 `NaN`
|
|
320
88
|
*
|
|
321
89
|
* @param value 待检查值
|
|
322
|
-
* @param checkNaN
|
|
90
|
+
* @param checkNaN 是否检查 `NaN`,默认为 `true`
|
|
323
91
|
* @returns 是否为 number
|
|
324
92
|
* @example
|
|
325
93
|
* ```ts
|
|
@@ -333,9 +101,15 @@ var TypeUtil = class {
|
|
|
333
101
|
}
|
|
334
102
|
/**
|
|
335
103
|
* 检查 value 是否为 NaN
|
|
104
|
+
* - 禁止使用全局 `isNaN`,其会先进行隐式数字转换,可能导致误判(例如 `isNaN("foo") === true`)
|
|
105
|
+
* - 使用 `Number.isNaN` 仅在值本身就是 `NaN` 时返回 `true`,语义更严格且更安全
|
|
336
106
|
*
|
|
337
107
|
* @param value 待检查值
|
|
338
108
|
* @returns 是否为 NaN
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* TypeUtil.isNaN(NaN); // true
|
|
112
|
+
* ```
|
|
339
113
|
*/
|
|
340
114
|
static isNaN(value) {
|
|
341
115
|
return Number.isNaN(value);
|
|
@@ -346,6 +120,11 @@ var TypeUtil = class {
|
|
|
346
120
|
* @param value 待检查值
|
|
347
121
|
* @param checkSafe 是否附加安全整数检查
|
|
348
122
|
* @returns 是否为整数
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* TypeUtil.isInteger(1); // true
|
|
126
|
+
* TypeUtil.isInteger(1.1); // false
|
|
127
|
+
* ```
|
|
349
128
|
*/
|
|
350
129
|
static isInteger(value, checkSafe = true) {
|
|
351
130
|
const check = Number.isInteger(value);
|
|
@@ -357,6 +136,11 @@ var TypeUtil = class {
|
|
|
357
136
|
*
|
|
358
137
|
* @param value 待检查值
|
|
359
138
|
* @param checkSafe 是否附加安全整数检查
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* TypeUtil.isPositiveInteger(1); // true
|
|
142
|
+
* TypeUtil.isPositiveInteger(0); // false
|
|
143
|
+
* ```
|
|
360
144
|
*/
|
|
361
145
|
static isPositiveInteger(value, checkSafe = true) {
|
|
362
146
|
return this.isInteger(value, checkSafe) && value > 0;
|
|
@@ -367,6 +151,11 @@ var TypeUtil = class {
|
|
|
367
151
|
*
|
|
368
152
|
* @param value 待检查值
|
|
369
153
|
* @param checkSafe 是否附加安全整数检查
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* TypeUtil.isNegativeInteger(-1); // true
|
|
157
|
+
* TypeUtil.isNegativeInteger(0); // false
|
|
158
|
+
* ```
|
|
370
159
|
*/
|
|
371
160
|
static isNegativeInteger(value, checkSafe = true) {
|
|
372
161
|
return this.isInteger(value, checkSafe) && value < 0;
|
|
@@ -376,6 +165,11 @@ var TypeUtil = class {
|
|
|
376
165
|
* - 排除 `NaN`
|
|
377
166
|
*
|
|
378
167
|
* @param value 待检查值
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* TypeUtil.isInfinity(Infinity); // true
|
|
171
|
+
* TypeUtil.isInfinity(1); // false
|
|
172
|
+
* ```
|
|
379
173
|
*/
|
|
380
174
|
static isInfinity(value) {
|
|
381
175
|
return this.isNumber(value) && (Number.POSITIVE_INFINITY === value || Number.NEGATIVE_INFINITY === value);
|
|
@@ -385,6 +179,11 @@ var TypeUtil = class {
|
|
|
385
179
|
* - 排除 `NaN`
|
|
386
180
|
*
|
|
387
181
|
* @param value 待检查值
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* TypeUtil.isInfinityLike("Infinity"); // true
|
|
185
|
+
* TypeUtil.isInfinityLike("123"); // false
|
|
186
|
+
* ```
|
|
388
187
|
*/
|
|
389
188
|
static isInfinityLike(value) {
|
|
390
189
|
const check = this.isInfinity(value);
|
|
@@ -403,6 +202,10 @@ var TypeUtil = class {
|
|
|
403
202
|
* 检查 value 是否为 Boolean
|
|
404
203
|
* @param value 待检查值
|
|
405
204
|
* @returns 是否为 Boolean
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* TypeUtil.isBoolean(false); // true
|
|
208
|
+
* ```
|
|
406
209
|
*/
|
|
407
210
|
static isBoolean(value) {
|
|
408
211
|
return typeof value === "boolean";
|
|
@@ -411,6 +214,10 @@ var TypeUtil = class {
|
|
|
411
214
|
* 检查 value 是否为 BigInt
|
|
412
215
|
* @param value 待检查值
|
|
413
216
|
* @returns 是否为 BigInt
|
|
217
|
+
* @example
|
|
218
|
+
* ```ts
|
|
219
|
+
* TypeUtil.isBigInt(1n); // true
|
|
220
|
+
* ```
|
|
414
221
|
*/
|
|
415
222
|
static isBigInt(value) {
|
|
416
223
|
return typeof value === "bigint";
|
|
@@ -419,6 +226,10 @@ var TypeUtil = class {
|
|
|
419
226
|
* 检查 value 是否为 Symbol
|
|
420
227
|
* @param value 待检查值
|
|
421
228
|
* @returns 是否为 Symbol
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* TypeUtil.isSymbol(Symbol("a")); // true
|
|
232
|
+
* ```
|
|
422
233
|
*/
|
|
423
234
|
static isSymbol(value) {
|
|
424
235
|
return typeof value === "symbol";
|
|
@@ -427,6 +238,10 @@ var TypeUtil = class {
|
|
|
427
238
|
* 检查 value 是否为 undefined
|
|
428
239
|
* @param value 待检查值
|
|
429
240
|
* @returns 是否为 undefined
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* TypeUtil.isUndefined(undefined); // true
|
|
244
|
+
* ```
|
|
430
245
|
*/
|
|
431
246
|
static isUndefined(value) {
|
|
432
247
|
return typeof value === "undefined";
|
|
@@ -435,6 +250,10 @@ var TypeUtil = class {
|
|
|
435
250
|
* 检查 value 是否为 null
|
|
436
251
|
* @param value 待检查值
|
|
437
252
|
* @returns 是否为 null
|
|
253
|
+
* @example
|
|
254
|
+
* ```ts
|
|
255
|
+
* TypeUtil.isNull(null); // true
|
|
256
|
+
* ```
|
|
438
257
|
*/
|
|
439
258
|
static isNull(value) {
|
|
440
259
|
return value === null;
|
|
@@ -443,6 +262,10 @@ var TypeUtil = class {
|
|
|
443
262
|
* 检查 value 是否为 Function
|
|
444
263
|
* @param value 待检查值
|
|
445
264
|
* @returns 是否为 Function
|
|
265
|
+
* @example
|
|
266
|
+
* ```ts
|
|
267
|
+
* TypeUtil.isFunction(() => {}); // true
|
|
268
|
+
* ```
|
|
446
269
|
*/
|
|
447
270
|
static isFunction(value) {
|
|
448
271
|
return typeof value === "function";
|
|
@@ -451,6 +274,10 @@ var TypeUtil = class {
|
|
|
451
274
|
* 检查 value 是否为 AsyncFunction
|
|
452
275
|
* @param value 待检查值
|
|
453
276
|
* @returns 是否为 AsyncFunction
|
|
277
|
+
* @example
|
|
278
|
+
* ```ts
|
|
279
|
+
* TypeUtil.isAsyncFunction(async () => {}); // true
|
|
280
|
+
* ```
|
|
454
281
|
*/
|
|
455
282
|
static isAsyncFunction(value) {
|
|
456
283
|
return this.isFunction(value) && this.getPrototypeString(value) === this.PROTOTYPE_TAGS.ASYNC_FUNCTION;
|
|
@@ -459,6 +286,10 @@ var TypeUtil = class {
|
|
|
459
286
|
* 检查 value 是否为 GeneratorFunction
|
|
460
287
|
* @param value 待检查值
|
|
461
288
|
* @returns 是否为 GeneratorFunction
|
|
289
|
+
* @example
|
|
290
|
+
* ```ts
|
|
291
|
+
* TypeUtil.isGeneratorFunction(function * a () {}); // true
|
|
292
|
+
* ```
|
|
462
293
|
*/
|
|
463
294
|
static isGeneratorFunction(value) {
|
|
464
295
|
return this.isFunction(value) && this.getPrototypeString(value) === this.PROTOTYPE_TAGS.GENERATOR_FUNCTION;
|
|
@@ -467,6 +298,10 @@ var TypeUtil = class {
|
|
|
467
298
|
* 检查 value 是否为 AsyncGeneratorFunction
|
|
468
299
|
* @param value 待检查值
|
|
469
300
|
* @returns 是否为 AsyncGeneratorFunction
|
|
301
|
+
* @example
|
|
302
|
+
* ```ts
|
|
303
|
+
* TypeUtil.isAsyncGeneratorFunction(async function * a () {}); // true
|
|
304
|
+
* ```
|
|
470
305
|
*/
|
|
471
306
|
static isAsyncGeneratorFunction(value) {
|
|
472
307
|
return this.isFunction(value) && this.getPrototypeString(value) === this.PROTOTYPE_TAGS.ASYNC_GENERATOR_FUNCTION;
|
|
@@ -475,8 +310,12 @@ var TypeUtil = class {
|
|
|
475
310
|
* 检查 value 是否为 Promise
|
|
476
311
|
* @param value 待检查值
|
|
477
312
|
* @returns 是否为 Promise
|
|
478
|
-
|
|
479
|
-
|
|
313
|
+
* @example
|
|
314
|
+
* ```ts
|
|
315
|
+
* TypeUtil.isPromise(Promise.resolve(1)); // true
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
static isPromise(value) {
|
|
480
319
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.PROMISE;
|
|
481
320
|
}
|
|
482
321
|
/**
|
|
@@ -484,6 +323,10 @@ var TypeUtil = class {
|
|
|
484
323
|
* - 可识别拥有 then 方法的非 Promise 对象
|
|
485
324
|
* @param value 待检查值
|
|
486
325
|
* @returns 是否为 PromiseLike
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* TypeUtil.isPromiseLike({ then: () => {} }); // true
|
|
329
|
+
* ```
|
|
487
330
|
*/
|
|
488
331
|
static isPromiseLike(value) {
|
|
489
332
|
return this.isPromise(value) || this.isObject(value, false) && this.isFunction(value["then"]);
|
|
@@ -519,6 +362,11 @@ var TypeUtil = class {
|
|
|
519
362
|
*
|
|
520
363
|
* @param enumeration 待检查值
|
|
521
364
|
* @returns [是否为有效的枚举, 是否为双向枚举]
|
|
365
|
+
* @example
|
|
366
|
+
* ```ts
|
|
367
|
+
* enum A { X, Y }
|
|
368
|
+
* TypeUtil.isEnumeration(A); // [true, true]
|
|
369
|
+
* ```
|
|
522
370
|
*/
|
|
523
371
|
static isEnumeration(enumeration) {
|
|
524
372
|
if (typeof enumeration !== "object" || enumeration === null) return [false, false];
|
|
@@ -600,6 +448,10 @@ var TypeUtil = class {
|
|
|
600
448
|
* 检查 value 是否为 Map
|
|
601
449
|
* @param value 待检查值
|
|
602
450
|
* @returns 是否为 Map
|
|
451
|
+
* @example
|
|
452
|
+
* ```ts
|
|
453
|
+
* TypeUtil.isMap(new Map()); // true
|
|
454
|
+
* ```
|
|
603
455
|
*/
|
|
604
456
|
static isMap(value) {
|
|
605
457
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.MAP;
|
|
@@ -608,6 +460,10 @@ var TypeUtil = class {
|
|
|
608
460
|
* 检查 value 是否为 WeakMap
|
|
609
461
|
* @param value 待检查值
|
|
610
462
|
* @returns 是否为 WeakMap
|
|
463
|
+
* @example
|
|
464
|
+
* ```ts
|
|
465
|
+
* TypeUtil.isWeakMap(new WeakMap()); // true
|
|
466
|
+
* ```
|
|
611
467
|
*/
|
|
612
468
|
static isWeakMap(value) {
|
|
613
469
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.WEAK_MAP;
|
|
@@ -616,6 +472,10 @@ var TypeUtil = class {
|
|
|
616
472
|
* 检查 value 是否为 Set
|
|
617
473
|
* @param value 待检查值
|
|
618
474
|
* @returns 是否为 Set
|
|
475
|
+
* @example
|
|
476
|
+
* ```ts
|
|
477
|
+
* TypeUtil.isSet(new Set()); // true
|
|
478
|
+
* ```
|
|
619
479
|
*/
|
|
620
480
|
static isSet(value) {
|
|
621
481
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.SET;
|
|
@@ -624,6 +484,10 @@ var TypeUtil = class {
|
|
|
624
484
|
* 检查 value 是否为 WeakSet
|
|
625
485
|
* @param value 待检查值
|
|
626
486
|
* @returns 是否为 WeakSet
|
|
487
|
+
* @example
|
|
488
|
+
* ```ts
|
|
489
|
+
* TypeUtil.isWeakSet(new WeakSet()); // true
|
|
490
|
+
* ```
|
|
627
491
|
*/
|
|
628
492
|
static isWeakSet(value) {
|
|
629
493
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.WEAK_SET;
|
|
@@ -632,6 +496,10 @@ var TypeUtil = class {
|
|
|
632
496
|
* 检查 value 是否为 Blob
|
|
633
497
|
* @param value 待检查值
|
|
634
498
|
* @returns 是否为 Blob
|
|
499
|
+
* @example
|
|
500
|
+
* ```ts
|
|
501
|
+
* TypeUtil.isBlob(new Blob(["a"])); // true
|
|
502
|
+
* ```
|
|
635
503
|
*/
|
|
636
504
|
static isBlob(value) {
|
|
637
505
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.BLOB;
|
|
@@ -640,6 +508,10 @@ var TypeUtil = class {
|
|
|
640
508
|
* 检查 value 是否为 File
|
|
641
509
|
* @param value 待检查值
|
|
642
510
|
* @returns 是否为 File
|
|
511
|
+
* @example
|
|
512
|
+
* ```ts
|
|
513
|
+
* TypeUtil.isFile(new File(["a"], "a.txt")); // true
|
|
514
|
+
* ```
|
|
643
515
|
*/
|
|
644
516
|
static isFile(value) {
|
|
645
517
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.FILE;
|
|
@@ -653,6 +525,10 @@ var TypeUtil = class {
|
|
|
653
525
|
*
|
|
654
526
|
* @param value 待检查值
|
|
655
527
|
* @returns 是否为 ReadableStream
|
|
528
|
+
* @example
|
|
529
|
+
* ```ts
|
|
530
|
+
* TypeUtil.isReadableStream(new ReadableStream()); // true
|
|
531
|
+
* ```
|
|
656
532
|
*/
|
|
657
533
|
static isReadableStream(value) {
|
|
658
534
|
if (this.getPrototypeString(value) === this.PROTOTYPE_TAGS.READABLE_STREAM) return true;
|
|
@@ -662,6 +538,10 @@ var TypeUtil = class {
|
|
|
662
538
|
* 检查 value 是否为 Window
|
|
663
539
|
* @param value 待检查值
|
|
664
540
|
* @returns 是否为 Window
|
|
541
|
+
* @example
|
|
542
|
+
* ```ts
|
|
543
|
+
* TypeUtil.isWindow(window); // true
|
|
544
|
+
* ```
|
|
665
545
|
*/
|
|
666
546
|
static isWindow(value) {
|
|
667
547
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.WINDOW;
|
|
@@ -670,6 +550,10 @@ var TypeUtil = class {
|
|
|
670
550
|
* 检查 value 是否为 HTMLIFrameElement
|
|
671
551
|
* @param value 待检查值
|
|
672
552
|
* @returns 是否为 HTMLIFrameElement
|
|
553
|
+
* @example
|
|
554
|
+
* ```ts
|
|
555
|
+
* TypeUtil.isIframe(document.createElement("iframe")); // true
|
|
556
|
+
* ```
|
|
673
557
|
*/
|
|
674
558
|
static isIframe(value) {
|
|
675
559
|
if (typeof window === "undefined") return false;
|
|
@@ -708,6 +592,10 @@ var TypeUtil = class {
|
|
|
708
592
|
* 检查 value 是否为 Error 对象
|
|
709
593
|
* @param value 待检查值
|
|
710
594
|
* @returns 是否为 Error
|
|
595
|
+
* @example
|
|
596
|
+
* ```ts
|
|
597
|
+
* TypeUtil.isError(new Error("x")); // true
|
|
598
|
+
* ```
|
|
711
599
|
*/
|
|
712
600
|
static isError(value) {
|
|
713
601
|
return value instanceof Error || this.getPrototypeString(value) === this.PROTOTYPE_TAGS.ERROR;
|
|
@@ -716,6 +604,10 @@ var TypeUtil = class {
|
|
|
716
604
|
* 检查 value 是否为 RegExp
|
|
717
605
|
* @param value 待检查值
|
|
718
606
|
* @returns 是否为 RegExp
|
|
607
|
+
* @example
|
|
608
|
+
* ```ts
|
|
609
|
+
* TypeUtil.isRegExp(/a/); // true
|
|
610
|
+
* ```
|
|
719
611
|
*/
|
|
720
612
|
static isRegExp(value) {
|
|
721
613
|
if (typeof value !== "object" || value === null) return false;
|
|
@@ -730,6 +622,10 @@ var TypeUtil = class {
|
|
|
730
622
|
* 检查 value 是否为 WebSocket
|
|
731
623
|
* @param value 待检查值
|
|
732
624
|
* @returns 是否为 WebSocket
|
|
625
|
+
* @example
|
|
626
|
+
* ```ts
|
|
627
|
+
* TypeUtil.isWebSocket(new WebSocket("wss://echo.websocket.events")); // true
|
|
628
|
+
* ```
|
|
733
629
|
*/
|
|
734
630
|
static isWebSocket(value) {
|
|
735
631
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.WEB_SOCKET;
|
|
@@ -738,6 +634,10 @@ var TypeUtil = class {
|
|
|
738
634
|
* 检查 value 是否为 URLSearchParams
|
|
739
635
|
* @param value 待检查值
|
|
740
636
|
* @returns 是否为 URLSearchParams
|
|
637
|
+
* @example
|
|
638
|
+
* ```ts
|
|
639
|
+
* TypeUtil.isURLSearchParams(new URLSearchParams("a=1")); // true
|
|
640
|
+
* ```
|
|
741
641
|
*/
|
|
742
642
|
static isURLSearchParams(value) {
|
|
743
643
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.URL_SEARCH_PARAMS;
|
|
@@ -746,6 +646,10 @@ var TypeUtil = class {
|
|
|
746
646
|
* 检查 value 是否为 AbortSignal
|
|
747
647
|
* @param value 待检查值
|
|
748
648
|
* @returns 是否为 AbortSignal
|
|
649
|
+
* @example
|
|
650
|
+
* ```ts
|
|
651
|
+
* TypeUtil.isAbortSignal(new AbortController().signal); // true
|
|
652
|
+
* ```
|
|
749
653
|
*/
|
|
750
654
|
static isAbortSignal(value) {
|
|
751
655
|
return this.getPrototypeString(value) === this.PROTOTYPE_TAGS.ABORT_SIGNAL;
|
|
@@ -754,6 +658,10 @@ var TypeUtil = class {
|
|
|
754
658
|
* 检查 value 是否为可迭代对象 (Iterable)
|
|
755
659
|
* @param value 待检查值
|
|
756
660
|
* @returns 是否为 Iterable
|
|
661
|
+
* @example
|
|
662
|
+
* ```ts
|
|
663
|
+
* TypeUtil.isIterable([1, 2]); // true
|
|
664
|
+
* ```
|
|
757
665
|
*/
|
|
758
666
|
static isIterable(value) {
|
|
759
667
|
return !!value && typeof value[Symbol.iterator] === "function";
|
|
@@ -762,11 +670,27 @@ var TypeUtil = class {
|
|
|
762
670
|
* 检查 value 是否为 Falsy 值 (false, 0, "", null, undefined, NaN)
|
|
763
671
|
* @param value 待检查值
|
|
764
672
|
* @returns 是否为 Falsy
|
|
673
|
+
* @example
|
|
674
|
+
* ```ts
|
|
675
|
+
* TypeUtil.isFalsy(0); // true
|
|
676
|
+
* ```
|
|
765
677
|
*/
|
|
766
678
|
static isFalsy(value) {
|
|
767
679
|
if (this.isNaN(value) || this.isNull(value) || this.isUndefined(value)) return true;
|
|
768
680
|
return value === false || value === 0 || value === 0n || value === "";
|
|
769
681
|
}
|
|
682
|
+
/**
|
|
683
|
+
* 检查 value 是否为 FalsyLike 值
|
|
684
|
+
* - 包含字符串形式的 `"null"`、`"undefined"`、`"false"`、`"0"` 等
|
|
685
|
+
*
|
|
686
|
+
* @param value 待检查值
|
|
687
|
+
* @returns 是否为 FalsyLike
|
|
688
|
+
* @example
|
|
689
|
+
* ```ts
|
|
690
|
+
* TypeUtil.isFalsyLike("false"); // true
|
|
691
|
+
* TypeUtil.isFalsyLike("hello"); // false
|
|
692
|
+
* ```
|
|
693
|
+
*/
|
|
770
694
|
static isFalsyLike(value) {
|
|
771
695
|
if (this.isFalsy(value)) return true;
|
|
772
696
|
return typeof value === "string" && (value === "null" || value === "undefined" || value === "NaN" || value === "false" || value === "0" || value === "-0" || value === "0n");
|
|
@@ -820,6 +744,13 @@ _defineProperty(TypeUtil, "TYPED_ARRAY_TAGS", new Set([
|
|
|
820
744
|
* 字符串工具类
|
|
821
745
|
*/
|
|
822
746
|
var StringUtil = class {
|
|
747
|
+
static cast(candidate, checkEmpty = true) {
|
|
748
|
+
if (checkEmpty) {
|
|
749
|
+
if (candidate === null || candidate === void 0) return "";
|
|
750
|
+
if (typeof candidate === "string" && candidate.trim().length === 0) return "";
|
|
751
|
+
}
|
|
752
|
+
return String(candidate);
|
|
753
|
+
}
|
|
823
754
|
/**
|
|
824
755
|
* 从字符串中提取数字字符串
|
|
825
756
|
* - 移除非数字字符,保留符号和小数点
|
|
@@ -1337,17 +1268,50 @@ _defineProperty(DateTimeUtil, "FORMAT", {
|
|
|
1337
1268
|
* 环境检查工具类
|
|
1338
1269
|
*/
|
|
1339
1270
|
var EnvUtil = class {
|
|
1271
|
+
/**
|
|
1272
|
+
* 检测是否处于浏览器环境
|
|
1273
|
+
*
|
|
1274
|
+
* @returns 是否为浏览器环境
|
|
1275
|
+
* @example
|
|
1276
|
+
* ```ts
|
|
1277
|
+
* EnvUtil.isBrowser(); // true: 浏览器, false: Node.js
|
|
1278
|
+
* ```
|
|
1279
|
+
*/
|
|
1340
1280
|
static isBrowser() {
|
|
1341
1281
|
return this._isBrowser;
|
|
1342
1282
|
}
|
|
1283
|
+
/**
|
|
1284
|
+
* 检测是否处于 Web Worker 环境
|
|
1285
|
+
*
|
|
1286
|
+
* @returns 是否为 Web Worker 环境
|
|
1287
|
+
* @example
|
|
1288
|
+
* ```ts
|
|
1289
|
+
* EnvUtil.isWebWorker(); // true: Worker, false: 主线程/Node.js
|
|
1290
|
+
* ```
|
|
1291
|
+
*/
|
|
1343
1292
|
static isWebWorker() {
|
|
1344
1293
|
return this._isWebWorker;
|
|
1345
1294
|
}
|
|
1295
|
+
/**
|
|
1296
|
+
* 检测是否处于 React Native 环境
|
|
1297
|
+
*
|
|
1298
|
+
* @returns 是否为 React Native 环境
|
|
1299
|
+
* @example
|
|
1300
|
+
* ```ts
|
|
1301
|
+
* EnvUtil.isReactNative(); // true: React Native, false: Web/Node.js
|
|
1302
|
+
* ```
|
|
1303
|
+
*/
|
|
1346
1304
|
static isReactNative() {
|
|
1347
1305
|
return this._isReactNative;
|
|
1348
1306
|
}
|
|
1349
1307
|
/**
|
|
1350
1308
|
* 检查是否在 iframe 环境中
|
|
1309
|
+
*
|
|
1310
|
+
* @returns 是否在 iframe 中
|
|
1311
|
+
* @example
|
|
1312
|
+
* ```ts
|
|
1313
|
+
* EnvUtil.isIframe(); // true: 当前页面在 iframe 中
|
|
1314
|
+
* ```
|
|
1351
1315
|
*/
|
|
1352
1316
|
static isIframe() {
|
|
1353
1317
|
if (typeof window === "undefined") return false;
|
|
@@ -1516,8 +1480,38 @@ _defineProperty(MimeUtil, "MIME", {
|
|
|
1516
1480
|
XML: "text/xml",
|
|
1517
1481
|
/** XHTML 文档(XML 严格格式的 HTML) */
|
|
1518
1482
|
XHTML: "application/xhtml+xml",
|
|
1519
|
-
/** JavaScript
|
|
1483
|
+
/** JavaScript 文件 */
|
|
1520
1484
|
JS: "text/javascript",
|
|
1485
|
+
/** TypeScript 文件 */
|
|
1486
|
+
TS: "text/typescript",
|
|
1487
|
+
/** Python 文件 */
|
|
1488
|
+
PY: "text/x-python",
|
|
1489
|
+
/** Shell 脚本 (.sh) */
|
|
1490
|
+
SH: "text/x-sh",
|
|
1491
|
+
/** C 语言源文件 */
|
|
1492
|
+
C: "text/x-c",
|
|
1493
|
+
/** C++ 源文件 */
|
|
1494
|
+
CPP: "text/x-c++",
|
|
1495
|
+
/** C# 源文件 */
|
|
1496
|
+
CSHARP: "text/x-csharp",
|
|
1497
|
+
/** Java 源文件 */
|
|
1498
|
+
JAVA: "text/x-java",
|
|
1499
|
+
/** Go 源文件 */
|
|
1500
|
+
GO: "text/x-go",
|
|
1501
|
+
/** Rust 源文件 */
|
|
1502
|
+
RUST: "text/x-rust",
|
|
1503
|
+
/** PHP 文件 */
|
|
1504
|
+
PHP: "text/x-php",
|
|
1505
|
+
/** Ruby 文件 */
|
|
1506
|
+
RUBY: "text/x-ruby",
|
|
1507
|
+
/** Swift 源文件 */
|
|
1508
|
+
SWIFT: "text/x-swift",
|
|
1509
|
+
/** YAML 文档 */
|
|
1510
|
+
YAML: "text/vnd.yaml",
|
|
1511
|
+
/** TOML 文档 */
|
|
1512
|
+
TOML: "text/x-toml",
|
|
1513
|
+
/** SQL 脚本 */
|
|
1514
|
+
SQL: "text/x-sql",
|
|
1521
1515
|
/** Markdown 格式文档 */
|
|
1522
1516
|
MARKDOWN: "text/markdown",
|
|
1523
1517
|
/** 富文本格式文档(.rtf) */
|
|
@@ -1542,6 +1536,12 @@ _defineProperty(MimeUtil, "MIME", {
|
|
|
1542
1536
|
ICO: "image/vnd.microsoft.icon",
|
|
1543
1537
|
/** WebP 图像(高效压缩) */
|
|
1544
1538
|
WEBP: "image/webp",
|
|
1539
|
+
/** TIFF 图像(.tif/.tiff) */
|
|
1540
|
+
TIFF: "image/tiff",
|
|
1541
|
+
/** HEIC 图像(高效编码) */
|
|
1542
|
+
HEIC: "image/heic",
|
|
1543
|
+
/** Adobe Photoshop 文件(.psd) */
|
|
1544
|
+
PSD: "image/vnd.adobe.photoshop",
|
|
1545
1545
|
/** MP3 音频(.mp3) */
|
|
1546
1546
|
MP3: "audio/mpeg",
|
|
1547
1547
|
/** AAC 音频(.aac) */
|
|
@@ -1610,6 +1610,8 @@ _defineProperty(MimeUtil, "MIME", {
|
|
|
1610
1610
|
BZIP2: "application/x-bzip2",
|
|
1611
1611
|
/** 7-Zip 压缩文件(.7z) */
|
|
1612
1612
|
SEVEN_Z: "application/x-7z-compressed",
|
|
1613
|
+
/** RAR 压缩文件(.rar) */
|
|
1614
|
+
RAR: "application/vnd.rar",
|
|
1613
1615
|
/** 通用二进制数据(默认类型) */
|
|
1614
1616
|
OCTET_STREAM: "application/octet-stream",
|
|
1615
1617
|
/** JSON 数据格式(.json) */
|
|
@@ -1618,10 +1620,18 @@ _defineProperty(MimeUtil, "MIME", {
|
|
|
1618
1620
|
LD_JSON: "application/ld+json",
|
|
1619
1621
|
/** Java 归档文件(.jar) */
|
|
1620
1622
|
JAR: "application/java-archive",
|
|
1623
|
+
/** WebAssembly 二进制指令格式(.wasm) */
|
|
1624
|
+
WASM: "application/wasm",
|
|
1621
1625
|
/** MS 嵌入式 OpenType 字体(.eot) */
|
|
1622
1626
|
EOT: "application/vnd.ms-fontobject",
|
|
1623
1627
|
/** OpenType 字体(.otf) */
|
|
1624
1628
|
OTF: "font/otf",
|
|
1629
|
+
/** WOFF 字体(.woff) */
|
|
1630
|
+
WOFF: "font/woff",
|
|
1631
|
+
/** WOFF2 字体(.woff2) */
|
|
1632
|
+
WOFF2: "font/woff2",
|
|
1633
|
+
/** TrueType 字体(.ttf) */
|
|
1634
|
+
TTF: "font/ttf",
|
|
1625
1635
|
/** Excel 97-2003 工作簿(.xls) */
|
|
1626
1636
|
XLS: "application/vnd.ms-excel",
|
|
1627
1637
|
/** Microsoft XPS 文档(.xps) */
|
|
@@ -1652,7 +1662,10 @@ var ObjectUtil = class {
|
|
|
1652
1662
|
* @example
|
|
1653
1663
|
* ```ts
|
|
1654
1664
|
* const obj = { a: 1, b: 2 };
|
|
1665
|
+
*
|
|
1655
1666
|
* ObjectUtil.entriesMap(obj, (k, v) => [k, v * 2]); // { a: 2, b: 4 }
|
|
1667
|
+
*
|
|
1668
|
+
* ObjectUtil.entriesMap(obj, (k, v) => [`prefix_${String(k)}`, `${v}x`]); // { prefix_a: "1x", prefix_b: "2x" }
|
|
1656
1669
|
* ```
|
|
1657
1670
|
*/
|
|
1658
1671
|
static entriesMap(plainObject, toEntry) {
|
|
@@ -1739,192 +1752,320 @@ _defineProperty(ThemeUtil, "THEME_MODE", {
|
|
|
1739
1752
|
var ValidateUtil = class {
|
|
1740
1753
|
/**
|
|
1741
1754
|
* 验证是否为手机号码
|
|
1755
|
+
* @example
|
|
1756
|
+
* ```ts
|
|
1757
|
+
* ValidateUtil.isPhone("13800138000"); // true
|
|
1758
|
+
* ```
|
|
1742
1759
|
*/
|
|
1743
1760
|
static isPhone(input) {
|
|
1744
1761
|
return this._phone.test(input.toString());
|
|
1745
1762
|
}
|
|
1746
1763
|
/**
|
|
1747
1764
|
* 验证是否为固定电话
|
|
1765
|
+
* @example
|
|
1766
|
+
* ```ts
|
|
1767
|
+
* ValidateUtil.isTelephone("010-12345678"); // true
|
|
1768
|
+
* ```
|
|
1748
1769
|
*/
|
|
1749
1770
|
static isTelephone(input) {
|
|
1750
1771
|
return this._telephone.test(input.toString());
|
|
1751
1772
|
}
|
|
1752
1773
|
/**
|
|
1753
1774
|
* 验证是否为移动设备识别码
|
|
1775
|
+
* @example
|
|
1776
|
+
* ```ts
|
|
1777
|
+
* ValidateUtil.isIMEI("490154203237518"); // true
|
|
1778
|
+
* ```
|
|
1754
1779
|
*/
|
|
1755
1780
|
static isIMEI(input) {
|
|
1756
1781
|
return this._IMEI.test(input.toString());
|
|
1757
1782
|
}
|
|
1758
1783
|
/**
|
|
1759
1784
|
* 验证是否为电子邮箱
|
|
1785
|
+
* @example
|
|
1786
|
+
* ```ts
|
|
1787
|
+
* ValidateUtil.isEmail("dev@example.com"); // true
|
|
1788
|
+
* ```
|
|
1760
1789
|
*/
|
|
1761
1790
|
static isEmail(input) {
|
|
1762
1791
|
return this._email.test(input.toString());
|
|
1763
1792
|
}
|
|
1764
1793
|
/**
|
|
1765
1794
|
* 验证是否为 http(s) 链接
|
|
1795
|
+
* @example
|
|
1796
|
+
* ```ts
|
|
1797
|
+
* ValidateUtil.isHttpLink("https://example.com/path"); // true
|
|
1798
|
+
* ```
|
|
1766
1799
|
*/
|
|
1767
1800
|
static isHttpLink(input) {
|
|
1768
1801
|
return this._link.test(input.toString());
|
|
1769
1802
|
}
|
|
1770
1803
|
/**
|
|
1771
1804
|
* 验证是否为端口号链接
|
|
1805
|
+
* @example
|
|
1806
|
+
* ```ts
|
|
1807
|
+
* ValidateUtil.isPortLink("http://example.com:8080"); // true
|
|
1808
|
+
* ```
|
|
1772
1809
|
*/
|
|
1773
1810
|
static isPortLink(input) {
|
|
1774
1811
|
return this._portLink.test(input.toString());
|
|
1775
1812
|
}
|
|
1776
1813
|
/**
|
|
1777
1814
|
* 验证是否为迅雷链接
|
|
1815
|
+
* @example
|
|
1816
|
+
* ```ts
|
|
1817
|
+
* ValidateUtil.isThunderLink("thunder://QUFodHRwOi8vZXhhbXBsZS5jb20vZmlsZQ=="); // true
|
|
1818
|
+
* ```
|
|
1778
1819
|
*/
|
|
1779
1820
|
static isThunderLink(input) {
|
|
1780
1821
|
return this._thunderLink.test(input.toString());
|
|
1781
1822
|
}
|
|
1782
1823
|
/**
|
|
1783
1824
|
* 验证是否为统一社会信用代码
|
|
1825
|
+
* @example
|
|
1826
|
+
* ```ts
|
|
1827
|
+
* ValidateUtil.isUSCC("91350100M000100Y43"); // true
|
|
1828
|
+
* ```
|
|
1784
1829
|
*/
|
|
1785
1830
|
static isUSCC(input) {
|
|
1786
1831
|
return this._uscc.test(input.toString());
|
|
1787
1832
|
}
|
|
1788
1833
|
/**
|
|
1789
1834
|
* 验证是否为统一社会信用代码 - 15位/18位/20位数字/字母
|
|
1835
|
+
* @example
|
|
1836
|
+
* ```ts
|
|
1837
|
+
* ValidateUtil.isUSCCS("91350100M000100Y43"); // true
|
|
1838
|
+
* ```
|
|
1790
1839
|
*/
|
|
1791
1840
|
static isUSCCS(input) {
|
|
1792
1841
|
return this._usccs.test(input.toString());
|
|
1793
1842
|
}
|
|
1794
1843
|
/**
|
|
1795
1844
|
* 验证是否为 Windows 系统文件夹路径
|
|
1845
|
+
* @example
|
|
1846
|
+
* ```ts
|
|
1847
|
+
* ValidateUtil.isDirPathWindows("C:\\Users\\pawover\\"); // true
|
|
1848
|
+
* ```
|
|
1796
1849
|
*/
|
|
1797
1850
|
static isDirPathWindows(input) {
|
|
1798
1851
|
return this._dirPathWindows.test(input.toString());
|
|
1799
1852
|
}
|
|
1800
1853
|
/**
|
|
1801
1854
|
* 验证是否为 Windows 系统文件路径
|
|
1855
|
+
* @example
|
|
1856
|
+
* ```ts
|
|
1857
|
+
* ValidateUtil.isFilePathWindows("C:\\Users\\pawover\\a.txt"); // true
|
|
1858
|
+
* ```
|
|
1802
1859
|
*/
|
|
1803
1860
|
static isFilePathWindows(input) {
|
|
1804
1861
|
return this._filePathWindows.test(input.toString());
|
|
1805
1862
|
}
|
|
1806
1863
|
/**
|
|
1807
1864
|
* 验证是否为 Linux 系统文件夹路径
|
|
1865
|
+
* @example
|
|
1866
|
+
* ```ts
|
|
1867
|
+
* ValidateUtil.isDirPathLinux("/usr/local/"); // true
|
|
1868
|
+
* ```
|
|
1808
1869
|
*/
|
|
1809
1870
|
static isDirPathLinux(input) {
|
|
1810
1871
|
return this._dirPathLinux.test(input.toString());
|
|
1811
1872
|
}
|
|
1812
1873
|
/**
|
|
1813
1874
|
* 验证是否为 Linux 系统文件路径
|
|
1875
|
+
* @example
|
|
1876
|
+
* ```ts
|
|
1877
|
+
* ValidateUtil.isFilePathLinux("/usr/local/bin/node"); // true
|
|
1878
|
+
* ```
|
|
1814
1879
|
*/
|
|
1815
1880
|
static isFilePathLinux(input) {
|
|
1816
1881
|
return this._filePathLinux.test(input.toString());
|
|
1817
1882
|
}
|
|
1818
1883
|
/**
|
|
1819
1884
|
* 验证是否为新能源车牌号
|
|
1885
|
+
* @example
|
|
1886
|
+
* ```ts
|
|
1887
|
+
* ValidateUtil.isEVCarNumber("粤AD12345"); // true
|
|
1888
|
+
* ```
|
|
1820
1889
|
*/
|
|
1821
1890
|
static isEVCarNumber(input) {
|
|
1822
1891
|
return this._EVCarNumber.test(input.toString());
|
|
1823
1892
|
}
|
|
1824
1893
|
/**
|
|
1825
1894
|
* 验证是否为燃油车车牌号
|
|
1895
|
+
* @example
|
|
1896
|
+
* ```ts
|
|
1897
|
+
* ValidateUtil.isGVCarNumber("粤B12345"); // true
|
|
1898
|
+
* ```
|
|
1826
1899
|
*/
|
|
1827
1900
|
static isGVCarNumber(input) {
|
|
1828
1901
|
return this._GVCarNumber.test(input.toString());
|
|
1829
1902
|
}
|
|
1830
1903
|
/**
|
|
1831
1904
|
* 验证是否为中文姓名
|
|
1905
|
+
* @example
|
|
1906
|
+
* ```ts
|
|
1907
|
+
* ValidateUtil.isChineseName("张三"); // true
|
|
1908
|
+
* ```
|
|
1832
1909
|
*/
|
|
1833
1910
|
static isChineseName(input) {
|
|
1834
1911
|
return this._chineseName.test(input.toString());
|
|
1835
1912
|
}
|
|
1836
1913
|
/**
|
|
1837
1914
|
* 验证是否为中国身份证号
|
|
1915
|
+
* @example
|
|
1916
|
+
* ```ts
|
|
1917
|
+
* ValidateUtil.isChineseID("11010519491231002X"); // true
|
|
1918
|
+
* ```
|
|
1838
1919
|
*/
|
|
1839
1920
|
static isChineseID(input) {
|
|
1840
1921
|
return this._chineseId.test(input.toString());
|
|
1841
1922
|
}
|
|
1842
1923
|
/**
|
|
1843
1924
|
* 验证是否为中国省份
|
|
1925
|
+
* @example
|
|
1926
|
+
* ```ts
|
|
1927
|
+
* ValidateUtil.isChineseProvince("浙江"); // true
|
|
1928
|
+
* ```
|
|
1844
1929
|
*/
|
|
1845
1930
|
static isChineseProvince(input) {
|
|
1846
1931
|
return this._chineseProvince.test(input.toString());
|
|
1847
1932
|
}
|
|
1848
1933
|
/**
|
|
1849
1934
|
* 验证是否为中华民族
|
|
1935
|
+
* @example
|
|
1936
|
+
* ```ts
|
|
1937
|
+
* ValidateUtil.isChineseNation("汉族"); // true
|
|
1938
|
+
* ```
|
|
1850
1939
|
*/
|
|
1851
1940
|
static isChineseNation(input) {
|
|
1852
1941
|
return this._chineseNation.test(input.toString());
|
|
1853
1942
|
}
|
|
1854
1943
|
/**
|
|
1855
1944
|
* 验证是否只包含字母
|
|
1945
|
+
* @example
|
|
1946
|
+
* ```ts
|
|
1947
|
+
* ValidateUtil.isLetter("abcDEF"); // true
|
|
1948
|
+
* ```
|
|
1856
1949
|
*/
|
|
1857
1950
|
static isLetter(input) {
|
|
1858
1951
|
return this._letter.test(input.toString());
|
|
1859
1952
|
}
|
|
1860
1953
|
/**
|
|
1861
1954
|
* 验证是否只包含小写字母
|
|
1955
|
+
* @example
|
|
1956
|
+
* ```ts
|
|
1957
|
+
* ValidateUtil.isLetterLowercase("abc"); // true
|
|
1958
|
+
* ```
|
|
1862
1959
|
*/
|
|
1863
1960
|
static isLetterLowercase(input) {
|
|
1864
1961
|
return this._letterLowercase.test(input.toString());
|
|
1865
1962
|
}
|
|
1866
1963
|
/**
|
|
1867
1964
|
* 验证是否只包含大写字母
|
|
1965
|
+
* @example
|
|
1966
|
+
* ```ts
|
|
1967
|
+
* ValidateUtil.isLetterUppercase("ABC"); // true
|
|
1968
|
+
* ```
|
|
1868
1969
|
*/
|
|
1869
1970
|
static isLetterUppercase(input) {
|
|
1870
1971
|
return this._letterUppercase.test(input.toString());
|
|
1871
1972
|
}
|
|
1872
1973
|
/**
|
|
1873
1974
|
* 验证是否不包含字母
|
|
1975
|
+
* @example
|
|
1976
|
+
* ```ts
|
|
1977
|
+
* ValidateUtil.isLetterOmit("123_-"); // true
|
|
1978
|
+
* ```
|
|
1874
1979
|
*/
|
|
1875
1980
|
static isLetterOmit(input) {
|
|
1876
1981
|
return this._letterOmit.test(input.toString());
|
|
1877
1982
|
}
|
|
1878
1983
|
/**
|
|
1879
1984
|
* 验证是否为数字和字母组合
|
|
1985
|
+
* @example
|
|
1986
|
+
* ```ts
|
|
1987
|
+
* ValidateUtil.isLetterAndNumber("A1B2"); // true
|
|
1988
|
+
* ```
|
|
1880
1989
|
*/
|
|
1881
1990
|
static isLetterAndNumber(input) {
|
|
1882
1991
|
return this._LetterAndNumber.test(input.toString());
|
|
1883
1992
|
}
|
|
1884
1993
|
/**
|
|
1885
1994
|
* 验证是否为有符号浮点数
|
|
1995
|
+
* @example
|
|
1996
|
+
* ```ts
|
|
1997
|
+
* ValidateUtil.isSignedFloat("-12.34"); // true
|
|
1998
|
+
* ```
|
|
1886
1999
|
*/
|
|
1887
2000
|
static isSignedFloat(input) {
|
|
1888
2001
|
return this._signedFloat.test(input.toString());
|
|
1889
2002
|
}
|
|
1890
2003
|
/**
|
|
1891
2004
|
* 验证是否为无符号浮点数
|
|
2005
|
+
* @example
|
|
2006
|
+
* ```ts
|
|
2007
|
+
* ValidateUtil.isUnsignedFloat("12.34"); // true
|
|
2008
|
+
* ```
|
|
1892
2009
|
*/
|
|
1893
2010
|
static isUnsignedFloat(input) {
|
|
1894
2011
|
return this._unsignedFloat.test(input.toString());
|
|
1895
2012
|
}
|
|
1896
2013
|
/**
|
|
1897
2014
|
* 验证是否为有符号整数
|
|
2015
|
+
* @example
|
|
2016
|
+
* ```ts
|
|
2017
|
+
* ValidateUtil.isSignedInteger("-12"); // true
|
|
2018
|
+
* ```
|
|
1898
2019
|
*/
|
|
1899
2020
|
static isSignedInteger(input) {
|
|
1900
2021
|
return this._signedInteger.test(input.toString());
|
|
1901
2022
|
}
|
|
1902
2023
|
/**
|
|
1903
2024
|
* 验证是否为无符号整数
|
|
2025
|
+
* @example
|
|
2026
|
+
* ```ts
|
|
2027
|
+
* ValidateUtil.isUnsignedInteger("12"); // true
|
|
2028
|
+
* ```
|
|
1904
2029
|
*/
|
|
1905
2030
|
static isUnsignedInteger(input) {
|
|
1906
2031
|
return this._unsignedInteger.test(input.toString());
|
|
1907
2032
|
}
|
|
1908
2033
|
/**
|
|
1909
2034
|
* 验证是否包含空格
|
|
2035
|
+
* @example
|
|
2036
|
+
* ```ts
|
|
2037
|
+
* ValidateUtil.isSpaceInclude("a b"); // true
|
|
2038
|
+
* ```
|
|
1910
2039
|
*/
|
|
1911
2040
|
static isSpaceInclude(input) {
|
|
1912
2041
|
return this._spaceInclude.test(input.toString());
|
|
1913
2042
|
}
|
|
1914
2043
|
/**
|
|
1915
2044
|
* 验证是否以空格开头
|
|
2045
|
+
* @example
|
|
2046
|
+
* ```ts
|
|
2047
|
+
* ValidateUtil.isSpaceStart(" abc"); // true
|
|
2048
|
+
* ```
|
|
1916
2049
|
*/
|
|
1917
2050
|
static isSpaceStart(input) {
|
|
1918
2051
|
return this._spaceStart.test(input.toString());
|
|
1919
2052
|
}
|
|
1920
2053
|
/**
|
|
1921
2054
|
* 验证是否以空格结尾
|
|
2055
|
+
* @example
|
|
2056
|
+
* ```ts
|
|
2057
|
+
* ValidateUtil.isSpaceEnd("abc "); // true
|
|
2058
|
+
* ```
|
|
1922
2059
|
*/
|
|
1923
2060
|
static isSpaceEnd(input) {
|
|
1924
2061
|
return this._spaceEnd.test(input.toString());
|
|
1925
2062
|
}
|
|
1926
2063
|
/**
|
|
1927
2064
|
* 验证是否以空格开头或结尾
|
|
2065
|
+
* @example
|
|
2066
|
+
* ```ts
|
|
2067
|
+
* ValidateUtil.isSpaceStartOrEnd(" abc"); // true
|
|
2068
|
+
* ```
|
|
1928
2069
|
*/
|
|
1929
2070
|
static isSpaceStartOrEnd(input) {
|
|
1930
2071
|
return this.isSpaceStart(input) || this.isSpaceEnd(input);
|
|
@@ -1996,6 +2137,441 @@ function useMount(effect) {
|
|
|
1996
2137
|
}, [effectRef]);
|
|
1997
2138
|
}
|
|
1998
2139
|
//#endregion
|
|
2140
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/_internal/globalThis.mjs
|
|
2141
|
+
const globalThis_ = typeof globalThis === "object" && globalThis || typeof window === "object" && window || typeof self === "object" && self || typeof global === "object" && global || (function() {
|
|
2142
|
+
return this;
|
|
2143
|
+
})() || Function("return this")();
|
|
2144
|
+
//#endregion
|
|
2145
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/function/noop.mjs
|
|
2146
|
+
/**
|
|
2147
|
+
* A no-operation function that does nothing.
|
|
2148
|
+
* This can be used as a placeholder or default function.
|
|
2149
|
+
*
|
|
2150
|
+
* @example
|
|
2151
|
+
* noop(); // Does nothing
|
|
2152
|
+
*
|
|
2153
|
+
* @returns {void} This function does not return anything.
|
|
2154
|
+
*/
|
|
2155
|
+
function noop() {}
|
|
2156
|
+
//#endregion
|
|
2157
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/predicate/isPrimitive.mjs
|
|
2158
|
+
/**
|
|
2159
|
+
* Checks whether a value is a JavaScript primitive.
|
|
2160
|
+
* JavaScript primitives include null, undefined, strings, numbers, booleans, symbols, and bigints.
|
|
2161
|
+
*
|
|
2162
|
+
* @param {unknown} value The value to check.
|
|
2163
|
+
* @returns {value is
|
|
2164
|
+
* null
|
|
2165
|
+
* | undefined
|
|
2166
|
+
* | string
|
|
2167
|
+
* | number
|
|
2168
|
+
* | boolean
|
|
2169
|
+
* | symbol
|
|
2170
|
+
* | bigint} Returns true if `value` is a primitive, false otherwise.
|
|
2171
|
+
*
|
|
2172
|
+
* @example
|
|
2173
|
+
* isPrimitive(null); // true
|
|
2174
|
+
* isPrimitive(undefined); // true
|
|
2175
|
+
* isPrimitive('123'); // true
|
|
2176
|
+
* isPrimitive(false); // true
|
|
2177
|
+
* isPrimitive(true); // true
|
|
2178
|
+
* isPrimitive(Symbol('a')); // true
|
|
2179
|
+
* isPrimitive(123n); // true
|
|
2180
|
+
* isPrimitive({}); // false
|
|
2181
|
+
* isPrimitive(new Date()); // false
|
|
2182
|
+
* isPrimitive(new Map()); // false
|
|
2183
|
+
* isPrimitive(new Set()); // false
|
|
2184
|
+
* isPrimitive([1, 2, 3]); // false
|
|
2185
|
+
*/
|
|
2186
|
+
function isPrimitive(value) {
|
|
2187
|
+
return value == null || typeof value !== "object" && typeof value !== "function";
|
|
2188
|
+
}
|
|
2189
|
+
//#endregion
|
|
2190
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/predicate/isTypedArray.mjs
|
|
2191
|
+
/**
|
|
2192
|
+
* Checks if a value is a TypedArray.
|
|
2193
|
+
* @param {unknown} x The value to check.
|
|
2194
|
+
* @returns {x is
|
|
2195
|
+
* Uint8Array
|
|
2196
|
+
* | Uint8ClampedArray
|
|
2197
|
+
* | Uint16Array
|
|
2198
|
+
* | Uint32Array
|
|
2199
|
+
* | BigUint64Array
|
|
2200
|
+
* | Int8Array
|
|
2201
|
+
* | Int16Array
|
|
2202
|
+
* | Int32Array
|
|
2203
|
+
* | BigInt64Array
|
|
2204
|
+
* | Float32Array
|
|
2205
|
+
* | Float64Array} Returns true if `x` is a TypedArray, false otherwise.
|
|
2206
|
+
*
|
|
2207
|
+
* @example
|
|
2208
|
+
* const arr = new Uint8Array([1, 2, 3]);
|
|
2209
|
+
* isTypedArray(arr); // true
|
|
2210
|
+
*
|
|
2211
|
+
* const regularArray = [1, 2, 3];
|
|
2212
|
+
* isTypedArray(regularArray); // false
|
|
2213
|
+
*
|
|
2214
|
+
* const buffer = new ArrayBuffer(16);
|
|
2215
|
+
* isTypedArray(buffer); // false
|
|
2216
|
+
*/
|
|
2217
|
+
function isTypedArray(x) {
|
|
2218
|
+
return ArrayBuffer.isView(x) && !(x instanceof DataView);
|
|
2219
|
+
}
|
|
2220
|
+
//#endregion
|
|
2221
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/object/clone.mjs
|
|
2222
|
+
/**
|
|
2223
|
+
* Creates a shallow clone of the given object.
|
|
2224
|
+
*
|
|
2225
|
+
* @template T - The type of the object.
|
|
2226
|
+
* @param {T} obj - The object to clone.
|
|
2227
|
+
* @returns {T} - A shallow clone of the given object.
|
|
2228
|
+
*
|
|
2229
|
+
* @example
|
|
2230
|
+
* // Clone a primitive values
|
|
2231
|
+
* const num = 29;
|
|
2232
|
+
* const clonedNum = clone(num);
|
|
2233
|
+
* console.log(clonedNum); // 29
|
|
2234
|
+
* console.log(clonedNum === num); // true
|
|
2235
|
+
*
|
|
2236
|
+
* @example
|
|
2237
|
+
* // Clone an array
|
|
2238
|
+
* const arr = [1, 2, 3];
|
|
2239
|
+
* const clonedArr = clone(arr);
|
|
2240
|
+
* console.log(clonedArr); // [1, 2, 3]
|
|
2241
|
+
* console.log(clonedArr === arr); // false
|
|
2242
|
+
*
|
|
2243
|
+
* @example
|
|
2244
|
+
* // Clone an object
|
|
2245
|
+
* const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };
|
|
2246
|
+
* const clonedObj = clone(obj);
|
|
2247
|
+
* console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }
|
|
2248
|
+
* console.log(clonedObj === obj); // false
|
|
2249
|
+
*/
|
|
2250
|
+
function clone(obj) {
|
|
2251
|
+
if (isPrimitive(obj)) return obj;
|
|
2252
|
+
if (Array.isArray(obj) || isTypedArray(obj) || obj instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && obj instanceof SharedArrayBuffer) return obj.slice(0);
|
|
2253
|
+
const prototype = Object.getPrototypeOf(obj);
|
|
2254
|
+
if (prototype == null) return Object.assign(Object.create(prototype), obj);
|
|
2255
|
+
const Constructor = prototype.constructor;
|
|
2256
|
+
if (obj instanceof Date || obj instanceof Map || obj instanceof Set) return new Constructor(obj);
|
|
2257
|
+
if (obj instanceof RegExp) {
|
|
2258
|
+
const newRegExp = new Constructor(obj);
|
|
2259
|
+
newRegExp.lastIndex = obj.lastIndex;
|
|
2260
|
+
return newRegExp;
|
|
2261
|
+
}
|
|
2262
|
+
if (obj instanceof DataView) return new Constructor(obj.buffer.slice(0));
|
|
2263
|
+
if (obj instanceof Error) {
|
|
2264
|
+
let newError;
|
|
2265
|
+
if (obj instanceof AggregateError) newError = new Constructor(obj.errors, obj.message, { cause: obj.cause });
|
|
2266
|
+
else newError = new Constructor(obj.message, { cause: obj.cause });
|
|
2267
|
+
newError.stack = obj.stack;
|
|
2268
|
+
Object.assign(newError, obj);
|
|
2269
|
+
return newError;
|
|
2270
|
+
}
|
|
2271
|
+
if (typeof File !== "undefined" && obj instanceof File) return new Constructor([obj], obj.name, {
|
|
2272
|
+
type: obj.type,
|
|
2273
|
+
lastModified: obj.lastModified
|
|
2274
|
+
});
|
|
2275
|
+
if (typeof obj === "object") return Object.assign(Object.create(prototype), obj);
|
|
2276
|
+
return obj;
|
|
2277
|
+
}
|
|
2278
|
+
//#endregion
|
|
2279
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/predicate/isBuffer.mjs
|
|
2280
|
+
/**
|
|
2281
|
+
* Checks if the given value is a Buffer instance.
|
|
2282
|
+
*
|
|
2283
|
+
* This function tests whether the provided value is an instance of Buffer.
|
|
2284
|
+
* It returns `true` if the value is a Buffer, and `false` otherwise.
|
|
2285
|
+
*
|
|
2286
|
+
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Buffer`.
|
|
2287
|
+
*
|
|
2288
|
+
* @param {unknown} x - The value to check if it is a Buffer.
|
|
2289
|
+
* @returns {boolean} Returns `true` if `x` is a Buffer, else `false`.
|
|
2290
|
+
*
|
|
2291
|
+
* @example
|
|
2292
|
+
* const buffer = Buffer.from("test");
|
|
2293
|
+
* console.log(isBuffer(buffer)); // true
|
|
2294
|
+
*
|
|
2295
|
+
* const notBuffer = "not a buffer";
|
|
2296
|
+
* console.log(isBuffer(notBuffer)); // false
|
|
2297
|
+
*/
|
|
2298
|
+
function isBuffer(x) {
|
|
2299
|
+
return typeof globalThis_.Buffer !== "undefined" && globalThis_.Buffer.isBuffer(x);
|
|
2300
|
+
}
|
|
2301
|
+
//#endregion
|
|
2302
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/_internal/getSymbols.mjs
|
|
2303
|
+
function getSymbols(object) {
|
|
2304
|
+
return Object.getOwnPropertySymbols(object).filter((symbol) => Object.prototype.propertyIsEnumerable.call(object, symbol));
|
|
2305
|
+
}
|
|
2306
|
+
//#endregion
|
|
2307
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/_internal/getTag.mjs
|
|
2308
|
+
/**
|
|
2309
|
+
* Gets the `toStringTag` of `value`.
|
|
2310
|
+
*
|
|
2311
|
+
* @private
|
|
2312
|
+
* @param {T} value The value to query.
|
|
2313
|
+
* @returns {string} Returns the `Object.prototype.toString.call` result.
|
|
2314
|
+
*/
|
|
2315
|
+
function getTag(value) {
|
|
2316
|
+
if (value == null) return value === void 0 ? "[object Undefined]" : "[object Null]";
|
|
2317
|
+
return Object.prototype.toString.call(value);
|
|
2318
|
+
}
|
|
2319
|
+
//#endregion
|
|
2320
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/compat/_internal/tags.mjs
|
|
2321
|
+
const regexpTag = "[object RegExp]";
|
|
2322
|
+
const stringTag = "[object String]";
|
|
2323
|
+
const numberTag = "[object Number]";
|
|
2324
|
+
const booleanTag = "[object Boolean]";
|
|
2325
|
+
const symbolTag = "[object Symbol]";
|
|
2326
|
+
const dateTag = "[object Date]";
|
|
2327
|
+
const mapTag = "[object Map]";
|
|
2328
|
+
const setTag = "[object Set]";
|
|
2329
|
+
const arrayTag = "[object Array]";
|
|
2330
|
+
const functionTag = "[object Function]";
|
|
2331
|
+
const arrayBufferTag = "[object ArrayBuffer]";
|
|
2332
|
+
const objectTag = "[object Object]";
|
|
2333
|
+
const errorTag = "[object Error]";
|
|
2334
|
+
const dataViewTag = "[object DataView]";
|
|
2335
|
+
const uint8ArrayTag = "[object Uint8Array]";
|
|
2336
|
+
const uint8ClampedArrayTag = "[object Uint8ClampedArray]";
|
|
2337
|
+
const uint16ArrayTag = "[object Uint16Array]";
|
|
2338
|
+
const uint32ArrayTag = "[object Uint32Array]";
|
|
2339
|
+
const bigUint64ArrayTag = "[object BigUint64Array]";
|
|
2340
|
+
const int8ArrayTag = "[object Int8Array]";
|
|
2341
|
+
const int16ArrayTag = "[object Int16Array]";
|
|
2342
|
+
const int32ArrayTag = "[object Int32Array]";
|
|
2343
|
+
const bigInt64ArrayTag = "[object BigInt64Array]";
|
|
2344
|
+
const float32ArrayTag = "[object Float32Array]";
|
|
2345
|
+
const float64ArrayTag = "[object Float64Array]";
|
|
2346
|
+
//#endregion
|
|
2347
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs
|
|
2348
|
+
/**
|
|
2349
|
+
* Checks if a given value is a plain object.
|
|
2350
|
+
*
|
|
2351
|
+
* @param {object} value - The value to check.
|
|
2352
|
+
* @returns {value is Record<PropertyKey, any>} - True if the value is a plain object, otherwise false.
|
|
2353
|
+
*
|
|
2354
|
+
* @example
|
|
2355
|
+
* ```typescript
|
|
2356
|
+
* // ✅👇 True
|
|
2357
|
+
*
|
|
2358
|
+
* isPlainObject({ }); // ✅
|
|
2359
|
+
* isPlainObject({ key: 'value' }); // ✅
|
|
2360
|
+
* isPlainObject({ key: new Date() }); // ✅
|
|
2361
|
+
* isPlainObject(new Object()); // ✅
|
|
2362
|
+
* isPlainObject(Object.create(null)); // ✅
|
|
2363
|
+
* isPlainObject({ nested: { key: true} }); // ✅
|
|
2364
|
+
* isPlainObject(new Proxy({}, {})); // ✅
|
|
2365
|
+
* isPlainObject({ [Symbol('tag')]: 'A' }); // ✅
|
|
2366
|
+
*
|
|
2367
|
+
* // ✅👇 (cross-realms, node context, workers, ...)
|
|
2368
|
+
* const runInNewContext = await import('node:vm').then(
|
|
2369
|
+
* (mod) => mod.runInNewContext
|
|
2370
|
+
* );
|
|
2371
|
+
* isPlainObject(runInNewContext('({})')); // ✅
|
|
2372
|
+
*
|
|
2373
|
+
* // ❌👇 False
|
|
2374
|
+
*
|
|
2375
|
+
* class Test { };
|
|
2376
|
+
* isPlainObject(new Test()) // ❌
|
|
2377
|
+
* isPlainObject(10); // ❌
|
|
2378
|
+
* isPlainObject(null); // ❌
|
|
2379
|
+
* isPlainObject('hello'); // ❌
|
|
2380
|
+
* isPlainObject([]); // ❌
|
|
2381
|
+
* isPlainObject(new Date()); // ❌
|
|
2382
|
+
* isPlainObject(new Uint8Array([1])); // ❌
|
|
2383
|
+
* isPlainObject(Buffer.from('ABC')); // ❌
|
|
2384
|
+
* isPlainObject(Promise.resolve({})); // ❌
|
|
2385
|
+
* isPlainObject(Object.create({})); // ❌
|
|
2386
|
+
* isPlainObject(new (class Cls {})); // ❌
|
|
2387
|
+
* isPlainObject(globalThis); // ❌,
|
|
2388
|
+
* ```
|
|
2389
|
+
*/
|
|
2390
|
+
function isPlainObject(value) {
|
|
2391
|
+
if (!value || typeof value !== "object") return false;
|
|
2392
|
+
const proto = Object.getPrototypeOf(value);
|
|
2393
|
+
if (!(proto === null || proto === Object.prototype || Object.getPrototypeOf(proto) === null)) return false;
|
|
2394
|
+
return Object.prototype.toString.call(value) === "[object Object]";
|
|
2395
|
+
}
|
|
2396
|
+
//#endregion
|
|
2397
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/_internal/isEqualsSameValueZero.mjs
|
|
2398
|
+
/**
|
|
2399
|
+
* Performs a `SameValueZero` comparison between two values to determine if they are equivalent.
|
|
2400
|
+
*
|
|
2401
|
+
* @param {any} value - The value to compare.
|
|
2402
|
+
* @param {any} other - The other value to compare.
|
|
2403
|
+
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
2404
|
+
*
|
|
2405
|
+
* @example
|
|
2406
|
+
* eq(1, 1); // true
|
|
2407
|
+
* eq(0, -0); // true
|
|
2408
|
+
* eq(NaN, NaN); // true
|
|
2409
|
+
* eq('a', Object('a')); // false
|
|
2410
|
+
*/
|
|
2411
|
+
function isEqualsSameValueZero(value, other) {
|
|
2412
|
+
return value === other || Number.isNaN(value) && Number.isNaN(other);
|
|
2413
|
+
}
|
|
2414
|
+
//#endregion
|
|
2415
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/predicate/isEqualWith.mjs
|
|
2416
|
+
/**
|
|
2417
|
+
* Compares two values for equality using a custom comparison function.
|
|
2418
|
+
*
|
|
2419
|
+
* The custom function allows for fine-tuned control over the comparison process. If it returns a boolean, that result determines the equality. If it returns undefined, the function falls back to the default equality comparison.
|
|
2420
|
+
*
|
|
2421
|
+
* This function also uses the custom equality function to compare values inside objects,
|
|
2422
|
+
* arrays, maps, sets, and other complex structures, ensuring a deep comparison.
|
|
2423
|
+
*
|
|
2424
|
+
* This approach provides flexibility in handling complex comparisons while maintaining efficient default behavior for simpler cases.
|
|
2425
|
+
*
|
|
2426
|
+
* The custom comparison function can take up to six parameters:
|
|
2427
|
+
* - `x`: The value from the first object `a`.
|
|
2428
|
+
* - `y`: The value from the second object `b`.
|
|
2429
|
+
* - `property`: The property key used to get `x` and `y`.
|
|
2430
|
+
* - `xParent`: The parent of the first value `x`.
|
|
2431
|
+
* - `yParent`: The parent of the second value `y`.
|
|
2432
|
+
* - `stack`: An internal stack (Map) to handle circular references.
|
|
2433
|
+
*
|
|
2434
|
+
* @param {unknown} a - The first value to compare.
|
|
2435
|
+
* @param {unknown} b - The second value to compare.
|
|
2436
|
+
* @param {(x: any, y: any, property?: PropertyKey, xParent?: any, yParent?: any, stack?: Map<any, any>) => boolean | void} areValuesEqual - A function to customize the comparison.
|
|
2437
|
+
* If it returns a boolean, that result will be used. If it returns undefined,
|
|
2438
|
+
* the default equality comparison will be used.
|
|
2439
|
+
* @returns {boolean} `true` if the values are equal according to the customizer, otherwise `false`.
|
|
2440
|
+
*
|
|
2441
|
+
* @example
|
|
2442
|
+
* const customizer = (a, b) => {
|
|
2443
|
+
* if (typeof a === 'string' && typeof b === 'string') {
|
|
2444
|
+
* return a.toLowerCase() === b.toLowerCase();
|
|
2445
|
+
* }
|
|
2446
|
+
* };
|
|
2447
|
+
* isEqualWith('Hello', 'hello', customizer); // true
|
|
2448
|
+
* isEqualWith({ a: 'Hello' }, { a: 'hello' }, customizer); // true
|
|
2449
|
+
* isEqualWith([1, 2, 3], [1, 2, 3], customizer); // true
|
|
2450
|
+
*/
|
|
2451
|
+
function isEqualWith(a, b, areValuesEqual) {
|
|
2452
|
+
return isEqualWithImpl(a, b, void 0, void 0, void 0, void 0, areValuesEqual);
|
|
2453
|
+
}
|
|
2454
|
+
function isEqualWithImpl(a, b, property, aParent, bParent, stack, areValuesEqual) {
|
|
2455
|
+
const result = areValuesEqual(a, b, property, aParent, bParent, stack);
|
|
2456
|
+
if (result !== void 0) return result;
|
|
2457
|
+
if (typeof a === typeof b) switch (typeof a) {
|
|
2458
|
+
case "bigint":
|
|
2459
|
+
case "string":
|
|
2460
|
+
case "boolean":
|
|
2461
|
+
case "symbol":
|
|
2462
|
+
case "undefined": return a === b;
|
|
2463
|
+
case "number": return a === b || Object.is(a, b);
|
|
2464
|
+
case "function": return a === b;
|
|
2465
|
+
case "object": return areObjectsEqual(a, b, stack, areValuesEqual);
|
|
2466
|
+
}
|
|
2467
|
+
return areObjectsEqual(a, b, stack, areValuesEqual);
|
|
2468
|
+
}
|
|
2469
|
+
function areObjectsEqual(a, b, stack, areValuesEqual) {
|
|
2470
|
+
if (Object.is(a, b)) return true;
|
|
2471
|
+
let aTag = getTag(a);
|
|
2472
|
+
let bTag = getTag(b);
|
|
2473
|
+
if (aTag === "[object Arguments]") aTag = objectTag;
|
|
2474
|
+
if (bTag === "[object Arguments]") bTag = objectTag;
|
|
2475
|
+
if (aTag !== bTag) return false;
|
|
2476
|
+
switch (aTag) {
|
|
2477
|
+
case stringTag: return a.toString() === b.toString();
|
|
2478
|
+
case numberTag: return isEqualsSameValueZero(a.valueOf(), b.valueOf());
|
|
2479
|
+
case booleanTag:
|
|
2480
|
+
case dateTag:
|
|
2481
|
+
case symbolTag: return Object.is(a.valueOf(), b.valueOf());
|
|
2482
|
+
case regexpTag: return a.source === b.source && a.flags === b.flags;
|
|
2483
|
+
case functionTag: return a === b;
|
|
2484
|
+
}
|
|
2485
|
+
stack = stack ?? /* @__PURE__ */ new Map();
|
|
2486
|
+
const aStack = stack.get(a);
|
|
2487
|
+
const bStack = stack.get(b);
|
|
2488
|
+
if (aStack != null && bStack != null) return aStack === b;
|
|
2489
|
+
stack.set(a, b);
|
|
2490
|
+
stack.set(b, a);
|
|
2491
|
+
try {
|
|
2492
|
+
switch (aTag) {
|
|
2493
|
+
case mapTag:
|
|
2494
|
+
if (a.size !== b.size) return false;
|
|
2495
|
+
for (const [key, value] of a.entries()) if (!b.has(key) || !isEqualWithImpl(value, b.get(key), key, a, b, stack, areValuesEqual)) return false;
|
|
2496
|
+
return true;
|
|
2497
|
+
case setTag: {
|
|
2498
|
+
if (a.size !== b.size) return false;
|
|
2499
|
+
const aValues = Array.from(a.values());
|
|
2500
|
+
const bValues = Array.from(b.values());
|
|
2501
|
+
for (let i = 0; i < aValues.length; i++) {
|
|
2502
|
+
const aValue = aValues[i];
|
|
2503
|
+
const index = bValues.findIndex((bValue) => {
|
|
2504
|
+
return isEqualWithImpl(aValue, bValue, void 0, a, b, stack, areValuesEqual);
|
|
2505
|
+
});
|
|
2506
|
+
if (index === -1) return false;
|
|
2507
|
+
bValues.splice(index, 1);
|
|
2508
|
+
}
|
|
2509
|
+
return true;
|
|
2510
|
+
}
|
|
2511
|
+
case arrayTag:
|
|
2512
|
+
case uint8ArrayTag:
|
|
2513
|
+
case uint8ClampedArrayTag:
|
|
2514
|
+
case uint16ArrayTag:
|
|
2515
|
+
case uint32ArrayTag:
|
|
2516
|
+
case bigUint64ArrayTag:
|
|
2517
|
+
case int8ArrayTag:
|
|
2518
|
+
case int16ArrayTag:
|
|
2519
|
+
case int32ArrayTag:
|
|
2520
|
+
case bigInt64ArrayTag:
|
|
2521
|
+
case float32ArrayTag:
|
|
2522
|
+
case float64ArrayTag:
|
|
2523
|
+
if (isBuffer(a) !== isBuffer(b)) return false;
|
|
2524
|
+
if (a.length !== b.length) return false;
|
|
2525
|
+
for (let i = 0; i < a.length; i++) if (!isEqualWithImpl(a[i], b[i], i, a, b, stack, areValuesEqual)) return false;
|
|
2526
|
+
return true;
|
|
2527
|
+
case arrayBufferTag:
|
|
2528
|
+
if (a.byteLength !== b.byteLength) return false;
|
|
2529
|
+
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
|
|
2530
|
+
case dataViewTag:
|
|
2531
|
+
if (a.byteLength !== b.byteLength || a.byteOffset !== b.byteOffset) return false;
|
|
2532
|
+
return areObjectsEqual(new Uint8Array(a), new Uint8Array(b), stack, areValuesEqual);
|
|
2533
|
+
case errorTag: return a.name === b.name && a.message === b.message;
|
|
2534
|
+
case objectTag: {
|
|
2535
|
+
if (!(areObjectsEqual(a.constructor, b.constructor, stack, areValuesEqual) || isPlainObject(a) && isPlainObject(b))) return false;
|
|
2536
|
+
const aKeys = [...Object.keys(a), ...getSymbols(a)];
|
|
2537
|
+
const bKeys = [...Object.keys(b), ...getSymbols(b)];
|
|
2538
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
2539
|
+
for (let i = 0; i < aKeys.length; i++) {
|
|
2540
|
+
const propKey = aKeys[i];
|
|
2541
|
+
const aProp = a[propKey];
|
|
2542
|
+
if (!Object.hasOwn(b, propKey)) return false;
|
|
2543
|
+
const bProp = b[propKey];
|
|
2544
|
+
if (!isEqualWithImpl(aProp, bProp, propKey, a, b, stack, areValuesEqual)) return false;
|
|
2545
|
+
}
|
|
2546
|
+
return true;
|
|
2547
|
+
}
|
|
2548
|
+
default: return false;
|
|
2549
|
+
}
|
|
2550
|
+
} finally {
|
|
2551
|
+
stack.delete(a);
|
|
2552
|
+
stack.delete(b);
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
//#endregion
|
|
2556
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/predicate/isEqual.mjs
|
|
2557
|
+
/**
|
|
2558
|
+
* Checks if two values are equal, including support for `Date`, `RegExp`, and deep object comparison.
|
|
2559
|
+
*
|
|
2560
|
+
* @param {unknown} a - The first value to compare.
|
|
2561
|
+
* @param {unknown} b - The second value to compare.
|
|
2562
|
+
* @returns {boolean} `true` if the values are equal, otherwise `false`.
|
|
2563
|
+
*
|
|
2564
|
+
* @example
|
|
2565
|
+
* isEqual(1, 1); // true
|
|
2566
|
+
* isEqual({ a: 1 }, { a: 1 }); // true
|
|
2567
|
+
* isEqual(/abc/g, /abc/g); // true
|
|
2568
|
+
* isEqual(new Date('2020-01-01'), new Date('2020-01-01')); // true
|
|
2569
|
+
* isEqual([1, 2, 3], [1, 2, 3]); // true
|
|
2570
|
+
*/
|
|
2571
|
+
function isEqual(a, b) {
|
|
2572
|
+
return isEqualWith(a, b, noop);
|
|
2573
|
+
}
|
|
2574
|
+
//#endregion
|
|
1999
2575
|
//#region src/react/useResponsive.ts
|
|
2000
2576
|
/** 屏幕响应断点 token 配置 */
|
|
2001
2577
|
const BREAK_POINT_TOKEN = {
|
|
@@ -2109,4 +2685,4 @@ function useTitle(title, options) {
|
|
|
2109
2685
|
});
|
|
2110
2686
|
}
|
|
2111
2687
|
//#endregion
|
|
2112
|
-
export { BREAK_POINT_TOKEN,
|
|
2688
|
+
export { BREAK_POINT_TOKEN, useLatest, useMount, useResponsive, useTitle, useUnmount };
|