@chopperqt/react-hook-form-rules 2.3.1 → 2.4.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.
- package/CHANGELOG.md +18 -0
- package/README.md +38 -13
- package/dist/cjs/locales/TranslateKey.d.ts +1 -0
- package/dist/cjs/locales/TranslateKey.js +1 -0
- package/dist/cjs/locales/en.json +2 -1
- package/dist/cjs/locales/ru.json +2 -1
- package/dist/cjs/rules/patterns/get-pattern-rule.d.ts +3 -4
- package/dist/cjs/rules/patterns/get-pattern-rule.js +4 -4
- package/dist/cjs/tests/rules/patterns/get-pattern-rule.test.js +7 -0
- package/dist/esm/locales/TranslateKey.js +1 -0
- package/dist/esm/locales/en.json +2 -1
- package/dist/esm/locales/ru.json +2 -1
- package/dist/esm/rules/patterns/get-pattern-rule.js +4 -4
- package/dist/esm/tests/rules/patterns/get-pattern-rule.test.js +7 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## [2.4.0](https://github.com/chopperqt/react-hook-form-rules/compare/v2.3.1...v2.4.0) (2026-03-15)
|
|
2
|
+
|
|
3
|
+
### 📄 Documentation
|
|
4
|
+
|
|
5
|
+
* обновлена документация, добавлно правило getPatternRule ([dc58c51](https://github.com/chopperqt/react-hook-form-rules/commit/dc58c513f82ff0203404cc13055dee87869ae2d6))
|
|
6
|
+
|
|
7
|
+
### 🆕 Features
|
|
8
|
+
|
|
9
|
+
* добавлена ошибки для getPatternRule ([c6c332b](https://github.com/chopperqt/react-hook-form-rules/commit/c6c332b5e8c8ab9723b00b7f52e940ea3233f1da))
|
|
10
|
+
|
|
11
|
+
### 🔥 Code Refactoring
|
|
12
|
+
|
|
13
|
+
* дОбавлена базовая ошибка в getPatternRule ([e2260ac](https://github.com/chopperqt/react-hook-form-rules/commit/e2260acb265c0b4807546f7139f00b233b8ea301))
|
|
14
|
+
|
|
15
|
+
### 🧪 Tests
|
|
16
|
+
|
|
17
|
+
* добавлены дополнительный текст для getPatternRule ([7536636](https://github.com/chopperqt/react-hook-form-rules/commit/753663692b7b92169227bb829e6087a3261005a9))
|
|
18
|
+
|
|
1
19
|
## [2.3.1](https://github.com/chopperqt/react-hook-form-rules/compare/v2.3.0...v2.3.1) (2026-03-15)
|
|
2
20
|
|
|
3
21
|
### 💿 Continuous Integration
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# react-hook-form-rules
|
|
1
|
+
# @chopperqt/react-hook-form-rules
|
|
2
2
|
|
|
3
3
|
This is a small library that contains rules for clearer validation handling in the [react-hook-form](https://www.react-hook-form.com/) library.
|
|
4
4
|
|
|
@@ -22,7 +22,7 @@ This rule makes the field required.
|
|
|
22
22
|
#### Code example
|
|
23
23
|
|
|
24
24
|
```
|
|
25
|
-
import { getRequiredRule } from 'react-hook-form-rules';
|
|
25
|
+
import { getRequiredRule } from '@chopperqt/react-hook-form-rules';
|
|
26
26
|
|
|
27
27
|
const {...} = useController({
|
|
28
28
|
rules: {{
|
|
@@ -47,7 +47,7 @@ This rule returns an error if the number is greater than the specified value.
|
|
|
47
47
|
#### Code example
|
|
48
48
|
|
|
49
49
|
```
|
|
50
|
-
import { getMaxRule } from 'react-hook-form-rules';
|
|
50
|
+
import { getMaxRule } from '@chopperqt/@chopperqt/react-hook-form-rules';
|
|
51
51
|
|
|
52
52
|
const {...} = useController({
|
|
53
53
|
rules: {{
|
|
@@ -72,7 +72,7 @@ This rule checks that the string contains a minimum number of characters.
|
|
|
72
72
|
#### Code example
|
|
73
73
|
|
|
74
74
|
```
|
|
75
|
-
import { getMinRule } from 'react-hook-form-rules';
|
|
75
|
+
import { getMinRule } from '@chopperqt/@chopperqt/react-hook-form-rules';
|
|
76
76
|
|
|
77
77
|
const {...} = useController({
|
|
78
78
|
rules: {{
|
|
@@ -97,7 +97,7 @@ This rule checks that the number of characters in the string does not exceed the
|
|
|
97
97
|
#### Code example
|
|
98
98
|
|
|
99
99
|
```
|
|
100
|
-
import { getMaxLengthRule } from 'react-hook-form-rules';
|
|
100
|
+
import { getMaxLengthRule } from '@chopperqt/@chopperqt/react-hook-form-rules';
|
|
101
101
|
|
|
102
102
|
const {...} = useController({
|
|
103
103
|
rules: {{
|
|
@@ -122,7 +122,7 @@ The rule checks that the string contains at least the specified number of charac
|
|
|
122
122
|
#### Code example
|
|
123
123
|
|
|
124
124
|
```
|
|
125
|
-
import { getMinLengthRule } from 'react-hook-form-rules';
|
|
125
|
+
import { getMinLengthRule } from '@chopperqt/@chopperqt/react-hook-form-rules';
|
|
126
126
|
|
|
127
127
|
const {...} = useController({
|
|
128
128
|
rules: {{
|
|
@@ -149,7 +149,7 @@ This rule makes the array field required.
|
|
|
149
149
|
#### Code example
|
|
150
150
|
|
|
151
151
|
```
|
|
152
|
-
import { getRequiredArrayRule } from 'react-hook-form-rules';
|
|
152
|
+
import { getRequiredArrayRule } from '@chopperqt/@chopperqt/react-hook-form-rules';
|
|
153
153
|
|
|
154
154
|
const {...} = useController({
|
|
155
155
|
rules: {{
|
|
@@ -175,7 +175,7 @@ This rule returns an error if the number of values in the array exceeds the spec
|
|
|
175
175
|
#### Code example
|
|
176
176
|
|
|
177
177
|
```
|
|
178
|
-
import { getMaxArrayLengthRule } from 'react-hook-form-rules';
|
|
178
|
+
import { getMaxArrayLengthRule } from '@chopperqt/@chopperqt/react-hook-form-rules';
|
|
179
179
|
|
|
180
180
|
const {...} = useController({
|
|
181
181
|
rules: {{
|
|
@@ -201,7 +201,7 @@ The rule checks that the array contains a minimum number of elements.
|
|
|
201
201
|
#### Code example
|
|
202
202
|
|
|
203
203
|
```
|
|
204
|
-
import { getMinArrayLengthRule } from 'react-hook-form-rules';
|
|
204
|
+
import { getMinArrayLengthRule } from '@chopperqt/@chopperqt/react-hook-form-rules';
|
|
205
205
|
|
|
206
206
|
const {...} = useController({
|
|
207
207
|
rules: {{
|
|
@@ -228,7 +228,7 @@ This rule makes the object field required.
|
|
|
228
228
|
#### Code example
|
|
229
229
|
|
|
230
230
|
```
|
|
231
|
-
import { getRequiredObjectRule } from 'react-hook-form-rules';
|
|
231
|
+
import { getRequiredObjectRule } from '@chopperqt/@chopperqt/react-hook-form-rules';
|
|
232
232
|
|
|
233
233
|
const {...} = useController({
|
|
234
234
|
rules: {{
|
|
@@ -239,11 +239,36 @@ const {...} = useController({
|
|
|
239
239
|
|
|
240
240
|
## URL
|
|
241
241
|
|
|
242
|
+
### getPatternRule
|
|
243
|
+
|
|
244
|
+
#### Description
|
|
245
|
+
|
|
246
|
+
The rule checks pattern by RegExp
|
|
247
|
+
|
|
248
|
+
#### Options
|
|
249
|
+
|
|
250
|
+
| Option | Type | Default | Description |
|
|
251
|
+
| ------- | ------ | ------------------------------------------------------------ | ------------------- |
|
|
252
|
+
| pattern | RegExp | - | Regular expression. |
|
|
253
|
+
| message | string | "Invalid characters" | Custom message |
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
#### Code example
|
|
257
|
+
```
|
|
258
|
+
import { getEmailRule } from '@chopperqt/@chopperqt/react-hook-form-rules';
|
|
259
|
+
|
|
260
|
+
const {...} = useController({
|
|
261
|
+
rules: {{
|
|
262
|
+
pattern: getPatternRule(pattern)
|
|
263
|
+
}}
|
|
264
|
+
})
|
|
265
|
+
```
|
|
266
|
+
|
|
242
267
|
### getEmailRule
|
|
243
268
|
|
|
244
269
|
#### Description
|
|
245
270
|
|
|
246
|
-
|
|
271
|
+
The rule checks the entered email for correctness.
|
|
247
272
|
|
|
248
273
|
#### Options
|
|
249
274
|
|
|
@@ -256,7 +281,7 @@ he rule checks the entered email for correctness.
|
|
|
256
281
|
#### Code example
|
|
257
282
|
|
|
258
283
|
```
|
|
259
|
-
import { getEmailRule } from 'react-hook-form-rules';
|
|
284
|
+
import { getEmailRule } from '@chopperqt/@chopperqt/react-hook-form-rules';
|
|
260
285
|
|
|
261
286
|
const {...} = useController({
|
|
262
287
|
rules: {{
|
|
@@ -282,7 +307,7 @@ The rule checks the entered URL for correctness.
|
|
|
282
307
|
#### Code example
|
|
283
308
|
|
|
284
309
|
```
|
|
285
|
-
import { getUrlRule } from 'react-hook-form-rules';
|
|
310
|
+
import { getUrlRule } from '@chopperqt/@chopperqt/react-hook-form-rules';
|
|
286
311
|
|
|
287
312
|
const {...} = useController({
|
|
288
313
|
rules: {{
|
package/dist/cjs/locales/en.json
CHANGED
|
@@ -7,5 +7,6 @@
|
|
|
7
7
|
"minLength": "Minimum length - {{min}}.",
|
|
8
8
|
"maxLength": "Maximum length - {{max}}.",
|
|
9
9
|
"email": "Please check the correctness of the entered email address.",
|
|
10
|
-
"url": "The URL does not match the format."
|
|
10
|
+
"url": "The URL does not match the format.",
|
|
11
|
+
"pattern": "Invalid characters"
|
|
11
12
|
}
|
package/dist/cjs/locales/ru.json
CHANGED
|
@@ -7,5 +7,6 @@
|
|
|
7
7
|
"minLength": "Минимальная длина - {{min}}.",
|
|
8
8
|
"maxLength": "Максимальная длина - {{max}}.",
|
|
9
9
|
"email": "Проверьте правильность введенного адреса электронной почты.",
|
|
10
|
-
"url": "URL не соответствует формату."
|
|
10
|
+
"url": "URL не соответствует формату.",
|
|
11
|
+
"pattern": "Недопустимые символы"
|
|
11
12
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns a rule that validates the pattern.
|
|
3
|
-
* @param
|
|
4
|
-
* @param
|
|
5
|
-
* @param options.message - Custom message.
|
|
3
|
+
* @param pattern - Regular expression.
|
|
4
|
+
* @param message - Custom message.
|
|
6
5
|
*
|
|
7
6
|
* @example rules: { pattern: getPatternRule(pattern) }
|
|
8
7
|
*/
|
|
9
|
-
export declare const getPatternRule: (pattern: RegExp, message
|
|
8
|
+
export declare const getPatternRule: (pattern: RegExp, message?: string) => {
|
|
10
9
|
value: RegExp;
|
|
11
10
|
message: string;
|
|
12
11
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPatternRule = void 0;
|
|
4
|
+
const _locales_1 = require("@locales");
|
|
4
5
|
/**
|
|
5
6
|
* Returns a rule that validates the pattern.
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @param options.message - Custom message.
|
|
7
|
+
* @param pattern - Regular expression.
|
|
8
|
+
* @param message - Custom message.
|
|
9
9
|
*
|
|
10
10
|
* @example rules: { pattern: getPatternRule(pattern) }
|
|
11
11
|
*/
|
|
12
|
-
const getPatternRule = (pattern, message) => ({
|
|
12
|
+
const getPatternRule = (pattern, message = (0, _locales_1.translate)(_locales_1.TranslateKey.PATTERN)) => ({
|
|
13
13
|
value: pattern,
|
|
14
14
|
message,
|
|
15
15
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const _locales_1 = require("@locales");
|
|
3
4
|
const get_pattern_rule_1 = require("@rules/patterns/get-pattern-rule");
|
|
4
5
|
describe('Тестирование функции getEmailRule', () => {
|
|
5
6
|
test('Проверка кастомного сообщения', () => {
|
|
@@ -8,4 +9,10 @@ describe('Тестирование функции getEmailRule', () => {
|
|
|
8
9
|
value: /-/
|
|
9
10
|
});
|
|
10
11
|
});
|
|
12
|
+
test('Проверка базового сообщения', () => {
|
|
13
|
+
expect((0, get_pattern_rule_1.getPatternRule)(/-/)).toEqual({
|
|
14
|
+
message: (0, _locales_1.translate)(_locales_1.TranslateKey.PATTERN),
|
|
15
|
+
value: /-/
|
|
16
|
+
});
|
|
17
|
+
});
|
|
11
18
|
});
|
package/dist/esm/locales/en.json
CHANGED
|
@@ -7,5 +7,6 @@
|
|
|
7
7
|
"minLength": "Minimum length - {{min}}.",
|
|
8
8
|
"maxLength": "Maximum length - {{max}}.",
|
|
9
9
|
"email": "Please check the correctness of the entered email address.",
|
|
10
|
-
"url": "The URL does not match the format."
|
|
10
|
+
"url": "The URL does not match the format.",
|
|
11
|
+
"pattern": "Invalid characters"
|
|
11
12
|
}
|
package/dist/esm/locales/ru.json
CHANGED
|
@@ -7,5 +7,6 @@
|
|
|
7
7
|
"minLength": "Минимальная длина - {{min}}.",
|
|
8
8
|
"maxLength": "Максимальная длина - {{max}}.",
|
|
9
9
|
"email": "Проверьте правильность введенного адреса электронной почты.",
|
|
10
|
-
"url": "URL не соответствует формату."
|
|
10
|
+
"url": "URL не соответствует формату.",
|
|
11
|
+
"pattern": "Недопустимые символы"
|
|
11
12
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { translate, TranslateKey, } from '@locales';
|
|
1
2
|
/**
|
|
2
3
|
* Returns a rule that validates the pattern.
|
|
3
|
-
* @param
|
|
4
|
-
* @param
|
|
5
|
-
* @param options.message - Custom message.
|
|
4
|
+
* @param pattern - Regular expression.
|
|
5
|
+
* @param message - Custom message.
|
|
6
6
|
*
|
|
7
7
|
* @example rules: { pattern: getPatternRule(pattern) }
|
|
8
8
|
*/
|
|
9
|
-
export const getPatternRule = (pattern, message) => ({
|
|
9
|
+
export const getPatternRule = (pattern, message = translate(TranslateKey.PATTERN)) => ({
|
|
10
10
|
value: pattern,
|
|
11
11
|
message,
|
|
12
12
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { translate, TranslateKey, } from "@locales";
|
|
1
2
|
import { getPatternRule } from "@rules/patterns/get-pattern-rule";
|
|
2
3
|
describe('Тестирование функции getEmailRule', () => {
|
|
3
4
|
test('Проверка кастомного сообщения', () => {
|
|
@@ -6,4 +7,10 @@ describe('Тестирование функции getEmailRule', () => {
|
|
|
6
7
|
value: /-/
|
|
7
8
|
});
|
|
8
9
|
});
|
|
10
|
+
test('Проверка базового сообщения', () => {
|
|
11
|
+
expect(getPatternRule(/-/)).toEqual({
|
|
12
|
+
message: translate(TranslateKey.PATTERN),
|
|
13
|
+
value: /-/
|
|
14
|
+
});
|
|
15
|
+
});
|
|
9
16
|
});
|