@tiny-codes/react-easy 1.1.1 → 1.1.3
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/CHANGELOG.md +18 -0
- package/es/components/BreakLines/index.d.ts +13 -19
- package/es/components/BreakLines/index.js +2 -3
- package/es/components/BreakLines/index.js.map +1 -1
- package/es/components/ConfigProvider/context.d.ts +20 -26
- package/es/components/ConfigProvider/context.js.map +1 -1
- package/es/components/ConfigProvider/index.d.ts +5 -7
- package/es/components/ConfigProvider/index.js +2 -3
- package/es/components/ConfigProvider/index.js.map +1 -1
- package/es/components/ConfirmAction/index.d.ts +58 -89
- package/es/components/ConfirmAction/index.js +12 -18
- package/es/components/ConfirmAction/index.js.map +1 -1
- package/es/components/DeleteConfirmAction/index.d.ts +2 -3
- package/es/components/DeleteConfirmAction/index.js +8 -12
- package/es/components/DeleteConfirmAction/index.js.map +1 -1
- package/es/components/EditableText/form.d.ts +144 -0
- package/es/components/EditableText/form.js +309 -0
- package/es/components/EditableText/form.js.map +1 -0
- package/es/components/EditableText/index.d.ts +138 -0
- package/es/components/EditableText/index.js +216 -0
- package/es/components/EditableText/index.js.map +1 -0
- package/es/components/EditableText/style/index.d.ts +3 -0
- package/es/components/EditableText/style/index.js +76 -0
- package/es/components/EditableText/style/index.js.map +1 -0
- package/es/components/FloatDrawer/index.d.ts +89 -86
- package/es/components/FloatDrawer/index.js +43 -20
- package/es/components/FloatDrawer/index.js.map +1 -1
- package/es/components/FloatDrawer/style/index.js +42 -23
- package/es/components/FloatDrawer/style/index.js.map +1 -1
- package/es/components/Loading/index.d.ts +66 -0
- package/es/components/Loading/index.js +97 -0
- package/es/components/Loading/index.js.map +1 -0
- package/es/components/Loading/style/index.d.ts +3 -0
- package/es/components/Loading/style/index.js +27 -0
- package/es/components/Loading/style/index.js.map +1 -0
- package/es/components/ModalAction/index.d.ts +98 -139
- package/es/components/ModalAction/index.js +25 -37
- package/es/components/ModalAction/index.js.map +1 -1
- package/es/components/OverflowTags/index.d.ts +30 -8
- package/es/components/OverflowTags/index.js +26 -7
- package/es/components/OverflowTags/index.js.map +1 -1
- package/es/components/OverflowTags/style/index.js +1 -3
- package/es/components/OverflowTags/style/index.js.map +1 -1
- package/es/components/index.d.ts +4 -0
- package/es/components/index.js +2 -0
- package/es/components/index.js.map +1 -1
- package/es/hooks/useRefFunction.d.ts +4 -5
- package/es/hooks/useRefFunction.js +6 -7
- package/es/hooks/useRefFunction.js.map +1 -1
- package/es/hooks/useRefValue.d.ts +2 -3
- package/es/hooks/useRefValue.js +2 -3
- package/es/hooks/useRefValue.js.map +1 -1
- package/es/hooks/useT.js +1 -2
- package/es/hooks/useT.js.map +1 -1
- package/es/hooks/useValidator.d.ts +2 -3
- package/es/hooks/useValidator.js +2 -3
- package/es/hooks/useValidator.js.map +1 -1
- package/es/hooks/useValidatorBuilder.d.ts +41 -61
- package/es/hooks/useValidatorBuilder.js +4 -6
- package/es/hooks/useValidatorBuilder.js.map +1 -1
- package/es/hooks/useValidators.d.ts +62 -83
- package/es/hooks/useValidators.js +3 -4
- package/es/hooks/useValidators.js.map +1 -1
- package/es/locales/index.d.ts +15 -0
- package/es/locales/langs/en-US.d.ts +5 -0
- package/es/locales/langs/en-US.js +5 -0
- package/es/locales/langs/en-US.js.map +1 -1
- package/es/locales/langs/zh-CN.d.ts +5 -0
- package/es/locales/langs/zh-CN.js +5 -0
- package/es/locales/langs/zh-CN.js.map +1 -1
- package/lib/components/BreakLines/index.d.ts +13 -19
- package/lib/components/BreakLines/index.js.map +2 -2
- package/lib/components/ConfigProvider/context.d.ts +20 -26
- package/lib/components/ConfigProvider/context.js.map +2 -2
- package/lib/components/ConfigProvider/index.d.ts +5 -7
- package/lib/components/ConfigProvider/index.js.map +2 -2
- package/lib/components/ConfirmAction/index.d.ts +58 -89
- package/lib/components/ConfirmAction/index.js.map +2 -2
- package/lib/components/DeleteConfirmAction/index.d.ts +2 -3
- package/lib/components/DeleteConfirmAction/index.js.map +2 -2
- package/lib/components/EditableText/form.d.ts +144 -0
- package/lib/components/EditableText/form.js +223 -0
- package/lib/components/EditableText/form.js.map +7 -0
- package/lib/components/EditableText/index.d.ts +138 -0
- package/lib/components/EditableText/index.js +174 -0
- package/lib/components/EditableText/index.js.map +7 -0
- package/lib/components/EditableText/style/index.d.ts +3 -0
- package/lib/components/EditableText/style/index.js +118 -0
- package/lib/components/EditableText/style/index.js.map +7 -0
- package/lib/components/FloatDrawer/index.d.ts +89 -86
- package/lib/components/FloatDrawer/index.js +64 -39
- package/lib/components/FloatDrawer/index.js.map +2 -2
- package/lib/components/FloatDrawer/style/index.js +60 -23
- package/lib/components/FloatDrawer/style/index.js.map +2 -2
- package/lib/components/Loading/index.d.ts +66 -0
- package/lib/components/Loading/index.js +81 -0
- package/lib/components/Loading/index.js.map +7 -0
- package/lib/components/Loading/style/index.d.ts +3 -0
- package/lib/components/Loading/style/index.js +50 -0
- package/lib/components/Loading/style/index.js.map +7 -0
- package/lib/components/ModalAction/index.d.ts +98 -139
- package/lib/components/ModalAction/index.js.map +2 -2
- package/lib/components/OverflowTags/index.d.ts +30 -8
- package/lib/components/OverflowTags/index.js +7 -5
- package/lib/components/OverflowTags/index.js.map +2 -2
- package/lib/components/OverflowTags/style/index.js +1 -1
- package/lib/components/OverflowTags/style/index.js.map +2 -2
- package/lib/components/index.d.ts +4 -0
- package/lib/components/index.js +6 -0
- package/lib/components/index.js.map +2 -2
- package/lib/hooks/useRefFunction.d.ts +4 -5
- package/lib/hooks/useRefFunction.js.map +2 -2
- package/lib/hooks/useRefValue.d.ts +2 -3
- package/lib/hooks/useRefValue.js.map +2 -2
- package/lib/hooks/useT.js.map +2 -2
- package/lib/hooks/useValidator.d.ts +2 -3
- package/lib/hooks/useValidator.js.map +2 -2
- package/lib/hooks/useValidatorBuilder.d.ts +41 -61
- package/lib/hooks/useValidatorBuilder.js.map +2 -2
- package/lib/hooks/useValidators.d.ts +62 -83
- package/lib/hooks/useValidators.js.map +2 -2
- package/lib/locales/index.d.ts +15 -0
- package/lib/locales/langs/en-US.d.ts +5 -0
- package/lib/locales/langs/en-US.js +5 -0
- package/lib/locales/langs/en-US.js.map +2 -2
- package/lib/locales/langs/zh-CN.d.ts +5 -0
- package/lib/locales/langs/zh-CN.js +5 -0
- package/lib/locales/langs/zh-CN.js.map +2 -2
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useCallback","useRef","useRefFunction","fn","ref","current","_ref$current","_len","arguments","length","args","Array","_key","call","apply","concat"],"sources":["../../src/hooks/useRefFunction.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\n\n/**\n * **EN:** Generate an immutable function reference, the dependencies inside the function will be\n *
|
|
1
|
+
{"version":3,"names":["useCallback","useRef","useRefFunction","fn","ref","current","_ref$current","_len","arguments","length","args","Array","_key","call","apply","concat"],"sources":["../../src/hooks/useRefFunction.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\n\n/**\n * - **EN:** Generate an immutable function reference, the dependencies inside the function will be\n * updated in real time, but the function itself will not change, which is very useful when used\n * as a dependency of `useEffect`.\n * - **CN:** 生成一个引用不可变的函数,函数内部的依赖项会保持实时更新,但函数本身不会变化,在作为 `useEffect` 的依赖时非常有用\n *\n * @param fn Function body | 函数体\n *\n * @returns An function with immutable reference | 引用不可变的函数\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst useRefFunction = <T extends (...args: any[]) => any>(fn: T | undefined) => {\n const ref = useRef<T | undefined>(fn);\n ref.current = fn;\n\n // eslint-disable-next-line @tiny-codes/react-hooks/exhaustive-deps\n return useCallback(((...args: any[]) => ref.current?.(...args)) as T, []);\n};\n\nexport default useRefFunction;\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,MAAM,QAAQ,OAAO;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CAAuCC,EAAiB,EAAK;EAC/E,IAAMC,GAAG,GAAGH,MAAM,CAAgBE,EAAE,CAAC;EACrCC,GAAG,CAACC,OAAO,GAAGF,EAAE;;EAEhB;EACA,OAAOH,WAAW,CAAE;IAAA,IAAAM,YAAA;IAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAIC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAJF,IAAI,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;IAAA;IAAA,QAAAN,YAAA,GAAYF,GAAG,CAACC,OAAO,cAAAC,YAAA,uBAAXA,YAAA,CAAAO,IAAA,CAAAC,KAAA,CAAAR,YAAA,GAAAF,GAAG,EAAAW,MAAA,CAAcL,IAAI,EAAC;EAAA,GAAQ,EAAE,CAAC;AAC3E,CAAC;AAED,eAAeR,cAAc"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
/**
|
|
3
|
-
* **EN:** Get a mutable ref object and automatically update the value change
|
|
4
|
-
*
|
|
5
|
-
* **CN:** 获取一个可变的ref对象,并自动更新值变化
|
|
3
|
+
* - **EN:** Get a mutable ref object and automatically update the value change
|
|
4
|
+
* - **CN:** 获取一个可变的ref对象,并自动更新值变化
|
|
6
5
|
*
|
|
7
6
|
* @param value the wrapped value | 被包装的值
|
|
8
7
|
*
|
package/es/hooks/useRefValue.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { useRef } from 'react';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* **EN:** Get a mutable ref object and automatically update the value change
|
|
5
|
-
*
|
|
6
|
-
* **CN:** 获取一个可变的ref对象,并自动更新值变化
|
|
4
|
+
* - **EN:** Get a mutable ref object and automatically update the value change
|
|
5
|
+
* - **CN:** 获取一个可变的ref对象,并自动更新值变化
|
|
7
6
|
*
|
|
8
7
|
* @param value the wrapped value | 被包装的值
|
|
9
8
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useRef","useRefValue","value","ref","current"],"sources":["../../src/hooks/useRefValue.ts"],"sourcesContent":["import { useRef } from 'react';\n\n/**\n * **EN:** Get a mutable ref object and automatically update the value change\n
|
|
1
|
+
{"version":3,"names":["useRef","useRefValue","value","ref","current"],"sources":["../../src/hooks/useRefValue.ts"],"sourcesContent":["import { useRef } from 'react';\n\n/**\n * - **EN:** Get a mutable ref object and automatically update the value change\n * - **CN:** 获取一个可变的ref对象,并自动更新值变化\n *\n * @param value the wrapped value | 被包装的值\n *\n * @returns A mutable ref object, but the reference is immutable | 可变的ref对象,但引用不可变\n */\nconst useRefValue = <T>(value: T) => {\n const ref = useRef<T>(value);\n ref.current = value;\n return ref;\n};\n\nexport default useRefValue;\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,OAAO;;AAE9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,WAAW,GAAG,SAAdA,WAAWA,CAAOC,KAAQ,EAAK;EACnC,IAAMC,GAAG,GAAGH,MAAM,CAAIE,KAAK,CAAC;EAC5BC,GAAG,CAACC,OAAO,GAAGF,KAAK;EACnB,OAAOC,GAAG;AACZ,CAAC;AAED,eAAeF,WAAW"}
|
package/es/hooks/useT.js
CHANGED
|
@@ -5,8 +5,7 @@ var useT = function useT() {
|
|
|
5
5
|
var context = useContext(ReactEasyContext);
|
|
6
6
|
var lang = context.lang;
|
|
7
7
|
|
|
8
|
-
// eslint-disable-next-line
|
|
9
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
8
|
+
// eslint-disable-next-line @tiny-codes/react-hooks/exhaustive-deps
|
|
10
9
|
return useMemo(function () {
|
|
11
10
|
return t;
|
|
12
11
|
}, [lang]);
|
package/es/hooks/useT.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useContext","useMemo","ReactEasyContext","t","useT","context","lang"],"sources":["../../src/hooks/useT.ts"],"sourcesContent":["import { useContext, useMemo } from 'react';\nimport ReactEasyContext from '../components/ConfigProvider/context';\nimport { t } from '../locales';\n\nconst useT = (): typeof t => {\n const context = useContext(ReactEasyContext);\n const lang = context.lang;\n\n // eslint-disable-next-line
|
|
1
|
+
{"version":3,"names":["useContext","useMemo","ReactEasyContext","t","useT","context","lang"],"sources":["../../src/hooks/useT.ts"],"sourcesContent":["import { useContext, useMemo } from 'react';\nimport ReactEasyContext from '../components/ConfigProvider/context';\nimport { t } from '../locales';\n\nconst useT = (): typeof t => {\n const context = useContext(ReactEasyContext);\n const lang = context.lang;\n\n // eslint-disable-next-line @tiny-codes/react-hooks/exhaustive-deps\n return useMemo(() => t, [lang]);\n};\n\nexport default useT;\n"],"mappings":"AAAA,SAASA,UAAU,EAAEC,OAAO,QAAQ,OAAO;AAC3C,OAAOC,gBAAgB;AACvB,SAASC,CAAC;AAEV,IAAMC,IAAI,GAAG,SAAPA,IAAIA,CAAA,EAAmB;EAC3B,IAAMC,OAAO,GAAGL,UAAU,CAACE,gBAAgB,CAAC;EAC5C,IAAMI,IAAI,GAAGD,OAAO,CAACC,IAAI;;EAEzB;EACA,OAAOL,OAAO,CAAC;IAAA,OAAME,CAAC;EAAA,GAAE,CAACG,IAAI,CAAC,CAAC;AACjC,CAAC;AAED,eAAeF,IAAI"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { BuilderOptions } from './useValidatorBuilder';
|
|
2
2
|
/**
|
|
3
|
-
* **EN:** Dynamically generate a validation rule, compatible with ant-design rules
|
|
4
|
-
*
|
|
5
|
-
* **CN:** 动态生成一个校验规则,与 ant-design 的规则兼容
|
|
3
|
+
* - **EN:** Dynamically generate a validation rule, compatible with ant-design rules
|
|
4
|
+
* - **CN:** 动态生成一个校验规则,与 ant-design 的规则兼容
|
|
6
5
|
*/
|
|
7
6
|
declare const useValidator: (props: BuilderOptions) => import("./useValidatorBuilder").ValidatorRule;
|
|
8
7
|
export default useValidator;
|
package/es/hooks/useValidator.js
CHANGED
|
@@ -2,9 +2,8 @@ import { useMemo } from 'react';
|
|
|
2
2
|
import useValidatorBuilder from "./useValidatorBuilder";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* **EN:** Dynamically generate a validation rule, compatible with ant-design rules
|
|
6
|
-
*
|
|
7
|
-
* **CN:** 动态生成一个校验规则,与 ant-design 的规则兼容
|
|
5
|
+
* - **EN:** Dynamically generate a validation rule, compatible with ant-design rules
|
|
6
|
+
* - **CN:** 动态生成一个校验规则,与 ant-design 的规则兼容
|
|
8
7
|
*/
|
|
9
8
|
var useValidator = function useValidator(props) {
|
|
10
9
|
var builder = useValidatorBuilder();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMemo","useValidatorBuilder","useValidator","props","builder"],"sources":["../../src/hooks/useValidator.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type { BuilderOptions } from './useValidatorBuilder';\nimport useValidatorBuilder from './useValidatorBuilder';\n\n/**\n * **EN:** Dynamically generate a validation rule, compatible with ant-design rules\n
|
|
1
|
+
{"version":3,"names":["useMemo","useValidatorBuilder","useValidator","props","builder"],"sources":["../../src/hooks/useValidator.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type { BuilderOptions } from './useValidatorBuilder';\nimport useValidatorBuilder from './useValidatorBuilder';\n\n/**\n * - **EN:** Dynamically generate a validation rule, compatible with ant-design rules\n * - **CN:** 动态生成一个校验规则,与 ant-design 的规则兼容\n */\nconst useValidator = (props: BuilderOptions) => {\n const builder = useValidatorBuilder();\n return useMemo(() => builder(props), [builder, props]);\n};\n\nexport default useValidator;\n"],"mappings":"AAAA,SAASA,OAAO,QAAQ,OAAO;AAE/B,OAAOC,mBAAmB;;AAE1B;AACA;AACA;AACA;AACA,IAAMC,YAAY,GAAG,SAAfA,YAAYA,CAAIC,KAAqB,EAAK;EAC9C,IAAMC,OAAO,GAAGH,mBAAmB,CAAC,CAAC;EACrC,OAAOD,OAAO,CAAC;IAAA,OAAMI,OAAO,CAACD,KAAK,CAAC;EAAA,GAAE,CAACC,OAAO,EAAED,KAAK,CAAC,CAAC;AACxD,CAAC;AAED,eAAeD,YAAY"}
|
|
@@ -1,132 +1,112 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* **EN:** Get a validation rule builder to build validation rules
|
|
3
|
-
*
|
|
4
|
-
* **CN:** 获取一个校验规则生成器,用来构建校验规则
|
|
2
|
+
* - **EN:** Get a validation rule builder to build validation rules
|
|
3
|
+
* - **CN:** 获取一个校验规则生成器,用来构建校验规则
|
|
5
4
|
*/
|
|
6
5
|
declare const useValidatorBuilder: () => (props: BuilderOptions) => ValidatorRule;
|
|
7
6
|
export interface BuilderOptions {
|
|
8
7
|
/**
|
|
9
|
-
* **EN:** The rule of allowed characters
|
|
10
|
-
*
|
|
11
|
-
* **CN:** 允许字符的规则
|
|
8
|
+
* - **EN:** The rule of allowed characters
|
|
9
|
+
* - **CN:** 允许字符的规则
|
|
12
10
|
*/
|
|
13
11
|
allowed: RuleRegExpFlags;
|
|
14
12
|
/**
|
|
15
|
-
* **EN:** The rule of the starting character
|
|
16
|
-
*
|
|
17
|
-
* **CN:** 开头字符的规则
|
|
13
|
+
* - **EN:** The rule of the starting character
|
|
14
|
+
* - **CN:** 开头字符的规则
|
|
18
15
|
*/
|
|
19
16
|
startsWith?: Omit<RuleRegExpFlags, 'min' | 'max'>;
|
|
20
17
|
/**
|
|
21
|
-
* **EN:** Regular expression flags
|
|
22
|
-
*
|
|
23
|
-
* **CN:** 正则表达式的标志
|
|
18
|
+
* - **EN:** Regular expression flags
|
|
19
|
+
* - **CN:** 正则表达式的标志
|
|
24
20
|
*/
|
|
25
21
|
flags?: string;
|
|
26
22
|
}
|
|
27
23
|
export interface RuleRegExpFlags {
|
|
28
24
|
/**
|
|
29
|
-
* **EN:** Include lowercase and uppercase Latin characters. If set to true, `lowerLetter` and
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* **CN:**: 包含大小写拉丁字符。如果设置为true,则`lowerLetter`和`upperLetter`属性不生效
|
|
25
|
+
* - **EN:** Include lowercase and uppercase Latin characters. If set to true, `lowerLetter` and
|
|
26
|
+
* `upperLetter` option are not effective
|
|
27
|
+
* - **CN:**: 包含大小写拉丁字符。如果设置为true,则`lowerLetter`和`upperLetter`属性不生效
|
|
33
28
|
*/
|
|
34
29
|
letter?: boolean;
|
|
35
30
|
/**
|
|
36
|
-
* **EN:** Include lowercase English letters
|
|
37
|
-
*
|
|
38
|
-
* **CN:**: 包含小写英文字符
|
|
31
|
+
* - **EN:** Include lowercase English letters
|
|
32
|
+
* - **CN:**: 包含小写英文字符
|
|
39
33
|
*/
|
|
40
34
|
lowerLetter?: boolean;
|
|
41
35
|
/**
|
|
42
|
-
* **EN:** Include uppercase English letters
|
|
43
|
-
*
|
|
44
|
-
* **CN:**: 包含大写英文字符
|
|
36
|
+
* - **EN:** Include uppercase English letters
|
|
37
|
+
* - **CN:**: 包含大写英文字符
|
|
45
38
|
*/
|
|
46
39
|
upperLetter?: boolean;
|
|
47
40
|
/**
|
|
48
|
-
* **EN:** Include Chinese characters
|
|
49
|
-
*
|
|
50
|
-
* **CN:** 包含中文字符
|
|
41
|
+
* - **EN:** Include Chinese characters
|
|
42
|
+
* - **CN:** 包含中文字符
|
|
51
43
|
*/
|
|
52
44
|
chineseCharacter?: boolean;
|
|
53
45
|
/**
|
|
54
|
-
* **EN:** Include Chinese (full-width) punctuation
|
|
55
|
-
*
|
|
56
|
-
* **CN:** 包含中文(全角)标点符号
|
|
46
|
+
* - **EN:** Include Chinese (full-width) punctuation
|
|
47
|
+
* - **CN:** 包含中文(全角)标点符号
|
|
57
48
|
*/
|
|
58
49
|
chinesePunctuation?: boolean;
|
|
59
50
|
/**
|
|
60
|
-
* **EN:** Include numbers
|
|
61
|
-
*
|
|
62
|
-
* **CN:** 包含数字
|
|
51
|
+
* - **EN:** Include numbers
|
|
52
|
+
* - **CN:** 包含数字
|
|
63
53
|
*/
|
|
64
54
|
number?: boolean;
|
|
65
55
|
/**
|
|
66
|
-
* **EN:** Include hyphens (-)
|
|
67
|
-
*
|
|
68
|
-
* **CN:** 包含连字符(-)
|
|
56
|
+
* - **EN:** Include hyphens (-)
|
|
57
|
+
* - **CN:** 包含连字符(-)
|
|
69
58
|
*/
|
|
70
59
|
hyphen?: boolean;
|
|
71
60
|
/**
|
|
72
|
-
* **EN:** Include underscores (_)
|
|
73
|
-
*
|
|
74
|
-
* **CN:** 包含下划线(_)
|
|
61
|
+
* - **EN:** Include underscores (_)
|
|
62
|
+
* - **CN:** 包含下划线(_)
|
|
75
63
|
*/
|
|
76
64
|
underscore?: boolean;
|
|
77
65
|
/**
|
|
78
|
-
* **EN:** Include specified special characters
|
|
79
|
-
*
|
|
80
|
-
* **CN:** 包含指定的特殊字符
|
|
66
|
+
* - **EN:** Include specified special characters
|
|
67
|
+
* - **CN:** 包含指定的特殊字符
|
|
81
68
|
*/
|
|
82
69
|
special?: string[];
|
|
83
70
|
/**
|
|
84
|
-
* **EN:** Minimum number of characters
|
|
85
|
-
*
|
|
86
|
-
* **CN:** 最小字符数量
|
|
71
|
+
* - **EN:** Minimum number of characters
|
|
72
|
+
* - **CN:** 最小字符数量
|
|
87
73
|
*
|
|
88
74
|
* @default 1
|
|
89
75
|
*/
|
|
90
76
|
min?: number;
|
|
91
77
|
/**
|
|
92
|
-
* **EN:** Maximum number of characters
|
|
93
|
-
*
|
|
94
|
-
* **CN:** 最大字符数量
|
|
78
|
+
* - **EN:** Maximum number of characters
|
|
79
|
+
* - **CN:** 最大字符数量
|
|
95
80
|
*/
|
|
96
81
|
max?: number;
|
|
97
82
|
}
|
|
98
83
|
export type StartsWithRegExpFlags = RuleRegExpFlags;
|
|
99
84
|
export interface ValidatorRule extends Validator {
|
|
100
85
|
/**
|
|
101
|
-
* **EN:** The options of allowed characters
|
|
102
|
-
*
|
|
103
|
-
* **CN:** 允许字符的规则设置
|
|
86
|
+
* - **EN:** The options of allowed characters
|
|
87
|
+
* - **CN:** 允许字符的规则设置
|
|
104
88
|
*/
|
|
105
89
|
allowedOptions: RuleRegExpFlags;
|
|
106
90
|
/**
|
|
107
|
-
* **EN:** The options of the starting character
|
|
108
|
-
*
|
|
109
|
-
* **CN:** 开头字符的规则设置
|
|
91
|
+
* - **EN:** The options of the starting character
|
|
92
|
+
* - **CN:** 开头字符的规则设置
|
|
110
93
|
*/
|
|
111
94
|
startsWithOptions?: StartsWithRegExpFlags;
|
|
112
95
|
/**
|
|
113
|
-
* **EN:** Regular expression flags
|
|
114
|
-
*
|
|
115
|
-
* **CN:** 正则表达式的标志
|
|
96
|
+
* - **EN:** Regular expression flags
|
|
97
|
+
* - **CN:** 正则表达式的标志
|
|
116
98
|
*/
|
|
117
99
|
flags?: string;
|
|
118
100
|
}
|
|
119
101
|
export interface Validator {
|
|
120
102
|
/**
|
|
121
|
-
* **EN:** Regular expression for verification
|
|
122
|
-
*
|
|
123
|
-
* **CN:** 校验正则表达式
|
|
103
|
+
* - **EN:** Regular expression for verification
|
|
104
|
+
* - **CN:** 校验正则表达式
|
|
124
105
|
*/
|
|
125
106
|
pattern: RegExp;
|
|
126
107
|
/**
|
|
127
|
-
* **EN:** Prompt message when verification fails
|
|
128
|
-
*
|
|
129
|
-
* **CN:** 校验失败时的提示信息
|
|
108
|
+
* - **EN:** Prompt message when verification fails
|
|
109
|
+
* - **CN:** 校验失败时的提示信息
|
|
130
110
|
*/
|
|
131
111
|
message: string;
|
|
132
112
|
}
|
|
@@ -10,9 +10,8 @@ import useT from "./useT";
|
|
|
10
10
|
var nameSeparator = 'validation.rule.buildRule.token.separator';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* **EN:** Get a validation rule builder to build validation rules
|
|
14
|
-
*
|
|
15
|
-
* **CN:** 获取一个校验规则生成器,用来构建校验规则
|
|
13
|
+
* - **EN:** Get a validation rule builder to build validation rules
|
|
14
|
+
* - **CN:** 获取一个校验规则生成器,用来构建校验规则
|
|
16
15
|
*/
|
|
17
16
|
var useValidatorBuilder = function useValidatorBuilder() {
|
|
18
17
|
var t = useT();
|
|
@@ -26,9 +25,8 @@ var useValidatorBuilder = function useValidatorBuilder() {
|
|
|
26
25
|
};
|
|
27
26
|
|
|
28
27
|
/**
|
|
29
|
-
* **EN:** Build regular expression rules dynamically, compatible with ant-design rules
|
|
30
|
-
*
|
|
31
|
-
* **CN:** 动态构建正则表达式规则,与 ant-design 的规则兼容
|
|
28
|
+
* - **EN:** Build regular expression rules dynamically, compatible with ant-design rules
|
|
29
|
+
* - **CN:** 动态构建正则表达式规则,与 ant-design 的规则兼容
|
|
32
30
|
*/
|
|
33
31
|
function buildRule(options) {
|
|
34
32
|
var allowed = options.allowed,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useMemo","escape","useT","nameSeparator","useValidatorBuilder","t","props","buildRule","_objectSpread","options","allowed","startsWith","flags","Object","values","some","v","Error","symbols","messages","push","meta","buildRuleMeta","concat","join","prefix","_allowed$min","_allowed$max","min","max","cMin","cMax","length","unshift","message","slice","pattern","RegExp","content","allowedOptions","startsWithOptions","chineseCharacter","chinesePunctuation","letter","lowerLetter","upperLetter","number","excludeSpecials","hyphen","underscore","special","specials","filter","includes"],"sources":["../../src/hooks/useValidatorBuilder.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport escape from 'escape-string-regexp';\nimport useT from './useT';\n\nconst nameSeparator = 'validation.rule.buildRule.token.separator';\n\n/**\n * **EN:** Get a validation rule builder to build validation rules\n *\n * **CN:** 获取一个校验规则生成器,用来构建校验规则\n */\nconst useValidatorBuilder = () => {\n const t = useT();\n return useMemo(() => (props: BuilderOptions) => buildRule({ ...props, t }), [t]);\n};\n\n/**\n * **EN:** Build regular expression rules dynamically, compatible with ant-design rules\n *\n * **CN:** 动态构建正则表达式规则,与 ant-design 的规则兼容\n */\nfunction buildRule(\n options: BuilderOptions & {\n /**\n * **EN:** Internationalization function\n *\n * **CN:** 国际化函数\n */\n t: ReturnType<typeof useT>;\n }\n): ValidatorRule {\n const { allowed, startsWith, flags, t } = options;\n if (!Object.values(allowed).some((v) => v === true)) {\n throw new Error(t('validation.rule.buildRule.includeMandatory'));\n }\n\n const symbols: string[] = [];\n const messages: string[] = [];\n symbols.push(`^`);\n\n // Process startsWith rules\n if (startsWith) {\n const meta = buildRuleMeta({\n flags: startsWith,\n t,\n });\n symbols.push(`[${meta.symbols.join('')}]`);\n messages.push(\n t('validation.rule.buildRule.startsWithFormat', {\n prefix: meta.messages.join(t(nameSeparator)),\n })\n );\n }\n\n // Process allowed rules\n {\n const meta = buildRuleMeta({ flags: allowed, t });\n\n const min = allowed.min ?? 0;\n const max = allowed.max ?? 0; // 0 means unlimited\n\n // If there is startWith in the regular expression, the limited data amount needs to be reduced by 1\n const cMin = min && startsWith ? min - 1 : min;\n const cMax = max && startsWith ? max - 1 : max;\n\n symbols.push(`[${meta.symbols.join('')}]{${cMin},${cMax || ''}}`);\n if (meta.messages.length === 0) {\n messages.unshift(``);\n } else if (meta.messages.length === 1) {\n messages.unshift(`${meta.messages.join(t(nameSeparator))}`);\n } else {\n messages.unshift(`${meta.messages.join(t(nameSeparator))}`);\n }\n if (min && max) {\n messages.push(\n t('validation.rule.buildRule.rangeLength', {\n min,\n max,\n })\n );\n } else {\n if (min > 1) {\n messages.push(t('validation.rule.buildRule.minLength', { min }));\n }\n if (max) {\n messages.push(t('validation.rule.buildRule.maxLength', { max }));\n }\n }\n }\n symbols.push(`$`);\n\n let message = messages.join('');\n if (message.startsWith(t(nameSeparator))) {\n message = message.slice(1);\n }\n return {\n pattern: new RegExp(symbols.join(''), flags),\n message: t('validation.rule.buildRule.messageFormat', { content: message }),\n allowedOptions: allowed,\n startsWithOptions: startsWith,\n flags,\n };\n}\n\nfunction buildRuleMeta(options: { flags: RuleRegExpFlags; t: ReturnType<typeof useT> }): RuleMeta {\n const { flags, t } = options;\n const symbols: string[] = [];\n const messages: string[] = [];\n if (flags.chineseCharacter) {\n // Chinese characters\n symbols.push(`\\u4e00-\\u9fa5`);\n messages.push(t('validation.rule.buildRule.token.chinese'));\n }\n if (flags.chinesePunctuation) {\n // Chinese punctuation\n symbols.push(`\\u3000-\\u301e`);\n symbols.push(`\\u3021-\\u303f`);\n symbols.push(`\\uff00-\\uffef`);\n messages.push(t('validation.rule.buildRule.token.chinesePunctuation'));\n }\n if (flags.letter) {\n symbols.push(`a-zA-Z`);\n messages.push(t('validation.rule.buildRule.token.letter'));\n } else if (flags.lowerLetter) {\n symbols.push(`a-z`);\n messages.push(t('validation.rule.buildRule.token.lowerLetter'));\n } else if (flags.upperLetter) {\n symbols.push(`A-Z`);\n messages.push(t('validation.rule.buildRule.token.upperLetter'));\n }\n if (flags.number) {\n symbols.push(`0-9`);\n messages.push(t('validation.rule.buildRule.token.number'));\n }\n const excludeSpecials: string[] = [];\n if (flags.hyphen) {\n symbols.push(`\\\\-`);\n messages.push(`-`);\n excludeSpecials.push('-');\n }\n if (flags.underscore) {\n symbols.push(`_`);\n messages.push(`_`);\n excludeSpecials.push('_');\n }\n if (flags.special) {\n const specials = flags.special.filter((v) => !excludeSpecials.includes(v));\n symbols.push(escape(specials.join('')));\n messages.push(specials.join(t(nameSeparator)));\n }\n return {\n symbols,\n messages,\n };\n}\n\nexport interface BuilderOptions {\n /**\n * **EN:** The rule of allowed characters\n *\n * **CN:** 允许字符的规则\n */\n allowed: RuleRegExpFlags;\n /**\n * **EN:** The rule of the starting character\n *\n * **CN:** 开头字符的规则\n */\n startsWith?: Omit<RuleRegExpFlags, 'min' | 'max'>;\n /**\n * **EN:** Regular expression flags\n *\n * **CN:** 正则表达式的标志\n */\n flags?: string;\n}\n\nexport interface RuleRegExpFlags {\n /**\n * **EN:** Include lowercase and uppercase Latin characters. If set to true, `lowerLetter` and\n * `upperLetter` option are not effective\n *\n * **CN:**: 包含大小写拉丁字符。如果设置为true,则`lowerLetter`和`upperLetter`属性不生效\n */\n\n letter?: boolean;\n /**\n * **EN:** Include lowercase English letters\n *\n * **CN:**: 包含小写英文字符\n */\n lowerLetter?: boolean;\n /**\n * **EN:** Include uppercase English letters\n *\n * **CN:**: 包含大写英文字符\n */\n upperLetter?: boolean;\n /**\n * **EN:** Include Chinese characters\n *\n * **CN:** 包含中文字符\n */\n chineseCharacter?: boolean;\n /**\n * **EN:** Include Chinese (full-width) punctuation\n *\n * **CN:** 包含中文(全角)标点符号\n */\n chinesePunctuation?: boolean;\n /**\n * **EN:** Include numbers\n *\n * **CN:** 包含数字\n */\n number?: boolean;\n /**\n * **EN:** Include hyphens (-)\n *\n * **CN:** 包含连字符(-)\n */\n hyphen?: boolean;\n /**\n * **EN:** Include underscores (_)\n *\n * **CN:** 包含下划线(_)\n */\n underscore?: boolean;\n /**\n * **EN:** Include specified special characters\n *\n * **CN:** 包含指定的特殊字符\n */\n special?: string[];\n /**\n * **EN:** Minimum number of characters\n *\n * **CN:** 最小字符数量\n *\n * @default 1\n */\n min?: number;\n /**\n * **EN:** Maximum number of characters\n *\n * **CN:** 最大字符数量\n */\n max?: number;\n}\n\nexport type StartsWithRegExpFlags = RuleRegExpFlags;\n\nexport interface ValidatorRule extends Validator {\n /**\n * **EN:** The options of allowed characters\n *\n * **CN:** 允许字符的规则设置\n */\n allowedOptions: RuleRegExpFlags;\n /**\n * **EN:** The options of the starting character\n *\n * **CN:** 开头字符的规则设置\n */\n startsWithOptions?: StartsWithRegExpFlags;\n /**\n * **EN:** Regular expression flags\n *\n * **CN:** 正则表达式的标志\n */\n flags?: string;\n}\n\ninterface RuleMeta {\n symbols: string[];\n messages: string[];\n}\n\nexport interface Validator {\n /**\n * **EN:** Regular expression for verification\n *\n * **CN:** 校验正则表达式\n */\n pattern: RegExp;\n /**\n * **EN:** Prompt message when verification fails\n *\n * **CN:** 校验失败时的提示信息\n */\n message: string;\n}\n\nexport default useValidatorBuilder;\n"],"mappings":";;;;;;AAAA,SAASA,OAAO,QAAQ,OAAO;AAC/B,OAAOC,MAAM,MAAM,sBAAsB;AACzC,OAAOC,IAAI;AAEX,IAAMC,aAAa,GAAG,2CAA2C;;AA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IAAI,CAAC;IACjBD,QAAQ,CAACC,IAAI,IAAI,CAAC;IAClB2B,eAAe,CAAC3B,IAAI,CAAC,GAAG,CAAC;EAC3B;EACA,IAAIR,KAAK,CAACsC,OAAO,EAAE;IACjB,IAAMC,QAAQ,GAAGvC,KAAK,CAACsC,OAAO,CAACE,MAAM,CAAC,UAACpC,CAAC;MAAA,OAAK,CAAC+B,eAAe,CAACM,QAAQ,CAACrC,CAAC,CAAC;IAAA,EAAC;IAC1EE,OAAO,CAACE,IAAI,CAACnB,MAAM,CAACkD,QAAQ,CAAC3B,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IACvCL,QAAQ,CAACC,IAAI,CAAC+B,QAAQ,CAAC3B,IAAI,CAACnB,CAAC,CAACF,aAAa,CAAC,CAAC,CAAC;EAChD;EACA,OAAO;IACLe,OAAO,EAAPA,OAAO;IACPC,QAAQ,EAARA;EACF,CAAC;AACH;AA2IA,eAAef,mBAAmB"}
|
|
1
|
+
{"version":3,"names":["useMemo","escape","useT","nameSeparator","useValidatorBuilder","t","props","buildRule","_objectSpread","options","allowed","startsWith","flags","Object","values","some","v","Error","symbols","messages","push","meta","buildRuleMeta","concat","join","prefix","_allowed$min","_allowed$max","min","max","cMin","cMax","length","unshift","message","slice","pattern","RegExp","content","allowedOptions","startsWithOptions","chineseCharacter","chinesePunctuation","letter","lowerLetter","upperLetter","number","excludeSpecials","hyphen","underscore","special","specials","filter","includes"],"sources":["../../src/hooks/useValidatorBuilder.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport escape from 'escape-string-regexp';\nimport useT from './useT';\n\nconst nameSeparator = 'validation.rule.buildRule.token.separator';\n\n/**\n * - **EN:** Get a validation rule builder to build validation rules\n * - **CN:** 获取一个校验规则生成器,用来构建校验规则\n */\nconst useValidatorBuilder = () => {\n const t = useT();\n return useMemo(() => (props: BuilderOptions) => buildRule({ ...props, t }), [t]);\n};\n\n/**\n * - **EN:** Build regular expression rules dynamically, compatible with ant-design rules\n * - **CN:** 动态构建正则表达式规则,与 ant-design 的规则兼容\n */\nfunction buildRule(\n options: BuilderOptions & {\n /**\n * - **EN:** Internationalization function\n * - **CN:** 国际化函数\n */\n t: ReturnType<typeof useT>;\n }\n): ValidatorRule {\n const { allowed, startsWith, flags, t } = options;\n if (!Object.values(allowed).some((v) => v === true)) {\n throw new Error(t('validation.rule.buildRule.includeMandatory'));\n }\n\n const symbols: string[] = [];\n const messages: string[] = [];\n symbols.push(`^`);\n\n // Process startsWith rules\n if (startsWith) {\n const meta = buildRuleMeta({\n flags: startsWith,\n t,\n });\n symbols.push(`[${meta.symbols.join('')}]`);\n messages.push(\n t('validation.rule.buildRule.startsWithFormat', {\n prefix: meta.messages.join(t(nameSeparator)),\n })\n );\n }\n\n // Process allowed rules\n {\n const meta = buildRuleMeta({ flags: allowed, t });\n\n const min = allowed.min ?? 0;\n const max = allowed.max ?? 0; // 0 means unlimited\n\n // If there is startWith in the regular expression, the limited data amount needs to be reduced by 1\n const cMin = min && startsWith ? min - 1 : min;\n const cMax = max && startsWith ? max - 1 : max;\n\n symbols.push(`[${meta.symbols.join('')}]{${cMin},${cMax || ''}}`);\n if (meta.messages.length === 0) {\n messages.unshift(``);\n } else if (meta.messages.length === 1) {\n messages.unshift(`${meta.messages.join(t(nameSeparator))}`);\n } else {\n messages.unshift(`${meta.messages.join(t(nameSeparator))}`);\n }\n if (min && max) {\n messages.push(\n t('validation.rule.buildRule.rangeLength', {\n min,\n max,\n })\n );\n } else {\n if (min > 1) {\n messages.push(t('validation.rule.buildRule.minLength', { min }));\n }\n if (max) {\n messages.push(t('validation.rule.buildRule.maxLength', { max }));\n }\n }\n }\n symbols.push(`$`);\n\n let message = messages.join('');\n if (message.startsWith(t(nameSeparator))) {\n message = message.slice(1);\n }\n return {\n pattern: new RegExp(symbols.join(''), flags),\n message: t('validation.rule.buildRule.messageFormat', { content: message }),\n allowedOptions: allowed,\n startsWithOptions: startsWith,\n flags,\n };\n}\n\nfunction buildRuleMeta(options: { flags: RuleRegExpFlags; t: ReturnType<typeof useT> }): RuleMeta {\n const { flags, t } = options;\n const symbols: string[] = [];\n const messages: string[] = [];\n if (flags.chineseCharacter) {\n // Chinese characters\n symbols.push(`\\u4e00-\\u9fa5`);\n messages.push(t('validation.rule.buildRule.token.chinese'));\n }\n if (flags.chinesePunctuation) {\n // Chinese punctuation\n symbols.push(`\\u3000-\\u301e`);\n symbols.push(`\\u3021-\\u303f`);\n symbols.push(`\\uff00-\\uffef`);\n messages.push(t('validation.rule.buildRule.token.chinesePunctuation'));\n }\n if (flags.letter) {\n symbols.push(`a-zA-Z`);\n messages.push(t('validation.rule.buildRule.token.letter'));\n } else if (flags.lowerLetter) {\n symbols.push(`a-z`);\n messages.push(t('validation.rule.buildRule.token.lowerLetter'));\n } else if (flags.upperLetter) {\n symbols.push(`A-Z`);\n messages.push(t('validation.rule.buildRule.token.upperLetter'));\n }\n if (flags.number) {\n symbols.push(`0-9`);\n messages.push(t('validation.rule.buildRule.token.number'));\n }\n const excludeSpecials: string[] = [];\n if (flags.hyphen) {\n symbols.push(`\\\\-`);\n messages.push(`-`);\n excludeSpecials.push('-');\n }\n if (flags.underscore) {\n symbols.push(`_`);\n messages.push(`_`);\n excludeSpecials.push('_');\n }\n if (flags.special) {\n const specials = flags.special.filter((v) => !excludeSpecials.includes(v));\n symbols.push(escape(specials.join('')));\n messages.push(specials.join(t(nameSeparator)));\n }\n return {\n symbols,\n messages,\n };\n}\n\nexport interface BuilderOptions {\n /**\n * - **EN:** The rule of allowed characters\n * - **CN:** 允许字符的规则\n */\n allowed: RuleRegExpFlags;\n /**\n * - **EN:** The rule of the starting character\n * - **CN:** 开头字符的规则\n */\n startsWith?: Omit<RuleRegExpFlags, 'min' | 'max'>;\n /**\n * - **EN:** Regular expression flags\n * - **CN:** 正则表达式的标志\n */\n flags?: string;\n}\n\nexport interface RuleRegExpFlags {\n /**\n * - **EN:** Include lowercase and uppercase Latin characters. If set to true, `lowerLetter` and\n * `upperLetter` option are not effective\n * - **CN:**: 包含大小写拉丁字符。如果设置为true,则`lowerLetter`和`upperLetter`属性不生效\n */\n\n letter?: boolean;\n /**\n * - **EN:** Include lowercase English letters\n * - **CN:**: 包含小写英文字符\n */\n lowerLetter?: boolean;\n /**\n * - **EN:** Include uppercase English letters\n * - **CN:**: 包含大写英文字符\n */\n upperLetter?: boolean;\n /**\n * - **EN:** Include Chinese characters\n * - **CN:** 包含中文字符\n */\n chineseCharacter?: boolean;\n /**\n * - **EN:** Include Chinese (full-width) punctuation\n * - **CN:** 包含中文(全角)标点符号\n */\n chinesePunctuation?: boolean;\n /**\n * - **EN:** Include numbers\n * - **CN:** 包含数字\n */\n number?: boolean;\n /**\n * - **EN:** Include hyphens (-)\n * - **CN:** 包含连字符(-)\n */\n hyphen?: boolean;\n /**\n * - **EN:** Include underscores (_)\n * - **CN:** 包含下划线(_)\n */\n underscore?: boolean;\n /**\n * - **EN:** Include specified special characters\n * - **CN:** 包含指定的特殊字符\n */\n special?: string[];\n /**\n * - **EN:** Minimum number of characters\n * - **CN:** 最小字符数量\n *\n * @default 1\n */\n min?: number;\n /**\n * - **EN:** Maximum number of characters\n * - **CN:** 最大字符数量\n */\n max?: number;\n}\n\nexport type StartsWithRegExpFlags = RuleRegExpFlags;\n\nexport interface ValidatorRule extends Validator {\n /**\n * - **EN:** The options of allowed characters\n * - **CN:** 允许字符的规则设置\n */\n allowedOptions: RuleRegExpFlags;\n /**\n * - **EN:** The options of the starting character\n * - **CN:** 开头字符的规则设置\n */\n startsWithOptions?: StartsWithRegExpFlags;\n /**\n * - **EN:** Regular expression flags\n * - **CN:** 正则表达式的标志\n */\n flags?: string;\n}\n\ninterface RuleMeta {\n symbols: string[];\n messages: string[];\n}\n\nexport interface Validator {\n /**\n * - **EN:** Regular expression for verification\n * - **CN:** 校验正则表达式\n */\n pattern: RegExp;\n /**\n * - **EN:** Prompt message when verification fails\n * - **CN:** 校验失败时的提示信息\n */\n message: string;\n}\n\nexport default useValidatorBuilder;\n"],"mappings":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C;IAClB2B,eAAe,CAAC3B,IAAI,CAAC,GAAG,CAAC;EAC3B;EACA,IAAIR,KAAK,CAACqC,UAAU,EAAE;IACpB/B,OAAO,CAACE,IAAI,IAAI,CAAC;IACjBD,QAAQ,CAACC,IAAI,IAAI,CAAC;IAClB2B,eAAe,CAAC3B,IAAI,CAAC,GAAG,CAAC;EAC3B;EACA,IAAIR,KAAK,CAACsC,OAAO,EAAE;IACjB,IAAMC,QAAQ,GAAGvC,KAAK,CAACsC,OAAO,CAACE,MAAM,CAAC,UAACpC,CAAC;MAAA,OAAK,CAAC+B,eAAe,CAACM,QAAQ,CAACrC,CAAC,CAAC;IAAA,EAAC;IAC1EE,OAAO,CAACE,IAAI,CAACnB,MAAM,CAACkD,QAAQ,CAAC3B,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IACvCL,QAAQ,CAACC,IAAI,CAAC+B,QAAQ,CAAC3B,IAAI,CAACnB,CAAC,CAACF,aAAa,CAAC,CAAC,CAAC;EAChD;EACA,OAAO;IACLe,OAAO,EAAPA,OAAO;IACPC,QAAQ,EAARA;EACF,CAAC;AACH;AAwHA,eAAef,mBAAmB"}
|
|
@@ -1,149 +1,128 @@
|
|
|
1
1
|
import { type Validator, type ValidatorRule } from './useValidatorBuilder';
|
|
2
2
|
/**
|
|
3
|
-
* **EN:** Get built-in validation rules, used to verify common data formats, compatible with
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* **CN:** 获取内置的校验规则,用于校验常见的数据格式,与 ant-design 的规则兼容
|
|
3
|
+
* - **EN:** Get built-in validation rules, used to verify common data formats, compatible with
|
|
4
|
+
* ant-design rules
|
|
5
|
+
* - **CN:** 获取内置的校验规则,用于校验常见的数据格式,与 ant-design 的规则兼容
|
|
7
6
|
*/
|
|
8
7
|
declare const useValidators: () => ValidatorRuleMap;
|
|
9
8
|
export interface ValidatorRuleMap {
|
|
10
9
|
/**
|
|
11
|
-
* **EN:** Number
|
|
12
|
-
*
|
|
13
|
-
* **CN:** 数字
|
|
10
|
+
* - **EN:** Number
|
|
11
|
+
* - **CN:** 数字
|
|
14
12
|
*/
|
|
15
13
|
number: Validator;
|
|
16
14
|
/**
|
|
17
|
-
* **EN:** Floating point number
|
|
18
|
-
*
|
|
19
|
-
* **CN:** 浮点数
|
|
15
|
+
* - **EN:** Floating point number
|
|
16
|
+
* - **CN:** 浮点数
|
|
20
17
|
*/
|
|
21
18
|
floatNumber: Validator;
|
|
22
19
|
/**
|
|
23
|
-
* **EN:** Email address regular expression (supports Chinese names)
|
|
24
|
-
*
|
|
25
|
-
* **CN:** 邮箱正则表达式(支持中文名称)
|
|
20
|
+
* - **EN:** Email address regular expression (supports Chinese names)
|
|
21
|
+
* - **CN:** 邮箱正则表达式(支持中文名称)
|
|
26
22
|
*/
|
|
27
23
|
email: Validator;
|
|
28
24
|
/**
|
|
29
|
-
* **EN:** IP address regular expression
|
|
30
|
-
*
|
|
31
|
-
* **CN:** ip地址正则表达式
|
|
25
|
+
* - **EN:** IP address regular expression
|
|
26
|
+
* - **CN:** ip地址正则表达式
|
|
32
27
|
*/
|
|
33
28
|
ip: Validator;
|
|
34
29
|
/**
|
|
35
|
-
* **EN:** Chine mobile phone number regular expression. If this rule does not meet the
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* **CN:** 中国手机号正则表达式。如果这个规则不满足需求,请使用 `useValidator` 方法自定义规则。
|
|
30
|
+
* - **EN:** Chine mobile phone number regular expression. If this rule does not meet the
|
|
31
|
+
* requirements, please use the `useValidator` method to customize the rule.
|
|
32
|
+
* - **CN:** 中国手机号正则表达式。如果这个规则不满足需求,请使用 `useValidator` 方法自定义规则。
|
|
39
33
|
*/
|
|
40
34
|
cnMobile: Validator;
|
|
41
35
|
/**
|
|
42
|
-
* **EN:** Default password verification rule: 8-16 digit password, at least two of numbers,
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* **CN:** 默认密码验证规则:8-16位密码,数字、字母、符号至少包含两种。如果这个规则不满足需求,请使用 `useValidator` 方法自定义规则。
|
|
36
|
+
* - **EN:** Default password verification rule: 8-16 digit password, at least two of numbers,
|
|
37
|
+
* letters, and symbols. If this rule does not meet the requirements, please use the
|
|
38
|
+
* `useValidator` method to customize the rule.
|
|
39
|
+
* - **CN:** 默认密码验证规则:8-16位密码,数字、字母、符号至少包含两种。如果这个规则不满足需求,请使用 `useValidator` 方法自定义规则。
|
|
47
40
|
*/
|
|
48
41
|
password: Validator;
|
|
49
42
|
/**
|
|
50
|
-
* **EN:** Used to verify the code rule: letters, numbers, _, starting with a letter, no limit on
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* **CN:** 用于校验编码的规则:字母、数字、_,以字母开头,不限制字符数量
|
|
43
|
+
* - **EN:** Used to verify the code rule: letters, numbers, _, starting with a letter, no limit on
|
|
44
|
+
* the number of characters
|
|
45
|
+
* - **CN:** 用于校验编码的规则:字母、数字、_,以字母开头,不限制字符数量
|
|
54
46
|
*/
|
|
55
47
|
code: ValidatorRule;
|
|
56
48
|
/**
|
|
57
|
-
* **EN:** Used to verify the code rule: letters, numbers, _, starting with a letter, up to 20
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* **CN:** 用于校验编码的规则:字母、数字、_,以字母开头,最多20个字符
|
|
49
|
+
* - **EN:** Used to verify the code rule: letters, numbers, _, starting with a letter, up to 20
|
|
50
|
+
* characters
|
|
51
|
+
* - **CN:** 用于校验编码的规则:字母、数字、_,以字母开头,最多20个字符
|
|
61
52
|
*/
|
|
62
53
|
codeMax20: ValidatorRule;
|
|
63
54
|
/**
|
|
64
|
-
* **EN:** Used to verify the code rule: letters, numbers, _, starting with a letter, up to 64
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* **CN:** 用于校验编码的规则:字母、数字、_,以字母开头,最多64个字符
|
|
55
|
+
* - **EN:** Used to verify the code rule: letters, numbers, _, starting with a letter, up to 64
|
|
56
|
+
* characters
|
|
57
|
+
* - **CN:** 用于校验编码的规则:字母、数字、_,以字母开头,最多64个字符
|
|
68
58
|
*/
|
|
69
59
|
codeMax64: ValidatorRule;
|
|
70
60
|
/**
|
|
71
|
-
* **EN:** Used to verify the code rule: letters, numbers, _, starting with a letter, up to 128
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* **CN:** 用于校验编码的规则:字母、数字、_,以字母开头,最多128个字符
|
|
61
|
+
* - **EN:** Used to verify the code rule: letters, numbers, _, starting with a letter, up to 128
|
|
62
|
+
* characters
|
|
63
|
+
* - **CN:** 用于校验编码的规则:字母、数字、_,以字母开头,最多128个字符
|
|
75
64
|
*/
|
|
76
65
|
codeMax128: ValidatorRule;
|
|
77
66
|
/**
|
|
78
|
-
* **EN:** Used to verify the code rule: letters, numbers, _, starting with a letter, up to {max}
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* **CN:** 用于校验名称的规则,可以自定义最大字符数:字母、汉字、数字、-、_,以汉字、字母开头,{max}字符以内
|
|
67
|
+
* - **EN:** Used to verify the code rule: letters, numbers, _, starting with a letter, up to {max}
|
|
68
|
+
* characters
|
|
69
|
+
* - **CN:** 用于校验名称的规则,可以自定义最大字符数:字母、汉字、数字、-、_,以汉字、字母开头,{max}字符以内
|
|
82
70
|
*/
|
|
83
71
|
codeWithMax: (max?: number) => ValidatorRule;
|
|
84
72
|
/**
|
|
85
|
-
* **EN:** Used to verify the name rule: letters, Chinese characters, numbers, -, _, up to 20
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* **CN:** 用于校验名称的规则:字母、汉字、数字、-、_,最多20个字符,
|
|
73
|
+
* - **EN:** Used to verify the name rule: letters, Chinese characters, numbers, -, _, up to 20
|
|
74
|
+
* characters
|
|
75
|
+
* - **CN:** 用于校验名称的规则:字母、汉字、数字、-、_,最多20个字符,
|
|
89
76
|
*/
|
|
90
77
|
name: ValidatorRule;
|
|
91
78
|
/**
|
|
92
|
-
* **EN:** Used to verify the name rule: letters, Chinese characters, numbers, -, _, up to 64
|
|
93
|
-
*
|
|
94
|
-
* **CN:** 用于校验名称的规则:字母、汉字、数字、-、_,不限制字符数量
|
|
79
|
+
* - **EN:** Used to verify the name rule: letters, Chinese characters, numbers, -, _, up to 64
|
|
80
|
+
* - **CN:** 用于校验名称的规则:字母、汉字、数字、-、_,不限制字符数量
|
|
95
81
|
*/
|
|
96
82
|
nameMax20: ValidatorRule;
|
|
97
83
|
/**
|
|
98
|
-
* **EN:** Used to verify the name rule: letters, Chinese characters, numbers, -, _, up to 64
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* **CN:** 用于校验名称的规则:字母、汉字、数字、-、_,最多64个字符
|
|
84
|
+
* - **EN:** Used to verify the name rule: letters, Chinese characters, numbers, -, _, up to 64
|
|
85
|
+
* characters
|
|
86
|
+
* - **CN:** 用于校验名称的规则:字母、汉字、数字、-、_,最多64个字符
|
|
102
87
|
*/
|
|
103
88
|
nameMax64: ValidatorRule;
|
|
104
89
|
/**
|
|
105
|
-
* **EN:** Used to verify the name rule: letters, Chinese characters, numbers, -, _, up to 128
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* **CN:** 用于校验名称的规则:字母、汉字、数字、-、_,最多128个字符
|
|
90
|
+
* - **EN:** Used to verify the name rule: letters, Chinese characters, numbers, -, _, up to 128
|
|
91
|
+
* characters
|
|
92
|
+
* - **CN:** 用于校验名称的规则:字母、汉字、数字、-、_,最多128个字符
|
|
109
93
|
*/
|
|
110
94
|
nameMax128: ValidatorRule;
|
|
111
95
|
/**
|
|
112
|
-
* **EN:** Used to verify the name rule: letters, Chinese characters, numbers, -, _, up to {max}
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* **CN:** 用于校验名称的规则,可以自定义最大字符数:字母、汉字、数字、-、_,以汉字、字母开头,{max}字符以内
|
|
96
|
+
* - **EN:** Used to verify the name rule: letters, Chinese characters, numbers, -, _, up to {max}
|
|
97
|
+
* characters
|
|
98
|
+
* - **CN:** 用于校验名称的规则,可以自定义最大字符数:字母、汉字、数字、-、_,以汉字、字母开头,{max}字符以内
|
|
116
99
|
*/
|
|
117
100
|
nameWithMax: (max?: number) => ValidatorRule;
|
|
118
101
|
/**
|
|
119
|
-
* **EN:** Used to verify the name rule, but it needs to start with Chinese characters or letters:
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
* **CN:** 用于校验名称的规则,但需要以汉字或字母开头:字母、汉字、数字、-、_,以汉字、字母开头
|
|
102
|
+
* - **EN:** Used to verify the name rule, but it needs to start with Chinese characters or letters:
|
|
103
|
+
* letters, Chinese characters, numbers, -, _, starting with Chinese characters or letters
|
|
104
|
+
* - **CN:** 用于校验名称的规则,但需要以汉字或字母开头:字母、汉字、数字、-、_,以汉字、字母开头
|
|
123
105
|
*/
|
|
124
106
|
strongName: ValidatorRule;
|
|
125
107
|
/**
|
|
126
|
-
* **EN:** Used to verify the name rule, but it needs to start with Chinese characters or letters:
|
|
127
|
-
*
|
|
128
|
-
* 64 characters
|
|
129
|
-
*
|
|
130
|
-
* **CN:** 用于校验名称的规则,但需要以汉字或字母开头:字母、汉字、数字、-、_,以汉字、字母开头,最多64个字符
|
|
108
|
+
* - **EN:** Used to verify the name rule, but it needs to start with Chinese characters or letters:
|
|
109
|
+
* letters, Chinese characters, numbers, -, _, starting with Chinese characters or letters, up
|
|
110
|
+
* to 64 characters
|
|
111
|
+
* - **CN:** 用于校验名称的规则,但需要以汉字或字母开头:字母、汉字、数字、-、_,以汉字、字母开头,最多64个字符
|
|
131
112
|
*/
|
|
132
113
|
strongNameMax64: ValidatorRule;
|
|
133
114
|
/**
|
|
134
|
-
* **EN:** Used to verify the name rule, but it needs to start with Chinese characters or letters:
|
|
135
|
-
*
|
|
136
|
-
* 128 characters
|
|
137
|
-
*
|
|
138
|
-
* **CN:** 用于校验名称的规则,但需要以汉字或字母开头:字母、汉字、数字、-、_,以汉字、字母开头,最多128个字符
|
|
115
|
+
* - **EN:** Used to verify the name rule, but it needs to start with Chinese characters or letters:
|
|
116
|
+
* letters, Chinese characters, numbers, -, _, starting with Chinese characters or letters, up
|
|
117
|
+
* to 128 characters
|
|
118
|
+
* - **CN:** 用于校验名称的规则,但需要以汉字或字母开头:字母、汉字、数字、-、_,以汉字、字母开头,最多128个字符
|
|
139
119
|
*/
|
|
140
120
|
strongNameMax128: ValidatorRule;
|
|
141
121
|
/**
|
|
142
|
-
* **EN:** Used to verify the name rule, but it needs to start with Chinese characters or letters:
|
|
143
|
-
*
|
|
144
|
-
* {max} characters
|
|
145
|
-
*
|
|
146
|
-
* **CN:** 用于校验名称的规则,但需要以汉字或字母开头:字母、汉字、数字、-、_,以汉字、字母开头,{max}字符以内
|
|
122
|
+
* - **EN:** Used to verify the name rule, but it needs to start with Chinese characters or letters:
|
|
123
|
+
* letters, Chinese characters, numbers, -, _, starting with Chinese characters or letters, up
|
|
124
|
+
* to {max} characters
|
|
125
|
+
* - **CN:** 用于校验名称的规则,但需要以汉字或字母开头:字母、汉字、数字、-、_,以汉字、字母开头,{max}字符以内
|
|
147
126
|
*/
|
|
148
127
|
strongNameWithMax: (max?: number) => ValidatorRule;
|
|
149
128
|
}
|
|
@@ -4,10 +4,9 @@ import useT from "./useT";
|
|
|
4
4
|
import useValidatorBuilder from "./useValidatorBuilder";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* **EN:** Get built-in validation rules, used to verify common data formats, compatible with
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* **CN:** 获取内置的校验规则,用于校验常见的数据格式,与 ant-design 的规则兼容
|
|
7
|
+
* - **EN:** Get built-in validation rules, used to verify common data formats, compatible with
|
|
8
|
+
* ant-design rules
|
|
9
|
+
* - **CN:** 获取内置的校验规则,用于校验常见的数据格式,与 ant-design 的规则兼容
|
|
11
10
|
*/
|
|
12
11
|
var useValidators = function useValidators() {
|
|
13
12
|
var t = useT();
|