@pawover/kit 0.4.1 → 0.5.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 +141 -30
- package/packages/hooks/dist/alova.cjs +53 -0
- package/packages/hooks/dist/alova.d.cts +1 -0
- package/packages/hooks/dist/index.cjs +0 -0
- package/packages/hooks/dist/index.d.cts +1 -0
- package/packages/hooks/dist/react.cjs +169 -0
- package/packages/hooks/dist/react.d.cts +1 -0
- package/packages/hooks/dist/react.d.ts +2 -60
- package/packages/hooks/dist/react.js +2 -2428
- package/packages/utils/dist/index.cjs +2300 -0
- package/packages/utils/dist/index.d.cts +1 -0
- package/packages/utils/dist/index.d.ts +157 -2712
- package/packages/utils/dist/index.js +122 -35
- package/packages/utils/dist/math-BznvO4qI.cjs +1029 -0
- package/packages/utils/dist/{math-Cvy9HBP0.js → math-DRbCtLQH.js} +44 -27
- package/packages/utils/dist/math.cjs +3 -0
- package/packages/utils/dist/math.d.cts +1 -0
- package/packages/utils/dist/math.d.ts +3 -0
- package/packages/utils/dist/math.js +1 -1
- package/packages/utils/dist/vite.cjs +44 -0
- package/packages/utils/dist/vite.d.cts +1 -0
- package/packages/utils/dist/vite.js +12 -8
- package/packages/zod/dist/index.cjs +91 -0
- package/packages/zod/dist/index.d.cts +1 -0
|
@@ -56,20 +56,12 @@ var TypeUtil = class {
|
|
|
56
56
|
static getPrototypeString(value) {
|
|
57
57
|
return Object.prototype.toString.call(value);
|
|
58
58
|
}
|
|
59
|
-
static isConstructable(fn) {
|
|
60
|
-
try {
|
|
61
|
-
Reflect.construct(fn, []);
|
|
62
|
-
return true;
|
|
63
|
-
} catch {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
59
|
/**
|
|
68
60
|
* 检查 value 是否为 string 类型
|
|
69
|
-
* - 当 `
|
|
61
|
+
* - 当 `checkNullish` 为 `true` 时,会先 trim 再判断是否为空
|
|
70
62
|
*
|
|
71
63
|
* @param value 待检查值
|
|
72
|
-
* @param
|
|
64
|
+
* @param checkNullish 是否检查空字符串(含空白字符串),默认为 `false`
|
|
73
65
|
* @returns 是否为字符串
|
|
74
66
|
* @example
|
|
75
67
|
* ```ts
|
|
@@ -80,8 +72,8 @@ var TypeUtil = class {
|
|
|
80
72
|
* TypeUtil.isString(" a ", true); // true
|
|
81
73
|
* ```
|
|
82
74
|
*/
|
|
83
|
-
static isString(value,
|
|
84
|
-
return typeof value === "string" && (!
|
|
75
|
+
static isString(value, checkNullish = false) {
|
|
76
|
+
return typeof value === "string" && (!checkNullish || value.trim().length > 0);
|
|
85
77
|
}
|
|
86
78
|
/**
|
|
87
79
|
* 检查 value 是否为 number 类型
|
|
@@ -260,6 +252,19 @@ var TypeUtil = class {
|
|
|
260
252
|
return value === null;
|
|
261
253
|
}
|
|
262
254
|
/**
|
|
255
|
+
* 检查 value 是否为 null 或 undefined
|
|
256
|
+
* @param value 待检查值
|
|
257
|
+
* @returns 是否为 Nullish
|
|
258
|
+
* @example
|
|
259
|
+
* ```ts
|
|
260
|
+
* TypeUtil.isNullish(null); // true
|
|
261
|
+
* TypeUtil.isNullish(undefined); // true
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
static isNullish(value) {
|
|
265
|
+
return this.isNull(value) || this.isUndefined(value);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
263
268
|
* 检查 value 是否为 Function
|
|
264
269
|
* @param value 待检查值
|
|
265
270
|
* @returns 是否为 Function
|
|
@@ -435,7 +440,7 @@ var TypeUtil = class {
|
|
|
435
440
|
* ```
|
|
436
441
|
*/
|
|
437
442
|
static isClass(value) {
|
|
438
|
-
return this.isFunction(value) && !this.isAsyncFunction(value) && Function.prototype.toString.call(value).startsWith("class ") &&
|
|
443
|
+
return this.isFunction(value) && !this.isAsyncFunction(value) && Function.prototype.toString.call(value).startsWith("class ") && value.prototype !== void 0;
|
|
439
444
|
}
|
|
440
445
|
/**
|
|
441
446
|
* 检查 value 是否为数组
|
|
@@ -686,7 +691,9 @@ var TypeUtil = class {
|
|
|
686
691
|
return !!value && typeof value[Symbol.iterator] === "function";
|
|
687
692
|
}
|
|
688
693
|
/**
|
|
689
|
-
* 检查 value 是否为 Falsy 值 (false, 0, "", null, undefined, NaN)
|
|
694
|
+
* 检查 value 是否为 Falsy 值 (false, 0, "", null, undefined, NaN, 0n)
|
|
695
|
+
* - 处理非字符串形式的 falsy;字符串形式(`"null"`、`"0"` 等)请使用 `isFalsyLike`
|
|
696
|
+
*
|
|
690
697
|
* @param value 待检查值
|
|
691
698
|
* @returns 是否为 Falsy
|
|
692
699
|
* @example
|
|
@@ -695,8 +702,7 @@ var TypeUtil = class {
|
|
|
695
702
|
* ```
|
|
696
703
|
*/
|
|
697
704
|
static isFalsy(value) {
|
|
698
|
-
|
|
699
|
-
return value === false || value === 0 || value === 0n || value === "";
|
|
705
|
+
return this.isNaN(value) || this.isNullish(value) || value === false || value === 0 || value === 0n || value === "";
|
|
700
706
|
}
|
|
701
707
|
/**
|
|
702
708
|
* 检查 value 是否为 FalsyLike 值
|
|
@@ -721,8 +727,8 @@ var TypeUtil = class {
|
|
|
721
727
|
* 字符串工具类
|
|
722
728
|
*/
|
|
723
729
|
var StringUtil = class {
|
|
724
|
-
static cast(candidate,
|
|
725
|
-
if (
|
|
730
|
+
static cast(candidate, checkNullish = true, trim = true) {
|
|
731
|
+
if (checkNullish) {
|
|
726
732
|
if (candidate === null || candidate === void 0) return "";
|
|
727
733
|
if (typeof candidate === "string" && candidate.trim().length === 0) return "";
|
|
728
734
|
}
|
|
@@ -777,19 +783,26 @@ var StringUtil = class {
|
|
|
777
783
|
return input.toUpperCase();
|
|
778
784
|
}
|
|
779
785
|
/**
|
|
780
|
-
*
|
|
781
|
-
* -
|
|
786
|
+
* 调整大小写
|
|
787
|
+
* - 每个单词(`\S+`)独立处理
|
|
788
|
+
* - 包含非西欧字母字符(如 `.`、`,`、`'`、`-`)时,该词不处理
|
|
782
789
|
* - 纯字母且全大写时,不处理
|
|
783
|
-
* -
|
|
784
|
-
* -
|
|
790
|
+
* - 纯字母且非全大写时:`caseType` 为 `"lower"` 则首字母小写,`"upper"` 则首字母大写,其余字符保留
|
|
791
|
+
* - ⚠️ 缺省 `caseType` 时不产生任何转换(no-op),需显式传 `"lower"` / `"upper"`
|
|
785
792
|
*
|
|
786
793
|
* @param input 待处理字符串
|
|
787
|
-
* @param caseType
|
|
794
|
+
* @param caseType 大小写类型(缺省时无操作)
|
|
788
795
|
* @returns 处理后的字符串
|
|
789
796
|
* @example
|
|
790
797
|
* ```ts
|
|
791
|
-
*
|
|
792
|
-
* StringUtil.toInitialCase("
|
|
798
|
+
* // 重载 1: lower
|
|
799
|
+
* StringUtil.toInitialCase("Hello World", "lower"); // "hello world"
|
|
800
|
+
*
|
|
801
|
+
* // 重载 2: upper
|
|
802
|
+
* StringUtil.toInitialCase("hello world", "upper"); // "Hello World"
|
|
803
|
+
*
|
|
804
|
+
* // 缺省 caseType → no-op
|
|
805
|
+
* StringUtil.toInitialCase("Hello"); // "Hello"
|
|
793
806
|
* ```
|
|
794
807
|
*/
|
|
795
808
|
static toInitialCase(input, caseType) {
|
|
@@ -908,14 +921,15 @@ var StringUtil = class {
|
|
|
908
921
|
static template(input, template, regex = /\{\{(.+?)\}\}/g) {
|
|
909
922
|
if (!TypeUtil.isString(input, true)) return "";
|
|
910
923
|
regex.lastIndex = 0;
|
|
924
|
+
const executor = regex.global ? regex : new RegExp(regex.source, `${regex.flags}g`);
|
|
911
925
|
let result = "";
|
|
912
926
|
let from = 0;
|
|
913
927
|
let match;
|
|
914
|
-
while (match =
|
|
928
|
+
while (match = executor.exec(input)) {
|
|
915
929
|
const replacement = template[match[1]];
|
|
916
930
|
const valueToInsert = replacement === null || replacement === void 0 ? match[0] : replacement;
|
|
917
931
|
result += input.slice(from, match.index) + valueToInsert;
|
|
918
|
-
from =
|
|
932
|
+
from = executor.lastIndex;
|
|
919
933
|
}
|
|
920
934
|
return result + input.slice(from);
|
|
921
935
|
}
|
|
@@ -977,6 +991,9 @@ var MathUtil = class MathUtil {
|
|
|
977
991
|
/**
|
|
978
992
|
* 数学表达式求值
|
|
979
993
|
*
|
|
994
|
+
* ⚠️ 安全警告:mathjs `evaluate` 存在已知的沙箱逃逸向量,**仅限可信输入**(硬编码表达式或受控参数),
|
|
995
|
+
* 切勿直接用于用户提供的表达式。
|
|
996
|
+
*
|
|
980
997
|
* @param mathJsInstance mathJs 实例
|
|
981
998
|
* @param expr 表达式
|
|
982
999
|
* @param scope 键值映射
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './math.d.ts'
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as MathUtil } from "./math-
|
|
1
|
+
import { t as MathUtil } from "./math-DRbCtLQH.js";
|
|
2
2
|
export { MathUtil };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/vite/viteUtil.ts
|
|
3
|
+
/**
|
|
4
|
+
* Vite 工具类
|
|
5
|
+
*/
|
|
6
|
+
var ViteUtil = class {
|
|
7
|
+
/**
|
|
8
|
+
* 开发服务器反向代理配置
|
|
9
|
+
*
|
|
10
|
+
* @param proxyList 代理配置项
|
|
11
|
+
* @param options 追加到每个代理项的 Vite `ProxyOptions`
|
|
12
|
+
* @returns Vite `server.proxy` 可直接使用的配置对象
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* ViteUtil.toProxy([
|
|
16
|
+
* ["/api", "http://localhost:3000"],
|
|
17
|
+
* ["/mock", "https://example.com"],
|
|
18
|
+
* ]);
|
|
19
|
+
* // {
|
|
20
|
+
* // "/api": { target: "http://localhost:3000", changeOrigin: true, ws: true, rewrite: [Function] },
|
|
21
|
+
* // "/mock": { target: "https://example.com", changeOrigin: true, ws: true, secure: false, rewrite: [Function] }
|
|
22
|
+
* // }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
static toProxy(proxyList, options) {
|
|
26
|
+
const httpsRE = /^https:\/\//;
|
|
27
|
+
const result = {};
|
|
28
|
+
if (Array.isArray(proxyList)) for (const [prefix, target] of proxyList) {
|
|
29
|
+
const isHttps = httpsRE.test(target);
|
|
30
|
+
const escapedPrefix = prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
31
|
+
result[prefix] = {
|
|
32
|
+
target,
|
|
33
|
+
changeOrigin: true,
|
|
34
|
+
ws: true,
|
|
35
|
+
rewrite: (path) => path.replace(new RegExp(`^${escapedPrefix}`), ""),
|
|
36
|
+
...isHttps ? { secure: false } : {},
|
|
37
|
+
...options
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
exports.ViteUtil = ViteUtil;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './vite.d.ts'
|
|
@@ -24,14 +24,18 @@ var ViteUtil = class {
|
|
|
24
24
|
static toProxy(proxyList, options) {
|
|
25
25
|
const httpsRE = /^https:\/\//;
|
|
26
26
|
const result = {};
|
|
27
|
-
if (
|
|
28
|
-
target
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
if (Array.isArray(proxyList)) for (const [prefix, target] of proxyList) {
|
|
28
|
+
const isHttps = httpsRE.test(target);
|
|
29
|
+
const escapedPrefix = prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
30
|
+
result[prefix] = {
|
|
31
|
+
target,
|
|
32
|
+
changeOrigin: true,
|
|
33
|
+
ws: true,
|
|
34
|
+
rewrite: (path) => path.replace(new RegExp(`^${escapedPrefix}`), ""),
|
|
35
|
+
...isHttps ? { secure: false } : {},
|
|
36
|
+
...options
|
|
37
|
+
};
|
|
38
|
+
}
|
|
35
39
|
return result;
|
|
36
40
|
}
|
|
37
41
|
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let zod = require("zod");
|
|
3
|
+
//#region src/server.ts
|
|
4
|
+
const id = zod.z.union([zod.z.string().min(1), zod.z.number()]);
|
|
5
|
+
const idAllowEmpty = id.nullish();
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/type.ts
|
|
8
|
+
/** 空 */
|
|
9
|
+
const empty = zod.z.union([zod.z.null(), zod.z.undefined()]);
|
|
10
|
+
/** 字符串 */
|
|
11
|
+
const string = zod.z.string();
|
|
12
|
+
/** 字符串-空 */
|
|
13
|
+
const stringEmpty = zod.z.literal("").nullish();
|
|
14
|
+
/** 字符串-非空 */
|
|
15
|
+
const stringNoEmpty = string.min(1);
|
|
16
|
+
/** 字符串-可空 */
|
|
17
|
+
const stringAllowEmpty = string.nullish();
|
|
18
|
+
/** 数字 */
|
|
19
|
+
const number = zod.z.number();
|
|
20
|
+
/** 数字-可空 */
|
|
21
|
+
const numberAllowEmpty = number.nullish();
|
|
22
|
+
/** 整数 */
|
|
23
|
+
const integer = number.int();
|
|
24
|
+
/** 整数-可空 */
|
|
25
|
+
const integerAllowEmpty = integer.nullish();
|
|
26
|
+
/** 整数-正整数和零 */
|
|
27
|
+
const integerPositive = integer.nonnegative().int();
|
|
28
|
+
/** 整数-正整数和零-可空 */
|
|
29
|
+
const integerPositiveAllowEmpty = integerPositive.nullish();
|
|
30
|
+
/** 整数-负整数和零 */
|
|
31
|
+
const integerNegative = integer.nonpositive().int();
|
|
32
|
+
/** 整数-负整数和零-可空 */
|
|
33
|
+
const integerNegativeAllowEmpty = integerNegative.nullish();
|
|
34
|
+
/** 布尔值 */
|
|
35
|
+
const boolean = zod.z.boolean();
|
|
36
|
+
/** 布尔值-可空 */
|
|
37
|
+
const booleanAllowEmpty = boolean.nullish();
|
|
38
|
+
/** 大数字 */
|
|
39
|
+
const bigint = zod.z.bigint();
|
|
40
|
+
/** 大数字-可空 */
|
|
41
|
+
const bigintAllowEmpty = bigint.nullish();
|
|
42
|
+
/** 大数字-正整数和零 */
|
|
43
|
+
const bigintPositive = bigint.nonnegative();
|
|
44
|
+
/** 大数字-正整数和零-可空 */
|
|
45
|
+
const bigintPositiveAllowEmpty = bigintPositive.nullish();
|
|
46
|
+
/** 大数字-负整数和零 */
|
|
47
|
+
const bigintNegative = bigint.nonpositive();
|
|
48
|
+
/** 大数字-负整数和零-可空 */
|
|
49
|
+
const bigintNegativeAllowEmpty = bigintNegative.nullish();
|
|
50
|
+
const symbol = zod.z.symbol();
|
|
51
|
+
const any = zod.z.any();
|
|
52
|
+
const unknown = zod.z.unknown();
|
|
53
|
+
const never = zod.z.never();
|
|
54
|
+
const propertyKey = zod.z.union([
|
|
55
|
+
string,
|
|
56
|
+
number,
|
|
57
|
+
symbol
|
|
58
|
+
]);
|
|
59
|
+
const anyObject = zod.z.record(propertyKey, any);
|
|
60
|
+
const plainObject = zod.z.record(propertyKey, unknown);
|
|
61
|
+
//#endregion
|
|
62
|
+
exports.any = any;
|
|
63
|
+
exports.anyObject = anyObject;
|
|
64
|
+
exports.bigint = bigint;
|
|
65
|
+
exports.bigintAllowEmpty = bigintAllowEmpty;
|
|
66
|
+
exports.bigintNegative = bigintNegative;
|
|
67
|
+
exports.bigintNegativeAllowEmpty = bigintNegativeAllowEmpty;
|
|
68
|
+
exports.bigintPositive = bigintPositive;
|
|
69
|
+
exports.bigintPositiveAllowEmpty = bigintPositiveAllowEmpty;
|
|
70
|
+
exports.boolean = boolean;
|
|
71
|
+
exports.booleanAllowEmpty = booleanAllowEmpty;
|
|
72
|
+
exports.empty = empty;
|
|
73
|
+
exports.id = id;
|
|
74
|
+
exports.idAllowEmpty = idAllowEmpty;
|
|
75
|
+
exports.integer = integer;
|
|
76
|
+
exports.integerAllowEmpty = integerAllowEmpty;
|
|
77
|
+
exports.integerNegative = integerNegative;
|
|
78
|
+
exports.integerNegativeAllowEmpty = integerNegativeAllowEmpty;
|
|
79
|
+
exports.integerPositive = integerPositive;
|
|
80
|
+
exports.integerPositiveAllowEmpty = integerPositiveAllowEmpty;
|
|
81
|
+
exports.never = never;
|
|
82
|
+
exports.number = number;
|
|
83
|
+
exports.numberAllowEmpty = numberAllowEmpty;
|
|
84
|
+
exports.plainObject = plainObject;
|
|
85
|
+
exports.propertyKey = propertyKey;
|
|
86
|
+
exports.string = string;
|
|
87
|
+
exports.stringAllowEmpty = stringAllowEmpty;
|
|
88
|
+
exports.stringEmpty = stringEmpty;
|
|
89
|
+
exports.stringNoEmpty = stringNoEmpty;
|
|
90
|
+
exports.symbol = symbol;
|
|
91
|
+
exports.unknown = unknown;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './index.d.ts'
|