@pawover/kit 0.0.0-alpha.6 → 0.0.0-alpha.8

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.
@@ -51,3 +51,4 @@ export declare function enumValues<E extends AnyObject>(enumeration: NonEmptyObj
51
51
  * @param enumeration 枚举
52
52
  */
53
53
  export declare function enumEntries<E extends AnyObject>(enumeration: NonEmptyObject<E>): [keyof E, E[keyof E]][];
54
+ export declare function mapEntries<TKey extends PropertyKey, TValue, TNewKey extends PropertyKey, TNewValue>(obj: UnknownObject<TKey, TValue>, toEntry: (key: TKey, value: TValue) => [TNewKey, TNewValue]): UnknownObject<TNewKey, TNewValue>;
@@ -1,3 +1,4 @@
1
+ import type { Replace } from "type-fest";
1
2
  /**
2
3
  * 转义特殊字符
3
4
  *
@@ -11,3 +12,4 @@ export declare function escapeStringRegexp(value: string): string;
11
12
  export declare function stringInitialCase(value: string, type: "lower" | "upper"): string;
12
13
  export declare function stringToJson<R extends AnyObject = AnyObject, D extends R = R>(data: string | null | undefined, safeValue: D): R;
13
14
  export declare function stringToValues<T extends number | string = number>(data: string | null | undefined, valueType?: "number" | "string"): T[];
15
+ export declare function stringReplace<I extends string, S extends string, R extends string>(input: I, search: S, replacement: R): Replace<I, S, R>;
@@ -0,0 +1,3 @@
1
+ export * from "./primitive";
2
+ export * from "./validator/input";
3
+ export * from "./validator/societal";
@@ -0,0 +1,32 @@
1
+ import { z } from "zod";
2
+ /** 空 */
3
+ export declare const empty: z.ZodUnion<readonly [z.ZodNull, z.ZodUndefined]>;
4
+ /** 字符串 */
5
+ export declare const string: z.ZodString;
6
+ /** 字符串-空 */
7
+ export declare const stringEmpty: z.ZodOptional<z.ZodNullable<z.ZodLiteral<"">>>;
8
+ /** 字符串-非空 */
9
+ export declare const stringNoEmpty: z.ZodString;
10
+ /** 字符串-可空 */
11
+ export declare const stringAllowEmpty: z.ZodOptional<z.ZodNullable<z.ZodString>>;
12
+ /** 数字 */
13
+ export declare const number: z.ZodNumber;
14
+ /** 数字-可空 */
15
+ export declare const numberAllowEmpty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
16
+ /** 整数 */
17
+ export declare const int: z.ZodNumber;
18
+ /** 整数-可空 */
19
+ export declare const intAllowEmpty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
20
+ /** 自然数 */
21
+ export declare const natural: z.ZodNumber;
22
+ /** 自然数-可空 */
23
+ export declare const naturalAllowEmpty: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
24
+ /** 布尔值 */
25
+ export declare const boolean: z.ZodBoolean;
26
+ /** 布尔值-可空 */
27
+ export declare const booleanAllowEmpty: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
28
+ export declare const bigint: z.ZodBigInt;
29
+ export declare const symbol: z.ZodSymbol;
30
+ export declare const any: z.ZodAny;
31
+ export declare const unknown: z.ZodUnknown;
32
+ export declare const never: z.ZodNever;
@@ -0,0 +1,27 @@
1
+ import { z } from "zod";
2
+ /** 字母 */
3
+ export declare const alphabet: z.ZodString;
4
+ /** 小写字母 */
5
+ export declare const alphabetLowercase: z.ZodString;
6
+ /** 大写字母 */
7
+ export declare const alphabetUppercase: z.ZodString;
8
+ /** 不包含字母 */
9
+ export declare const alphabetOmit: z.ZodString;
10
+ /** 数字和字母 */
11
+ export declare const numberAlphabet: z.ZodString;
12
+ /** 有符号十进制浮点数字符串 */
13
+ export declare const stringSignedDecimalismFloat: z.ZodString;
14
+ /** 无符号十进制浮点数字符串 */
15
+ export declare const stringUnsignedDecimalismFloat: z.ZodString;
16
+ /** 有符号十进制整数字符串 */
17
+ export declare const stringSignedDecimalismInt: z.ZodString;
18
+ /** 无符号十进制整数字符串 */
19
+ export declare const stringUnsignedDecimalismInt: z.ZodString;
20
+ /** 包含空格 */
21
+ export declare const spaceInclude: z.ZodString;
22
+ /** 首空格 */
23
+ export declare const spaceStart: z.ZodString;
24
+ /** 尾空格 */
25
+ export declare const spaceEnd: z.ZodString;
26
+ /** 首尾空格 */
27
+ export declare const spaceStartEnd: z.ZodIntersection<z.ZodString, z.ZodString>;
@@ -0,0 +1,39 @@
1
+ import { z } from "zod";
2
+ /** 手机号码 */
3
+ export declare const phone: z.ZodString;
4
+ /** 固定电话 */
5
+ export declare const telephone: z.ZodString;
6
+ /** 电子邮箱 */
7
+ export declare const email: z.ZodString;
8
+ /** 中文姓名 */
9
+ export declare const chineseName: z.ZodString;
10
+ /** 手机机身码 */
11
+ export declare const IMEI: z.ZodString;
12
+ /** 身份证号 */
13
+ export declare const ID: z.ZodString;
14
+ /** 链接 */
15
+ export declare const link: z.ZodString;
16
+ /** 端口号网址 */
17
+ export declare const linkPort: z.ZodString;
18
+ /** 统一社会信用代码 */
19
+ export declare const USCC_S: z.ZodString;
20
+ /** 统一社会信用代码 - 15位/18位/20位数字/字母 */
21
+ export declare const USCC: z.ZodString;
22
+ /** 迅雷链接 */
23
+ export declare const thunder: z.ZodString;
24
+ /** windows 文件夹路径 */
25
+ export declare const dirPathWindows: z.ZodString;
26
+ /** windows 文件路径 */
27
+ export declare const filePathWindows: z.ZodString;
28
+ /** linux 文件夹路径 */
29
+ export declare const dirPathLinux: z.ZodString;
30
+ /** linux 文件路径 */
31
+ export declare const filePathLinux: z.ZodString;
32
+ /** 车牌号 新能源 */
33
+ export declare const carCodeGreen: z.ZodString;
34
+ /** 车牌号 非新能源 */
35
+ export declare const carCodeNotGreen: z.ZodString;
36
+ /** 中国省份 */
37
+ export declare const chinaProvince: z.ZodString;
38
+ /** 民族 */
39
+ export declare const nation: z.ZodString;
@@ -54,9 +54,9 @@ export function objectAssign(obj, overrideObj) {
54
54
  if (!isObject(obj) || !isObject(overrideObj)) {
55
55
  return obj ?? overrideObj ?? result;
56
56
  }
57
- return Object.entries({ ...obj, ...overrideObj }).reduce((prev, [key, value]) => {
57
+ return objectEntries({ ...obj, ...overrideObj }).reduce((acc, [key, value]) => {
58
58
  return {
59
- ...prev,
59
+ ...acc,
60
60
  [key]: (() => {
61
61
  if (isObject(obj[key])) {
62
62
  return objectAssign(obj[key], value);
@@ -74,11 +74,11 @@ export function objectPick(obj, keys) {
74
74
  if (!isArray(keys)) {
75
75
  return obj;
76
76
  }
77
- return keys.reduce((prev, curr) => {
77
+ return keys.reduce((acc, curr) => {
78
78
  if (curr in obj) {
79
- prev[curr] = obj[curr];
79
+ acc[curr] = obj[curr];
80
80
  }
81
- return prev;
81
+ return acc;
82
82
  }, result);
83
83
  }
84
84
  function enumType(enumeration) {
@@ -136,3 +136,14 @@ export function enumEntries(enumeration) {
136
136
  }
137
137
  return entries;
138
138
  }
139
+ export function mapEntries(obj, toEntry) {
140
+ const defaultResult = {};
141
+ if (!obj) {
142
+ return defaultResult;
143
+ }
144
+ return objectEntries(obj).reduce((acc, [key, value]) => {
145
+ const [newKey, newValue] = toEntry(key, value);
146
+ acc[newKey] = newValue;
147
+ return acc;
148
+ }, defaultResult);
149
+ }
@@ -68,3 +68,6 @@ export function stringToValues(data, valueType = "number") {
68
68
  return [];
69
69
  }
70
70
  }
71
+ export function stringReplace(input, search, replacement) {
72
+ return input.replace(search, replacement);
73
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./primitive";
2
+ export * from "./validator/input";
3
+ export * from "./validator/societal";
@@ -0,0 +1,32 @@
1
+ import { z } from "zod";
2
+ /** 空 */
3
+ export const empty = z.union([z.null(), z.undefined()]);
4
+ /** 字符串 */
5
+ export const string = z.string();
6
+ /** 字符串-空 */
7
+ export const stringEmpty = z.literal("").nullish();
8
+ /** 字符串-非空 */
9
+ export const stringNoEmpty = z.string().min(1);
10
+ /** 字符串-可空 */
11
+ export const stringAllowEmpty = z.string().nullish();
12
+ /** 数字 */
13
+ export const number = z.number();
14
+ /** 数字-可空 */
15
+ export const numberAllowEmpty = number.nullish();
16
+ /** 整数 */
17
+ export const int = z.number().int({ error: "应为整数" });
18
+ /** 整数-可空 */
19
+ export const intAllowEmpty = int.nullish();
20
+ /** 自然数 */
21
+ export const natural = int.nonnegative({ error: "应为非负数" });
22
+ /** 自然数-可空 */
23
+ export const naturalAllowEmpty = natural.nullish();
24
+ /** 布尔值 */
25
+ export const boolean = z.boolean();
26
+ /** 布尔值-可空 */
27
+ export const booleanAllowEmpty = z.boolean().nullish();
28
+ export const bigint = z.bigint();
29
+ export const symbol = z.symbol();
30
+ export const any = z.any();
31
+ export const unknown = z.unknown();
32
+ export const never = z.never();
@@ -0,0 +1,39 @@
1
+ import { z } from "zod";
2
+ const _alphabet = /^[a-z]+$/i;
3
+ /** 字母 */
4
+ export const alphabet = z.string().regex(_alphabet, { error: "应为字母" });
5
+ const _alphabetLowercase = /^[a-z]+$/;
6
+ /** 小写字母 */
7
+ export const alphabetLowercase = z.string().regex(_alphabetLowercase, { error: "应为小写字母" });
8
+ const _alphabetUppercase = /^[A-Z]+$/;
9
+ /** 大写字母 */
10
+ export const alphabetUppercase = z.string().regex(_alphabetUppercase, { error: "应为大写字母" });
11
+ const _alphabetOmit = /^[^A-Z]*$/i;
12
+ /** 不包含字母 */
13
+ export const alphabetOmit = z.string().regex(_alphabetOmit, { error: "应不包含字母" });
14
+ const _numberAlphabet = /^[A-Z0-9]+$/i;
15
+ /** 数字和字母 */
16
+ export const numberAlphabet = z.string().regex(_numberAlphabet, { error: "应为数字和字母组合" });
17
+ const _stringSignedDecimalismFloat = /^[+-]?(\d+(\.\d+)?|\.\d+)$/;
18
+ /** 有符号十进制浮点数字符串 */
19
+ export const stringSignedDecimalismFloat = z.string().regex(_stringSignedDecimalismFloat, { error: "应为十进制数字" });
20
+ const _stringUnsignedDecimalismFloat = /^\+?(\d+(\.\d+)?|\.\d+)$/;
21
+ /** 无符号十进制浮点数字符串 */
22
+ export const stringUnsignedDecimalismFloat = z.string().regex(_stringUnsignedDecimalismFloat, { error: "应为十进制正数" });
23
+ const _stringSignedDecimalismInt = /^[+-]?\d+$/;
24
+ /** 有符号十进制整数字符串 */
25
+ export const stringSignedDecimalismInt = z.string().regex(_stringSignedDecimalismInt, { error: "应为十进制整数" });
26
+ const _stringUnsignedDecimalismInt = /^\+?\d+$/;
27
+ /** 无符号十进制整数字符串 */
28
+ export const stringUnsignedDecimalismInt = z.string().regex(_stringUnsignedDecimalismInt, { error: "应为十进制正整数" });
29
+ const _spaceInclude = /^[^ ]+$/;
30
+ /** 包含空格 */
31
+ export const spaceInclude = z.string().regex(_spaceInclude, { error: "应不包含空格" });
32
+ const _spaceStart = /^\S/g;
33
+ /** 首空格 */
34
+ export const spaceStart = z.string().regex(_spaceStart, { error: "应不包含首空格" });
35
+ const _spaceEnd = /\s$/g;
36
+ /** 尾空格 */
37
+ export const spaceEnd = z.string().regex(_spaceEnd, { error: "应不包含尾空格" });
38
+ /** 首尾空格 */
39
+ export const spaceStartEnd = spaceStart.and(spaceEnd);
@@ -0,0 +1,57 @@
1
+ import { z } from "zod";
2
+ const _phone = /^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/;
3
+ /** 手机号码 */
4
+ export const phone = z.string().regex(_phone, { error: "手机号码格式错误" });
5
+ const _telephone = /0\d{2,3}-\d{7,9}$/;
6
+ /** 固定电话 */
7
+ export const telephone = z.string().regex(_telephone, { error: "电话号码格式错误" });
8
+ const _email = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])|(([a-z\-0-9]+\.)+[a-z]{2,}))$/i;
9
+ /** 电子邮箱 */
10
+ export const email = z.string().regex(_email, { error: "电子邮箱格式错误" });
11
+ const _chineseName = /^[一-龢][一·-龢]*$/;
12
+ /** 中文姓名 */
13
+ export const chineseName = z.string().regex(_chineseName, { error: "应为中文姓名" });
14
+ /** 手机机身码 */
15
+ export const IMEI = z.string().regex(/^\d{15,17}$/, { error: "手机机身码格式错误" });
16
+ const _ID = /^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))([\dX])$/i;
17
+ /** 身份证号 */
18
+ export const ID = z.string().regex(_ID, { error: "身份证号格式错误" });
19
+ const _link = /^(((ht|f)tps?):\/\/)?(([\w-]+(\.[\w-]+)*\.[a-z]{2,6})|((\d{1,3}\.){3}\d{1,3}))(:\d+)?(\/\S*)?$/;
20
+ /** 链接 */
21
+ export const link = z.string().regex(_link, { error: "链接格式错误" });
22
+ const _linkPort = /^((ht|f)tps?:\/\/)?[\w-]+(\.[\w-]+)+:\d{1,5}\/?$/;
23
+ /** 端口号网址 */
24
+ export const linkPort = z.string().regex(_linkPort, { error: "网址格式错误" });
25
+ const _USCC_S = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/;
26
+ /** 统一社会信用代码 */
27
+ export const USCC_S = z.string().regex(_USCC_S, { error: "统一社会信用代码格式错误" });
28
+ const _USCC = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/;
29
+ /** 统一社会信用代码 - 15位/18位/20位数字/字母 */
30
+ export const USCC = z.string().regex(_USCC, { error: "统一社会信用代码格式错误" });
31
+ const _thunder = /^thunderx?:\/\/[a-zA-Z\d]+=$/;
32
+ /** 迅雷链接 */
33
+ export const thunder = z.string().regex(_thunder, { error: "迅雷链接格式错误" });
34
+ const _dirPathWindows = /^[a-z]:\\(?:\w+\\?)*$/i;
35
+ /** windows 文件夹路径 */
36
+ export const dirPathWindows = z.string().regex(_dirPathWindows, { error: "路径格式错误" });
37
+ const _filePathWindows = /^[a-z]:\\(?:\w+\\)*\w+\.\w+$/i;
38
+ /** windows 文件路径 */
39
+ export const filePathWindows = z.string().regex(_filePathWindows, { error: "路径格式错误" });
40
+ const _dirPathLinux = /^\/(?:[^/]+\/)*$/;
41
+ /** linux 文件夹路径 */
42
+ export const dirPathLinux = z.string().regex(_dirPathLinux, { error: "路径格式错误" });
43
+ const _filePathLinux = /^\/(?:[^/]+\/)*[^/]+$/;
44
+ /** linux 文件路径 */
45
+ export const filePathLinux = z.string().regex(_filePathLinux, { error: "路径格式错误" });
46
+ const _carCodeGreen = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z](([DF]((?![IO])[a-zA-Z0-9](?![IO]))\d{4})|(\d{5}[DF]))$/;
47
+ /** 车牌号 新能源 */
48
+ export const carCodeGreen = z.string().regex(_carCodeGreen, { error: "车牌号格式错误" });
49
+ const _carCodeNotGreen = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$/;
50
+ /** 车牌号 非新能源 */
51
+ export const carCodeNotGreen = z.string().regex(_carCodeNotGreen, { error: "车牌号格式错误" });
52
+ const _chinaProvince = /^安徽|澳门|北京|重庆|福建|甘肃|广东|广西|贵州|海南|河北|河南|黑龙江|湖北|湖南|吉林|江苏|江西|辽宁|内蒙古|宁夏|青海|山东|山西|陕西|上海|四川|台湾|天津|西藏|香港|新疆|云南|浙江$/;
53
+ /** 中国省份 */
54
+ export const chinaProvince = z.string().regex(_chinaProvince, { error: "应为中国省份" });
55
+ const _nation = /^汉族|蒙古族|回族|藏族|维吾尔族|苗族|彝族|壮族|布依族|朝鲜族|满族|侗族|瑶族|白族|土家族|哈尼族|哈萨克族|傣族|黎族|傈僳族|佤族|畲族|高山族|拉祜族|水族|东乡族|纳西族|景颇族|柯尔克孜族|土族|达斡尔族|仫佬族|羌族|布朗族|撒拉族|毛南族|仡佬族|锡伯族|阿昌族|普米族|塔吉克族|怒族|乌孜别克族|俄罗斯族|鄂温克族|德昂族|保安族|裕固族|京族|塔塔尔族|独龙族|鄂伦春族|赫哲族|门巴族|珞巴族|基诺族|其它未识别民族|外国人入中国籍$/;
56
+ /** 民族 */
57
+ export const nation = z.string().regex(_nation, { error: "应为民族" });
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "description": "pawover's kit",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "version": "0.0.0-alpha.6",
7
+ "version": "0.0.0-alpha.8",
8
8
  "packageManager": "pnpm@10.20.0",
9
9
  "engines": {
10
10
  "node": ">=22.20.0"
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "main": "./dist/index.js",
22
22
  "module": "./dist/index.js",
23
- "types": "dist/types/index.d.ts",
23
+ "types": "./dist/types/index.d.ts",
24
24
  "files": [
25
25
  "dist"
26
26
  ],
@@ -30,10 +30,11 @@
30
30
  "import": "./dist/index.js",
31
31
  "default": "./dist/index.js"
32
32
  },
33
- "./hooks/react/*": {
34
- "types": "./dist/types/hooks/react/*.d.ts",
35
- "import": "./dist/hooks/react/*.js",
36
- "default": "./dist/hooks/react/*.js"
33
+ "./*": {
34
+ "types": "./dist/types/*.d.ts",
35
+ "import": "./dist/*.js",
36
+ "default": "./dist/*.js",
37
+ "require": "./dist/*.js"
37
38
  }
38
39
  },
39
40
  "scripts": {
@@ -41,21 +42,21 @@
41
42
  "public": "pnpm build && npm publish --access public",
42
43
  "check": "pnpm check:types & pnpm check:eslint & pnpm check:format",
43
44
  "check:types": "tsc --noEmit",
44
- "check:eslint": "eslint --fix \"**/*.{js,cjs,mjs,ts,cts,mts,jsx,tsx,vue}\" --cache-location=eslint.cache.json --cache",
45
- "check:format": "prettier --write \"**/*.{html,json}\" !.vscode/settings.json --cache-location=prettier.cache.json --cache",
45
+ "check:eslint": "eslint --fix \"**/*.{js,cjs,mjs,ts,cts,mts,jsx,tsx,vue}\" --cache-location=.cache/eslint.cache.json --cache",
46
+ "check:format": "prettier --write \"**/*.{html,json}\" !.vscode/settings.json --cache-location=.cache/prettier.cache.json --cache",
46
47
  "check:pack": "attw --pack .",
47
48
  "clean": "pnpm clean:cache & pnpm clean:lib & pnpm clean:output",
48
- "clean:cache": "rimraf -g **/*.cache.json **/auto-*.json **/auto-*.d.ts",
49
+ "clean:cache": "rimraf -g **/.cache",
49
50
  "clean:lib": "rimraf -g **/node_modules",
50
51
  "clean:output": "rimraf dist",
51
52
  "lib:up": "taze -I -r --exclude pnpm"
52
53
  },
53
54
  "devDependencies": {
54
- "@pawover/eslint-rules": "0.0.0-alpha.3",
55
+ "@pawover/eslint-rules": "0.0.0-alpha.8",
55
56
  "@pawover/types": "0.0.0-alpha.6",
56
57
  "@stylistic/eslint-plugin": "^5.5.0",
57
58
  "@types/node": "^24.10.1",
58
- "@types/react": "^19.2.4",
59
+ "@types/react": "^19.2.5",
59
60
  "ahooks": "^3.9.6",
60
61
  "eslint": "^9.39.1",
61
62
  "eslint-plugin-antfu": "^3.1.1",
@@ -67,12 +68,14 @@
67
68
  "type-fest": "^5.2.0",
68
69
  "typescript": "^5.9.3",
69
70
  "typescript-eslint": "^8.46.4",
70
- "vue": "^3.5.24"
71
+ "vue": "^3.5.24",
72
+ "zod": "^4.1.12"
71
73
  },
72
74
  "peerDependencies": {
73
75
  "ahooks": ">=3.9.6",
74
76
  "react": ">=19.2.0",
75
- "vue": ">=3.5.24"
77
+ "vue": ">=3.5.24",
78
+ "zod": ">=4.1.12"
76
79
  },
77
80
  "peerDependenciesMeta": {
78
81
  "ahooks": {
@@ -83,6 +86,9 @@
83
86
  },
84
87
  "vue": {
85
88
  "optional": true
89
+ },
90
+ "zod": {
91
+ "optional": true
86
92
  }
87
93
  }
88
94
  }
package/dist/index.js DELETED
@@ -1,2 +0,0 @@
1
- export * from "./enums";
2
- export * from "./utils";
@@ -1,2 +0,0 @@
1
- export * from "./enums";
2
- export * from "./utils";