@opentiny/utils 1.0.0 → 3.22.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.
Files changed (92) hide show
  1. package/README.md +5 -1
  2. package/dist/after-leave/__tests__/index.test.d.ts +1 -0
  3. package/dist/after-leave/index.d.ts +25 -0
  4. package/dist/array/__tests__/index.test.d.ts +1 -0
  5. package/dist/array/index.d.ts +118 -0
  6. package/dist/bigInt/__tests__/index.test.d.ts +1 -0
  7. package/dist/bigInt/index.d.ts +249 -0
  8. package/dist/calendar/__test__/index.test.d.ts +1 -0
  9. package/dist/calendar/index.d.ts +96 -0
  10. package/dist/common/__tests__/index.test.d.ts +1 -0
  11. package/dist/common/index.d.ts +67 -0
  12. package/dist/crypt/__tests__/crypt.test.d.ts +1 -0
  13. package/dist/crypt/index.d.ts +5 -0
  14. package/dist/dataset/index.d.ts +102 -0
  15. package/dist/date/__test__/index.test.d.ts +1 -0
  16. package/dist/date/index.d.ts +95 -0
  17. package/dist/date-util/fecha.d.ts +14 -0
  18. package/dist/date-util/index.d.ts +50 -0
  19. package/dist/debounce/__tests__/debounce.test.d.ts +12 -0
  20. package/dist/debounce/index.d.ts +26 -0
  21. package/dist/decimal/__tests__/index.test.d.ts +1 -0
  22. package/dist/decimal/index.d.ts +92 -0
  23. package/dist/dom/index.d.ts +159 -0
  24. package/dist/espace-ctrl/index.d.ts +2 -0
  25. package/dist/event/index.d.ts +38 -0
  26. package/dist/fastdom/async.d.ts +12 -0
  27. package/dist/fastdom/index.d.ts +4 -0
  28. package/dist/fastdom/sandbox.d.ts +12 -0
  29. package/dist/fastdom/singleton.d.ts +10 -0
  30. package/dist/fecha/index.d.ts +13 -0
  31. package/dist/form/index.d.ts +5 -0
  32. package/dist/fullscreen/apis.d.ts +21 -0
  33. package/dist/fullscreen/index.d.ts +3 -0
  34. package/dist/fullscreen/screenfull.d.ts +22 -0
  35. package/dist/function/index.d.ts +7 -0
  36. package/dist/globalConfig/index.d.ts +20 -0
  37. package/dist/index.d.ts +43 -0
  38. package/dist/index.es.js +5333 -0
  39. package/dist/logger/index.d.ts +3 -0
  40. package/dist/memorize/index.d.ts +22 -0
  41. package/dist/nanoid/index.d.ts +11 -0
  42. package/dist/nanoid/nanoid.d.ts +4 -0
  43. package/dist/object/index.d.ts +137 -0
  44. package/dist/popup-manager/index.d.ts +42 -0
  45. package/dist/resize-event/index.d.ts +13 -0
  46. package/dist/resize-observer/index.d.ts +13 -0
  47. package/dist/scroll-into-view/index.d.ts +12 -0
  48. package/dist/scroll-width/index.d.ts +12 -0
  49. package/dist/string/index.d.ts +376 -0
  50. package/dist/throttle/index.d.ts +35 -0
  51. package/dist/touch/index.d.ts +15 -0
  52. package/dist/touch-emulator/index.d.ts +1 -0
  53. package/dist/tree-model/index.d.ts +3 -0
  54. package/dist/tree-model/node.d.ts +58 -0
  55. package/dist/tree-model/tree-store.d.ts +44 -0
  56. package/dist/tree-model/util.d.ts +14 -0
  57. package/dist/type/__tests__/type.test.d.ts +1 -0
  58. package/dist/type/index.d.ts +212 -0
  59. package/dist/upload-ajax/index.d.ts +12 -0
  60. package/dist/validate/__test__/util.test.d.ts +1 -0
  61. package/dist/validate/index.d.ts +2 -0
  62. package/dist/validate/messages.d.ts +72 -0
  63. package/dist/validate/rules/enum.d.ts +12 -0
  64. package/dist/validate/rules/index.d.ts +15 -0
  65. package/dist/validate/rules/pattern.d.ts +12 -0
  66. package/dist/validate/rules/range.d.ts +1 -0
  67. package/dist/validate/rules/required.d.ts +21 -0
  68. package/dist/validate/rules/type.d.ts +12 -0
  69. package/dist/validate/rules/whitespace.d.ts +12 -0
  70. package/dist/validate/schema.d.ts +22 -0
  71. package/dist/validate/util.d.ts +80 -0
  72. package/dist/validate/validations/__test__/date.test.d.ts +12 -0
  73. package/dist/validate/validations/__test__/integer.test.d.ts +12 -0
  74. package/dist/validate/validations/__test__/number.test.d.ts +12 -0
  75. package/dist/validate/validations/__test__/pattern.test.d.ts +1 -0
  76. package/dist/validate/validations/__test__/required.test.d.ts +1 -0
  77. package/dist/validate/validations/array.d.ts +30 -0
  78. package/dist/validate/validations/date.d.ts +29 -0
  79. package/dist/validate/validations/enum.d.ts +30 -0
  80. package/dist/validate/validations/float.d.ts +29 -0
  81. package/dist/validate/validations/index.d.ts +43 -0
  82. package/dist/validate/validations/integer.d.ts +34 -0
  83. package/dist/validate/validations/method.d.ts +33 -0
  84. package/dist/validate/validations/number.d.ts +30 -0
  85. package/dist/validate/validations/pattern.d.ts +31 -0
  86. package/dist/validate/validations/required.d.ts +24 -0
  87. package/dist/validate/validations/string.d.ts +32 -0
  88. package/dist/validate/validations/type.d.ts +28 -0
  89. package/dist/xss/__tests__/xss.test.d.ts +1 -0
  90. package/dist/xss/index.d.ts +16 -0
  91. package/package.json +11 -6
  92. package/dist/opentiny-utils.es.js +0 -1011
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Copyright (c) 2022 - present TinyVue Authors.
3
+ * Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license.
6
+ *
7
+ * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8
+ * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9
+ * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10
+ *
11
+ */
12
+ /**
13
+ * @description 警告函数(当前未实现)
14
+ * @returns undefined
15
+ */
16
+ export declare const warning: () => undefined;
17
+ /**
18
+ * @description 转换返回错误的数据结构,将错误数组转换为按字段分组的对象
19
+ * @param errors 错误数组
20
+ * @returns 按字段分组的错误对象或null
21
+ */
22
+ export declare function convertFieldsError(errors: Array<{
23
+ field: string;
24
+ [key: string]: any;
25
+ }> | null | undefined): Record<string, any[]> | null;
26
+ /**
27
+ * @description 生成校验错误的提示信息,支持格式化占位符
28
+ * @param i18nTemplate 带占位符的字符串或函数
29
+ * @param rest 替换占位符的字符串参数
30
+ * @returns 格式化后的字符串
31
+ * 例:format('%s 必须等于 %s', 'A', 'B') 返回 A 必须等于 B
32
+ */
33
+ export declare function format(i18nTemplate: Function | string, ...rest: string[]): string;
34
+ /**
35
+ * @description 判断对应的类型是否是空值
36
+ * @param data 要检查的数据
37
+ * @param dataType 数据类型
38
+ * @returns 是否为空值
39
+ */
40
+ export declare function isEmptyValue(data: any, dataType?: string): boolean;
41
+ /**
42
+ * @description 判断对象是否为空
43
+ * @param data 要检查的对象
44
+ * @returns 对象是否为空
45
+ */
46
+ export declare function isEmptyObject(data: Record<string, any>): boolean;
47
+ /**
48
+ * @description 异步映射处理对象数组,支持串行或并行处理
49
+ * @param objArray 对象数组
50
+ * @param option 选项配置
51
+ * @param func 处理函数
52
+ * @param callback 完成回调
53
+ * @returns Promise对象
54
+ */
55
+ export declare function asyncMap(objArray: Record<string, any[]>, option: {
56
+ first?: boolean;
57
+ firstFields?: boolean | string[];
58
+ }, func: (rule: any, callback: (errors: any[]) => void) => void, callback: (errors: any[]) => void): Promise<void>;
59
+ /**
60
+ * @description 处理返回的错误,补充错误信息
61
+ * @param rule 规则对象
62
+ * @returns 处理函数
63
+ */
64
+ export declare function complementError(rule: {
65
+ fullField?: string;
66
+ [key: string]: any;
67
+ }): (onError: string | Function | {
68
+ message?: string;
69
+ field?: string;
70
+ }) => {
71
+ message: string;
72
+ field: string;
73
+ };
74
+ /**
75
+ * @description 深度合并对象
76
+ * @param target 目标对象
77
+ * @param sources 源对象
78
+ * @returns 合并后的对象
79
+ */
80
+ export declare function deepMerge(target: Record<string, any>, sources: Record<string, any>): Record<string, any>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) 2022 - present TinyVue Authors.
3
+ * Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license.
6
+ *
7
+ * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8
+ * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9
+ * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10
+ *
11
+ */
12
+ export {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) 2022 - present TinyVue Authors.
3
+ * Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license.
6
+ *
7
+ * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8
+ * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9
+ * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10
+ *
11
+ */
12
+ export {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) 2022 - present TinyVue Authors.
3
+ * Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license.
6
+ *
7
+ * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8
+ * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9
+ * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10
+ *
11
+ */
12
+ export {};
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Copyright (c) 2022 - present TinyVue Authors.
3
+ * Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license.
6
+ *
7
+ * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8
+ * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9
+ * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10
+ *
11
+ */
12
+ /**
13
+ * 数组验证函数
14
+ *
15
+ * @description 验证目标值是否符合数组规则要求,支持必填验证、类型验证和范围验证
16
+ * @param rule - 验证规则对象,包含验证条件
17
+ * @param checkValue - 需要验证的值
18
+ * @param callback - 验证完成后的回调函数
19
+ * @param source - 验证源对象,包含所有需要验证的字段
20
+ * @param options - 验证选项配置
21
+ * @returns void
22
+ */
23
+ export default function arrayValidation(rule: {
24
+ required?: boolean;
25
+ field: string;
26
+ type?: string;
27
+ min?: number;
28
+ max?: number;
29
+ [key: string]: any;
30
+ }, checkValue: any, callback: (errors?: any[]) => void, source: Record<string, any>, options: Record<string, any>): void;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Copyright (c) 2022 - present TinyVue Authors.
3
+ * Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license.
6
+ *
7
+ * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8
+ * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9
+ * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10
+ *
11
+ */
12
+ /**
13
+ * 日期验证函数
14
+ *
15
+ * @description 验证字段值是否为有效的日期格式,支持日期对象和日期字符串
16
+ * @param rule - 验证规则对象
17
+ * @param checkValue - 待验证的值
18
+ * @param callback - 验证完成后的回调函数
19
+ * @param source - 包含所有字段的源对象
20
+ * @param options - 验证选项
21
+ */
22
+ export default function dateValidator(rule: {
23
+ required?: boolean;
24
+ field: string;
25
+ type?: string;
26
+ min?: number;
27
+ max?: number;
28
+ [key: string]: any;
29
+ }, checkValue: any, callback: (errors?: any[]) => void, source: Record<string, any>, options: Record<string, any>): void;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Copyright (c) 2022 - present TinyVue Authors.
3
+ * Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license.
6
+ *
7
+ * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8
+ * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9
+ * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10
+ *
11
+ */
12
+ /**
13
+ * 枚举验证函数
14
+ *
15
+ * @description 验证值是否在指定的枚举范围内
16
+ * @param rule - 验证规则对象,包含验证的字段和验证选项
17
+ * @param checkValue - 需要验证的值
18
+ * @param callback - 回调函数,用于返回验证结果
19
+ * @param source - 数据源对象
20
+ * @param options - 验证选项
21
+ */
22
+ export default function (rule: {
23
+ field: string;
24
+ required?: boolean;
25
+ enum?: any[];
26
+ [key: string]: any;
27
+ }, checkValue: any, callback: (errors?: any[]) => void, source: Record<string, any>, options: {
28
+ messages: Record<string, any>;
29
+ [key: string]: any;
30
+ }): void;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Copyright (c) 2022 - present TinyVue Authors.
3
+ * Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license.
6
+ *
7
+ * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8
+ * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9
+ * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10
+ *
11
+ */
12
+ /**
13
+ * 浮点数验证函数
14
+ *
15
+ * @description 验证字段是否为有效的浮点数,并检查其范围
16
+ * @param rule 验证规则对象,包含验证条件如required、type和范围限制
17
+ * @param checkValue 需要验证的值
18
+ * @param cb 回调函数,用于返回验证结果
19
+ * @param source 包含所有字段的源对象
20
+ * @param options 验证选项
21
+ */
22
+ export default function float(rule: {
23
+ required?: boolean;
24
+ field: string;
25
+ type?: string;
26
+ min?: number;
27
+ max?: number;
28
+ [key: string]: any;
29
+ }, checkValue: any, cb: (errors?: any[]) => void, source: Record<string, any>, options?: Record<string, any>): void;
@@ -0,0 +1,43 @@
1
+ import { default as date } from './date';
2
+ import { default as type } from './type';
3
+ import { default as float } from './float';
4
+ import { default as array } from './array';
5
+ import { default as string } from './string';
6
+ import { default as method } from './method';
7
+ import { default as number } from './number';
8
+ import { default as integer } from './integer';
9
+ import { default as pattern } from './pattern';
10
+ import { default as required } from './required';
11
+ import { default as enumValidator } from './enum';
12
+ declare const _default: {
13
+ date: typeof date;
14
+ float: typeof float;
15
+ array: typeof array;
16
+ string: typeof string;
17
+ method: typeof method;
18
+ number: typeof number;
19
+ integer: typeof integer;
20
+ pattern: typeof pattern;
21
+ required: typeof required;
22
+ hex: typeof type;
23
+ url: typeof type;
24
+ time: typeof type;
25
+ email: typeof type;
26
+ digits: typeof type;
27
+ dateYM: typeof type;
28
+ speczh: typeof type;
29
+ dateYMD: typeof type;
30
+ version: typeof type;
31
+ fileSize: typeof type;
32
+ regexp: typeof method;
33
+ object: typeof method;
34
+ dateTime: typeof type;
35
+ specialch: typeof type;
36
+ boolean: typeof method;
37
+ acceptImg: typeof type;
38
+ specialch2: typeof type;
39
+ acceptFile: typeof type;
40
+ longDateTime: typeof type;
41
+ enum: typeof enumValidator;
42
+ };
43
+ export default _default;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Copyright (c) 2022 - present TinyVue Authors.
3
+ * Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license.
6
+ *
7
+ * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8
+ * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9
+ * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10
+ *
11
+ */
12
+ /**
13
+ * 整数验证函数,用于验证输入值是否符合整数规则
14
+ *
15
+ * @param rule - 验证规则对象,包含验证所需的各种属性
16
+ * @param checkValue - 待验证的值
17
+ * @param callback - 回调函数,用于返回验证结果
18
+ * @param source - 包含所有字段值的源对象
19
+ * @param options - 验证选项
20
+ *
21
+ * 验证流程:
22
+ * 1. 如果字段未提供且非必填,则验证通过
23
+ * 2. 检查是否满足必填规则
24
+ * 3. 检查值的类型是否为整数
25
+ * 4. 检查值是否在指定范围内
26
+ */
27
+ export default function (rule: {
28
+ required?: boolean;
29
+ field: string;
30
+ type?: string;
31
+ min?: number;
32
+ max?: number;
33
+ [key: string]: any;
34
+ }, checkValue: any, callback: (errors?: any[]) => void, source: Record<string, any>, options: Record<string, any>): void;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Copyright (c) 2022 - present TinyVue Authors.
3
+ * Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license.
6
+ *
7
+ * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8
+ * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9
+ * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10
+ *
11
+ */
12
+ interface ValidationRule {
13
+ required?: boolean;
14
+ field: string;
15
+ type?: string;
16
+ }
17
+ interface ValidationSource {
18
+ [key: string]: any;
19
+ }
20
+ interface ValidationOptions {
21
+ [key: string]: any;
22
+ }
23
+ type ValidationCallback = (errors: string[]) => void;
24
+ /**
25
+ * 验证方法的主函数
26
+ * @param rule - 验证规则对象
27
+ * @param checkValue - 需要验证的值
28
+ * @param callback - 验证完成后的回调函数
29
+ * @param source - 包含所有字段值的源对象
30
+ * @param options - 验证选项
31
+ */
32
+ export default function validate(rule: ValidationRule, checkValue: any, callback: ValidationCallback, source: ValidationSource, options: ValidationOptions): void;
33
+ export {};
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Copyright (c) 2022 - present TinyVue Authors.
3
+ * Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license.
6
+ *
7
+ * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8
+ * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9
+ * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10
+ *
11
+ */
12
+ /**
13
+ * 数字类型验证函数
14
+ *
15
+ * @description 用于验证数字类型字段是否符合规则,包括必填、类型和范围验证
16
+ * @param rule - 验证规则对象
17
+ * @param checkValue - 需要验证的值
18
+ * @param callback - 验证完成后的回调函数,传入错误数组
19
+ * @param source - 包含所有字段的源对象
20
+ * @param options - 验证选项
21
+ * @returns void
22
+ */
23
+ export default function (rule: {
24
+ required?: boolean;
25
+ field: string;
26
+ type?: string;
27
+ min?: number;
28
+ max?: number;
29
+ [key: string]: any;
30
+ }, checkValue: any, callback: (errors?: any[]) => void, source: Record<string, any>, options?: Record<string, any>): void;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Copyright (c) 2022 - present TinyVue Authors.
3
+ * Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license.
6
+ *
7
+ * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8
+ * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9
+ * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10
+ *
11
+ */
12
+ /**
13
+ * 模式校验函数
14
+ *
15
+ * @description 根据规则验证值是否匹配指定的模式(正则表达式)
16
+ * @param rule 校验规则对象,包含校验字段和条件
17
+ * @param checkValue 需要校验的值
18
+ * @param callback 校验完成后的回调函数
19
+ * @param source 包含校验字段的源对象
20
+ * @param options 校验选项
21
+ * @returns void
22
+ */
23
+ export default function pattern(rule: {
24
+ field: string;
25
+ required?: boolean;
26
+ pattern?: RegExp | string;
27
+ [key: string]: any;
28
+ }, checkValue: any, callback: (errors?: any[]) => void, source: Record<string, any>, options: {
29
+ messages: Record<string, any>;
30
+ [key: string]: any;
31
+ }): void;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copyright (c) 2022 - present TinyVue Authors.
3
+ * Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license.
6
+ *
7
+ * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8
+ * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9
+ * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10
+ *
11
+ */
12
+ /**
13
+ * 必填验证函数
14
+ *
15
+ * 检查字段是否满足必填要求。根据值的类型(数组或其他类型)应用相应的验证规则,
16
+ * 并将验证结果通过回调函数返回。
17
+ *
18
+ * @param rule - 验证规则对象
19
+ * @param checkValue - 需要验证的值
20
+ * @param callback - 回调函数,用于返回验证错误
21
+ * @param source - 包含所有字段的源对象
22
+ * @param options - 验证选项,包括错误消息等配置
23
+ */
24
+ export default function (rule: Record<string, any>, checkValue: any, callback: (errors: any[]) => void, source: Record<string, any>, options: Record<string, any>): void;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Copyright (c) 2022 - present TinyVue Authors.
3
+ * Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license.
6
+ *
7
+ * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8
+ * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9
+ * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10
+ *
11
+ */
12
+ /**
13
+ * 字符串验证函数
14
+ *
15
+ * @description 根据规则验证字符串类型的值是否合法,支持必填验证、类型验证、范围验证、模式匹配和空白字符验证
16
+ * @param rule - 验证规则对象,包含验证条件
17
+ * @param checkValue - 需要验证的值
18
+ * @param callback - 验证完成后的回调函数
19
+ * @param source - 验证源对象,包含所有需要验证的字段
20
+ * @param options - 验证选项配置
21
+ * @returns void
22
+ */
23
+ export default function stringValidation(rule: {
24
+ required?: boolean;
25
+ field: string;
26
+ type?: string;
27
+ pattern?: RegExp | string;
28
+ whitespace?: boolean;
29
+ min?: number;
30
+ max?: number;
31
+ [key: string]: any;
32
+ }, checkValue: any, callback: (errors?: any[]) => void, source: Record<string, any>, options: Record<string, any>): void;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Copyright (c) 2022 - present TinyVue Authors.
3
+ * Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license.
6
+ *
7
+ * THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
8
+ * BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
9
+ * A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
10
+ *
11
+ */
12
+ /**
13
+ * 类型验证函数
14
+ *
15
+ * 根据规则验证数据类型,如果数据为空且非必填则直接通过,否则进行类型校验
16
+ *
17
+ * @param rule - 验证规则对象,包含类型、是否必填等信息
18
+ * @param checkValue - 需要验证的值
19
+ * @param callback - 回调函数,用于返回验证结果
20
+ * @param source - 源数据对象
21
+ * @param options - 验证选项配置
22
+ */
23
+ export default function (rule: {
24
+ type: string;
25
+ required?: boolean;
26
+ field: string;
27
+ [key: string]: any;
28
+ }, checkValue: any, callback: (errors?: any[]) => void, source: Record<string, any>, options: Record<string, any>): void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ export declare const getXssOption: () => object;
2
+ export declare const setXssOption: (option: any) => void;
3
+ export declare const setFilterHtml: (filter: (content: string) => string) => void;
4
+ export declare const setFilterAttrs: (filter: (content: string) => string) => void;
5
+ export declare const setFilterUrl: (filter: (content: any) => any) => void;
6
+ declare const _default: {
7
+ getXssOption: () => object;
8
+ setXssOption: (option: any) => void;
9
+ filterHtml: (content: string) => string;
10
+ setFilterHtml: (filter: (content: string) => string) => void;
11
+ filterAttrs: (content: string) => string;
12
+ setFilterAttrs: (filter: (content: string) => string) => void;
13
+ filterUrl: (content: string) => string;
14
+ setFilterUrl: (filter: (content: any) => any) => void;
15
+ };
16
+ export default _default;
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@opentiny/utils",
3
- "version": "1.0.0",
3
+ "type": "module",
4
+ "version": "3.22.0",
4
5
  "description": "nanoid console xss",
5
6
  "author": "",
6
7
  "license": "ISC",
@@ -8,7 +9,7 @@
8
9
  "type": "git",
9
10
  "url": "git@github.com:opentiny/tiny-vue.git"
10
11
  },
11
- "main": "dist/opentiny-utils.es.js",
12
+ "main": "dist/index.es.js",
12
13
  "files": [
13
14
  "dist"
14
15
  ],
@@ -16,11 +17,15 @@
16
17
  "xss": "1.0.14"
17
18
  },
18
19
  "devDependencies": {
19
- "typescript": "^5.2.2",
20
- "vite": "^6.0.0"
20
+ "typescript": "~5.3.3",
21
+ "vite": "^6.0.0",
22
+ "vite-plugin-dts": "~4.3.0",
23
+ "vitest": "^3.0.8"
21
24
  },
22
25
  "scripts": {
23
26
  "build": "vite build",
24
- "pub": "pnpm publish --no-git-checks --access=public"
25
- }
27
+ "pub": "pnpm publish --no-git-checks --access=public",
28
+ "test": "vitest"
29
+ },
30
+ "types": "dist/index.d.ts"
26
31
  }