@pawover/kit 0.1.0 → 0.2.0
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.
|
@@ -1,46 +1,52 @@
|
|
|
1
|
-
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
|
|
2
|
-
function _typeof(o) {
|
|
3
|
-
"@babel/helpers - typeof";
|
|
4
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
5
|
-
return typeof o;
|
|
6
|
-
} : function(o) {
|
|
7
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
8
|
-
}, _typeof(o);
|
|
9
|
-
}
|
|
10
|
-
//#endregion
|
|
11
|
-
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
|
|
12
|
-
function toPrimitive(t, r) {
|
|
13
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
14
|
-
var e = t[Symbol.toPrimitive];
|
|
15
|
-
if (void 0 !== e) {
|
|
16
|
-
var i = e.call(t, r || "default");
|
|
17
|
-
if ("object" != _typeof(i)) return i;
|
|
18
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
19
|
-
}
|
|
20
|
-
return ("string" === r ? String : Number)(t);
|
|
21
|
-
}
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
|
|
24
|
-
function toPropertyKey(t) {
|
|
25
|
-
var i = toPrimitive(t, "string");
|
|
26
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
27
|
-
}
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
|
|
30
|
-
function _defineProperty(e, r, t) {
|
|
31
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
32
|
-
value: t,
|
|
33
|
-
enumerable: !0,
|
|
34
|
-
configurable: !0,
|
|
35
|
-
writable: !0
|
|
36
|
-
}) : e[r] = t, e;
|
|
37
|
-
}
|
|
38
|
-
//#endregion
|
|
39
1
|
//#region src/type/typeUtil.ts
|
|
40
2
|
/**
|
|
41
3
|
* 类型工具类
|
|
42
4
|
*/
|
|
43
5
|
var TypeUtil = class {
|
|
6
|
+
static PROTOTYPE_TAGS = {
|
|
7
|
+
STRING: "[object String]",
|
|
8
|
+
NUMBER: "[object Number]",
|
|
9
|
+
BOOLEAN: "[object Boolean]",
|
|
10
|
+
BIGINT: "[object BigInt]",
|
|
11
|
+
SYMBOL: "[object Symbol]",
|
|
12
|
+
UNDEFINED: "[object Undefined]",
|
|
13
|
+
NULL: "[object Null]",
|
|
14
|
+
OBJECT: "[object Object]",
|
|
15
|
+
FUNCTION: "[object Function]",
|
|
16
|
+
GENERATOR_FUNCTION: "[object GeneratorFunction]",
|
|
17
|
+
ASYNC_FUNCTION: "[object AsyncFunction]",
|
|
18
|
+
ASYNC_GENERATOR_FUNCTION: "[object AsyncGeneratorFunction]",
|
|
19
|
+
PROMISE: "[object Promise]",
|
|
20
|
+
MAP: "[object Map]",
|
|
21
|
+
SET: "[object Set]",
|
|
22
|
+
WEAK_MAP: "[object WeakMap]",
|
|
23
|
+
WEAK_SET: "[object WeakSet]",
|
|
24
|
+
BLOB: "[object Blob]",
|
|
25
|
+
FILE: "[object File]",
|
|
26
|
+
READABLE_STREAM: "[object ReadableStream]",
|
|
27
|
+
GLOBAL: "[object global]",
|
|
28
|
+
WINDOW: "[object Window]",
|
|
29
|
+
IFRAME: "[object HTMLIFrameElement]",
|
|
30
|
+
DATE: "[object Date]",
|
|
31
|
+
ERROR: "[object Error]",
|
|
32
|
+
REG_EXP: "[object RegExp]",
|
|
33
|
+
WEB_SOCKET: "[object WebSocket]",
|
|
34
|
+
URL_SEARCH_PARAMS: "[object URLSearchParams]",
|
|
35
|
+
ABORT_SIGNAL: "[object AbortSignal]"
|
|
36
|
+
};
|
|
37
|
+
static TYPED_ARRAY_TAGS = /* @__PURE__ */ new Set([
|
|
38
|
+
"[object Int8Array]",
|
|
39
|
+
"[object Uint8Array]",
|
|
40
|
+
"[object Uint8ClampedArray]",
|
|
41
|
+
"[object Int16Array]",
|
|
42
|
+
"[object Uint16Array]",
|
|
43
|
+
"[object Int32Array]",
|
|
44
|
+
"[object Uint32Array]",
|
|
45
|
+
"[object Float32Array]",
|
|
46
|
+
"[object Float64Array]",
|
|
47
|
+
"[object BigInt64Array]",
|
|
48
|
+
"[object BigUint64Array]"
|
|
49
|
+
]);
|
|
44
50
|
/**
|
|
45
51
|
* 获取值的 [[Prototype]] 标签
|
|
46
52
|
*
|
|
@@ -60,19 +66,22 @@ var TypeUtil = class {
|
|
|
60
66
|
}
|
|
61
67
|
/**
|
|
62
68
|
* 检查 value 是否为 string 类型
|
|
69
|
+
* - 当 `checkEmpty` 为 `true` 时,会先 trim 再判断是否为空
|
|
63
70
|
*
|
|
64
71
|
* @param value 待检查值
|
|
65
|
-
* @param checkEmpty
|
|
72
|
+
* @param checkEmpty 是否检查空字符串(含空白字符串),默认为 `false`
|
|
66
73
|
* @returns 是否为字符串
|
|
67
74
|
* @example
|
|
68
75
|
* ```ts
|
|
69
76
|
* TypeUtil.isString("abc"); // true
|
|
70
77
|
* TypeUtil.isString(""); // true
|
|
71
78
|
* TypeUtil.isString("", true); // false
|
|
79
|
+
* TypeUtil.isString(" ", true); // false
|
|
80
|
+
* TypeUtil.isString(" a ", true); // true
|
|
72
81
|
* ```
|
|
73
82
|
*/
|
|
74
83
|
static isString(value, checkEmpty = false) {
|
|
75
|
-
return typeof value === "string" && (!checkEmpty ||
|
|
84
|
+
return typeof value === "string" && (!checkEmpty || value.trim().length > 0);
|
|
76
85
|
}
|
|
77
86
|
/**
|
|
78
87
|
* 检查 value 是否为 number 类型
|
|
@@ -321,7 +330,7 @@ var TypeUtil = class {
|
|
|
321
330
|
* ```
|
|
322
331
|
*/
|
|
323
332
|
static isPromiseLike(value) {
|
|
324
|
-
return this.isPromise(value) || this.
|
|
333
|
+
return this.isPromise(value) || this.isPlainObject(value, false) && this.isFunction(value["then"]);
|
|
325
334
|
}
|
|
326
335
|
/**
|
|
327
336
|
* 判断是否为普通对象类型
|
|
@@ -329,18 +338,19 @@ var TypeUtil = class {
|
|
|
329
338
|
*
|
|
330
339
|
* @param value 待检查值
|
|
331
340
|
* @param prototypeCheck 是否进行原型检查,默认 `true`
|
|
332
|
-
* @returns 是否为 Plain Object (当
|
|
341
|
+
* @returns 是否为 Plain Object (当 prototypeCheck=true) 或 object
|
|
333
342
|
* @example
|
|
334
343
|
* ```ts
|
|
335
|
-
* TypeUtil.
|
|
336
|
-
* TypeUtil.
|
|
337
|
-
* TypeUtil.
|
|
338
|
-
* TypeUtil.
|
|
339
|
-
* TypeUtil.
|
|
340
|
-
* TypeUtil.
|
|
344
|
+
* TypeUtil.isPlainObject({}); // true
|
|
345
|
+
* TypeUtil.isPlainObject([]); // false
|
|
346
|
+
* TypeUtil.isPlainObject(new Date()); // false
|
|
347
|
+
* TypeUtil.isPlainObject(new (class {})()); // false
|
|
348
|
+
* TypeUtil.isPlainObject(new (class {})(), false); // true
|
|
349
|
+
* TypeUtil.isPlainObject(Object.create(null)) // false
|
|
350
|
+
* TypeUtil.isPlainObject(Object.create(null), false) // true
|
|
341
351
|
* ```
|
|
342
352
|
*/
|
|
343
|
-
static
|
|
353
|
+
static isPlainObject(value, prototypeCheck = true) {
|
|
344
354
|
const check = this.getPrototypeString(value) === this.PROTOTYPE_TAGS.OBJECT;
|
|
345
355
|
return prototypeCheck ? check && Object.getPrototypeOf(value) === Object.prototype : check;
|
|
346
356
|
}
|
|
@@ -524,7 +534,7 @@ var TypeUtil = class {
|
|
|
524
534
|
*/
|
|
525
535
|
static isReadableStream(value) {
|
|
526
536
|
if (this.getPrototypeString(value) === this.PROTOTYPE_TAGS.READABLE_STREAM) return true;
|
|
527
|
-
return this.
|
|
537
|
+
return this.isPlainObject(value) && this.isFunction(value["getReader"]) && this.isFunction(value["pipeThrough"]);
|
|
528
538
|
}
|
|
529
539
|
/**
|
|
530
540
|
* 检查 value 是否为 Window
|
|
@@ -688,56 +698,19 @@ var TypeUtil = class {
|
|
|
688
698
|
return typeof value === "string" && (value === "null" || value === "undefined" || value === "NaN" || value === "false" || value === "0" || value === "-0" || value === "0n");
|
|
689
699
|
}
|
|
690
700
|
};
|
|
691
|
-
_defineProperty(TypeUtil, "PROTOTYPE_TAGS", {
|
|
692
|
-
STRING: "[object String]",
|
|
693
|
-
NUMBER: "[object Number]",
|
|
694
|
-
BOOLEAN: "[object Boolean]",
|
|
695
|
-
BIGINT: "[object BigInt]",
|
|
696
|
-
SYMBOL: "[object Symbol]",
|
|
697
|
-
UNDEFINED: "[object Undefined]",
|
|
698
|
-
NULL: "[object Null]",
|
|
699
|
-
OBJECT: "[object Object]",
|
|
700
|
-
FUNCTION: "[object Function]",
|
|
701
|
-
GENERATOR_FUNCTION: "[object GeneratorFunction]",
|
|
702
|
-
ASYNC_FUNCTION: "[object AsyncFunction]",
|
|
703
|
-
ASYNC_GENERATOR_FUNCTION: "[object AsyncGeneratorFunction]",
|
|
704
|
-
PROMISE: "[object Promise]",
|
|
705
|
-
MAP: "[object Map]",
|
|
706
|
-
SET: "[object Set]",
|
|
707
|
-
WEAK_MAP: "[object WeakMap]",
|
|
708
|
-
WEAK_SET: "[object WeakSet]",
|
|
709
|
-
BLOB: "[object Blob]",
|
|
710
|
-
FILE: "[object File]",
|
|
711
|
-
READABLE_STREAM: "[object ReadableStream]",
|
|
712
|
-
GLOBAL: "[object global]",
|
|
713
|
-
WINDOW: "[object Window]",
|
|
714
|
-
IFRAME: "[object HTMLIFrameElement]",
|
|
715
|
-
DATE: "[object Date]",
|
|
716
|
-
ERROR: "[object Error]",
|
|
717
|
-
REG_EXP: "[object RegExp]",
|
|
718
|
-
WEB_SOCKET: "[object WebSocket]",
|
|
719
|
-
URL_SEARCH_PARAMS: "[object URLSearchParams]",
|
|
720
|
-
ABORT_SIGNAL: "[object AbortSignal]"
|
|
721
|
-
});
|
|
722
|
-
_defineProperty(TypeUtil, "TYPED_ARRAY_TAGS", new Set([
|
|
723
|
-
"[object Int8Array]",
|
|
724
|
-
"[object Uint8Array]",
|
|
725
|
-
"[object Uint8ClampedArray]",
|
|
726
|
-
"[object Int16Array]",
|
|
727
|
-
"[object Uint16Array]",
|
|
728
|
-
"[object Int32Array]",
|
|
729
|
-
"[object Uint32Array]",
|
|
730
|
-
"[object Float32Array]",
|
|
731
|
-
"[object Float64Array]",
|
|
732
|
-
"[object BigInt64Array]",
|
|
733
|
-
"[object BigUint64Array]"
|
|
734
|
-
]));
|
|
735
701
|
//#endregion
|
|
736
702
|
//#region src/string/stringUtil.ts
|
|
737
703
|
/**
|
|
738
704
|
* 字符串工具类
|
|
739
705
|
*/
|
|
740
706
|
var StringUtil = class {
|
|
707
|
+
static cast(candidate, checkEmpty = true) {
|
|
708
|
+
if (checkEmpty) {
|
|
709
|
+
if (candidate === null || candidate === void 0) return "";
|
|
710
|
+
if (typeof candidate === "string" && candidate.trim().length === 0) return "";
|
|
711
|
+
}
|
|
712
|
+
return String(candidate);
|
|
713
|
+
}
|
|
741
714
|
/**
|
|
742
715
|
* 从字符串中提取数字字符串
|
|
743
716
|
* - 移除非数字字符,保留符号和小数点
|
|
@@ -838,8 +811,8 @@ var StringUtil = class {
|
|
|
838
811
|
let normalized = input.replace(/^[A-Za-z]:([\\/])?/, (_, separator) => {
|
|
839
812
|
return separator ? "/" : "";
|
|
840
813
|
});
|
|
841
|
-
normalized = normalized.
|
|
842
|
-
normalized = normalized.
|
|
814
|
+
normalized = normalized.replaceAll("\\", "/");
|
|
815
|
+
normalized = normalized.replaceAll(/\/+/g, "/");
|
|
843
816
|
if (removeLeadingSlash && normalized.startsWith("/")) normalized = normalized.substring(1);
|
|
844
817
|
return normalized;
|
|
845
818
|
}
|
|
@@ -947,4 +920,4 @@ var StringUtil = class {
|
|
|
947
920
|
}
|
|
948
921
|
};
|
|
949
922
|
//#endregion
|
|
950
|
-
export { TypeUtil as n,
|
|
923
|
+
export { TypeUtil as n, StringUtil as t };
|