react-hook-form-rules 1.0.10 → 1.0.12

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/README.md CHANGED
@@ -20,8 +20,8 @@ This rule makes the field required.
20
20
  #### Options
21
21
  | Option | Type | Default | Description |
22
22
  | -------- | --------- | ------ | ---------- |
23
- | isRequired | boolean | true | |
24
- | message | string | "This field is required." | . |
23
+ | isRequired | boolean | true | Dynamic parameter that indicates whether the field is required. |
24
+ | message | string | "This field is required." | Custom message. |
25
25
 
26
26
  #### Code example
27
27
  ```
@@ -48,8 +48,8 @@ This rule makes the array field required.
48
48
  #### Options
49
49
  | Option | Type | Default | Description |
50
50
  | -------- | --------- | ------ | ---------- |
51
- | arr | array | [] | |
52
- | message | string | "This field is required." | |
51
+ | arr | array | - | Array of values. |
52
+ | message | string | "This field is required." | Custom message. |
53
53
 
54
54
 
55
55
  #### Code example
@@ -76,8 +76,8 @@ This rule makes the object field required.
76
76
  #### Options
77
77
  | Option | Type | Default | Description |
78
78
  | -------- | --------- | ------ | ---------- |
79
- | obj | object | {} | |
80
- | message | string | "This field is required." | |
79
+ | obj | object | - | Object with values. |
80
+ | message | string | "This field is required." | Custom message. |
81
81
 
82
82
 
83
83
  #### Code example
@@ -102,8 +102,8 @@ This rule returns an error if the number is greater than the specified value.
102
102
  #### Options
103
103
  | Option | Type | Default | Description |
104
104
  | -------- | --------- | ------ | ---------- |
105
- | max | number | - | - |
106
- | message | string | - | - |
105
+ | max | number | - | Maximum number. |
106
+ | message | string | - | Custom message. |
107
107
 
108
108
  #### Code example
109
109
  ```
@@ -127,8 +127,8 @@ This rule checks that the number of characters in the string does not exceed the
127
127
  #### Options
128
128
  | Option | Type | Default | Description |
129
129
  | -------- | --------- | ------ | ---------- |
130
- | maxLength | number | - | - |
131
- | message | string | - | - |
130
+ | maxLength | number | - | Maximum number of characters allowed. |
131
+ | message | string | - | Custom message. |
132
132
 
133
133
  ### Code example
134
134
  ```
@@ -153,9 +153,9 @@ This rule returns an error if the number of values in the array exceeds the spec
153
153
  #### Options
154
154
  | Option | Type | Default | Description |
155
155
  | -------- | --------- | ------ | ---------- |
156
- | arr | arrray | - | - |
157
- | maxLength | number | - | - |
158
- | message | string | - | - |
156
+ | arr | arrray | - | Array of values. |
157
+ | maxLength | number | - | Maximum number of values. |
158
+ | message | string | - | Custom message |
159
159
 
160
160
  #### Code example
161
161
  ```
@@ -178,8 +178,8 @@ This rule checks that the string contains a minimum number of characters.
178
178
  #### Options
179
179
  | Option | Type | Default | Description |
180
180
  | -------- | --------- | ------ | ---------- |
181
- | min | number | - | - |
182
- | message | string | - | - |
181
+ | min | number | - | Minimum number. |
182
+ | message | string | - | Custom message. |
183
183
 
184
184
  #### Code example
185
185
  ```
@@ -203,8 +203,8 @@ The rule checks that the string contains at least the specified number of charac
203
203
  #### Options
204
204
  | Option | Type | Default | Description |
205
205
  | -------- | --------- | ------ | ---------- |
206
- | minLength | number | - | - |
207
- | message | string | - | - |
206
+ | minLength | number | - | Minimum number of characters allowed. |
207
+ | message | string | - | Custom message |
208
208
 
209
209
  #### Code example
210
210
  ```
@@ -228,9 +228,9 @@ The rule checks that the array contains a minimum number of elements.
228
228
  #### Options
229
229
  | Option | Type | Default | Description |
230
230
  | -------- | --------- | ------ | ---------- |
231
- | arr | arrray | - | - |
232
- | minLength | number | - | - |
233
- | message | string | - | - |
231
+ | arr | arrray | - | Array of values. |
232
+ | minLength | number | - | Maximum number of values. |
233
+ | message | string | - | Custom message |
234
234
 
235
235
  #### Code example
236
236
  ```
@@ -251,8 +251,9 @@ he rule checks the entered email for correctness.
251
251
  #### Options
252
252
  | Option | Type | Default | Description |
253
253
  | -------- | --------- | ------ | ---------- |
254
- | pattern | RegExp | - | - |
255
- | message | string | - | - |
254
+ | props | object | - | Object with values |
255
+ | props.pattern | RegExp | - | Regular expression. |
256
+ | props.message | string | - | Custom message |
256
257
 
257
258
  #### Code example
258
259
  ```
@@ -276,8 +277,9 @@ The rule checks the entered URL for correctness.
276
277
  #### Options
277
278
  | Option | Type | Default | Description |
278
279
  | -------- | --------- | ------ | ---------- |
279
- | pattern | RegExp | - | - |
280
- | message | string | - | - |
280
+ | props | object | - | Object with values |
281
+ | props.pattern | RegExp | - | Regular expression. |
282
+ | props.message | string | - | Custom message |
281
283
 
282
284
  #### Code example
283
285
  ```
@@ -289,7 +291,3 @@ const {...} = useController({
289
291
  }}
290
292
  })
291
293
  ```
292
-
293
-
294
-
295
-
@@ -5,4 +5,4 @@
5
5
  *
6
6
  * @example rules: { validate: (arr) => getRequiredArrayRule(arr) }
7
7
  */
8
- export declare const getRequiredArrayRule: (arr?: unknown[], message?: string) => string | true;
8
+ export declare const getRequiredArrayRule: (arr: unknown[], message?: string) => string | true;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getRequiredArrayRule = void 0;
4
- const REQUIRED_MESSAGE_TEXT = 'Это поле обязательное.';
4
+ const constants_1 = require("../constants");
5
5
  /**
6
6
  * Validates an array, checking if it contains values.
7
7
  * @param arr - Array of values.
@@ -9,7 +9,7 @@ const REQUIRED_MESSAGE_TEXT = 'Это поле обязательное.';
9
9
  *
10
10
  * @example rules: { validate: (arr) => getRequiredArrayRule(arr) }
11
11
  */
12
- const getRequiredArrayRule = (arr = [], message) => {
13
- return arr.length > 0 || (message || REQUIRED_MESSAGE_TEXT);
12
+ const getRequiredArrayRule = (arr, message) => {
13
+ return arr.length > 0 || (message || constants_1.REQUIRED_MESSAGE_TEXT);
14
14
  };
15
15
  exports.getRequiredArrayRule = getRequiredArrayRule;
@@ -0,0 +1 @@
1
+ export declare const REQUIRED_MESSAGE_TEXT = "This field is required.";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.REQUIRED_MESSAGE_TEXT = void 0;
4
+ exports.REQUIRED_MESSAGE_TEXT = 'This field is required.';
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getMaxLengthRule = void 0;
7
- const plural_ru_1 = __importDefault(require("plural-ru"));
8
4
  /**
9
5
  * Validates the maximum length of a string.
10
6
  * @param maxLength - Maximum number of characters allowed.
@@ -13,7 +9,7 @@ const plural_ru_1 = __importDefault(require("plural-ru"));
13
9
  * @example rules: { maxLength: getMaxLengthRule(1000) }
14
10
  */
15
11
  const getMaxLengthRule = (maxLength, message) => {
16
- const formattedMessage = `Максимальная длина ${maxLength} ${(0, plural_ru_1.default)(maxLength, "символ", "символа", "символов")}.`;
12
+ const formattedMessage = `Maximum length - ${maxLength}`;
17
13
  return {
18
14
  value: maxLength,
19
15
  message: message || formattedMessage,
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getMinLengthRule = void 0;
7
- const plural_ru_1 = __importDefault(require("plural-ru"));
8
4
  /**
9
5
  * Returns a rule that validates the minimum length of a string.
10
6
  * @param minLength - Minimum number of characters allowed.
@@ -13,7 +9,7 @@ const plural_ru_1 = __importDefault(require("plural-ru"));
13
9
  * @example rules: { minLength: getMinLengthRule(20) }
14
10
  */
15
11
  const getMinLengthRule = (minLength, message) => {
16
- const formattedMessage = `Минимальная длина ${minLength} ${(0, plural_ru_1.default)(minLength, "символ", "символа", "символов")}.`;
12
+ const formattedMessage = `Minimum length - ${minLength}`;
17
13
  return {
18
14
  value: minLength,
19
15
  message: message || formattedMessage,
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getRequiredRule = void 0;
4
- const REQUIRED_MESSAGE_TEXT = 'Это поле обязательное.';
4
+ const constants_1 = require("../constants");
5
5
  /**
6
6
  * Validates a required field.
7
7
  * @param isRequired - Dynamic parameter that indicates whether the field is required.
@@ -9,7 +9,7 @@ const REQUIRED_MESSAGE_TEXT = 'Это поле обязательное.';
9
9
  *
10
10
  * @example rules: { required: getRequiredRule() }
11
11
  */
12
- const getRequiredRule = (isRequired = true, message = REQUIRED_MESSAGE_TEXT) => ({
12
+ const getRequiredRule = (isRequired = true, message = constants_1.REQUIRED_MESSAGE_TEXT) => ({
13
13
  value: isRequired,
14
14
  message,
15
15
  });
@@ -5,4 +5,4 @@
5
5
  *
6
6
  * @example rules: { validate: (obj) => getRequiredObjectRule(obj) }
7
7
  */
8
- export declare const getRequiredObjectRule: (obj?: Record<string, unknown>, message?: string) => string | true;
8
+ export declare const getRequiredObjectRule: (obj: Record<string, unknown>, message?: string) => string | true;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getRequiredObjectRule = void 0;
4
- const REQUIRED_MESSAGE_TEXT = 'Это поле обязательное.';
4
+ const constants_1 = require("../constants");
5
5
  /**
6
6
  * Validates an object, checking if it contains values.
7
7
  * @param obj - Object with values.
@@ -9,9 +9,9 @@ const REQUIRED_MESSAGE_TEXT = 'Это поле обязательное.';
9
9
  *
10
10
  * @example rules: { validate: (obj) => getRequiredObjectRule(obj) }
11
11
  */
12
- const getRequiredObjectRule = (obj = {}, message) => {
12
+ const getRequiredObjectRule = (obj, message) => {
13
13
  var _a;
14
- const formattedMessage = message || REQUIRED_MESSAGE_TEXT;
14
+ const formattedMessage = message || constants_1.REQUIRED_MESSAGE_TEXT;
15
15
  if (!obj) {
16
16
  return false || formattedMessage;
17
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-hook-form-rules",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -9,6 +9,10 @@
9
9
  "build": "tsc --declaration",
10
10
  "deploy": "npm run build && npm publish"
11
11
  },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/chopperqt/react-hook-form-rules"
15
+ },
12
16
  "keywords": [],
13
17
  "author": "",
14
18
  "license": "ISC",
@@ -1,4 +1,4 @@
1
- const REQUIRED_MESSAGE_TEXT = 'Это поле обязательное.';
1
+ import { REQUIRED_MESSAGE_TEXT } from "../constants";
2
2
 
3
3
  /**
4
4
  * Validates an array, checking if it contains values.
@@ -7,6 +7,6 @@ const REQUIRED_MESSAGE_TEXT = 'Это поле обязательное.';
7
7
  *
8
8
  * @example rules: { validate: (arr) => getRequiredArrayRule(arr) }
9
9
  */
10
- export const getRequiredArrayRule = (arr: unknown[] = [], message?: string) => {
10
+ export const getRequiredArrayRule = (arr: unknown[], message?: string) => {
11
11
  return arr.length > 0 || (message || REQUIRED_MESSAGE_TEXT);
12
12
  };
@@ -0,0 +1 @@
1
+ export const REQUIRED_MESSAGE_TEXT = 'This field is required.';
@@ -1,5 +1,3 @@
1
- import plural from "plural-ru";
2
-
3
1
  /**
4
2
  * Validates the maximum length of a string.
5
3
  * @param maxLength - Maximum number of characters allowed.
@@ -8,12 +6,7 @@ import plural from "plural-ru";
8
6
  * @example rules: { maxLength: getMaxLengthRule(1000) }
9
7
  */
10
8
  export const getMaxLengthRule = (maxLength: number, message?: string) => {
11
- const formattedMessage = `Максимальная длина ${maxLength} ${plural(
12
- maxLength,
13
- "символ",
14
- "символа",
15
- "символов",
16
- )}.`;
9
+ const formattedMessage = `Maximum length - ${maxLength}`;
17
10
 
18
11
  return {
19
12
  value: maxLength,
@@ -1,5 +1,3 @@
1
- import plural from "plural-ru";
2
-
3
1
  /**
4
2
  * Returns a rule that validates the minimum length of a string.
5
3
  * @param minLength - Minimum number of characters allowed.
@@ -8,12 +6,7 @@ import plural from "plural-ru";
8
6
  * @example rules: { minLength: getMinLengthRule(20) }
9
7
  */
10
8
  export const getMinLengthRule = (minLength: number, message?: string) => {
11
- const formattedMessage = `Минимальная длина ${minLength} ${plural(
12
- minLength,
13
- "символ",
14
- "символа",
15
- "символов",
16
- )}.`;
9
+ const formattedMessage = `Minimum length - ${minLength}`;
17
10
 
18
11
  return {
19
12
  value: minLength,
@@ -1,4 +1,4 @@
1
- const REQUIRED_MESSAGE_TEXT = 'Это поле обязательное.';
1
+ import { REQUIRED_MESSAGE_TEXT } from "../constants";
2
2
 
3
3
  /**
4
4
  * Validates a required field.
@@ -1,4 +1,4 @@
1
- const REQUIRED_MESSAGE_TEXT = 'Это поле обязательное.';
1
+ import { REQUIRED_MESSAGE_TEXT } from "../constants";
2
2
 
3
3
  /**
4
4
  * Validates an object, checking if it contains values.
@@ -7,7 +7,7 @@ const REQUIRED_MESSAGE_TEXT = 'Это поле обязательное.';
7
7
  *
8
8
  * @example rules: { validate: (obj) => getRequiredObjectRule(obj) }
9
9
  */
10
- export const getRequiredObjectRule = (obj: Record<string, unknown> = {}, message?: string) => {
10
+ export const getRequiredObjectRule = (obj: Record<string, unknown>, message?: string) => {
11
11
  const formattedMessage = message || REQUIRED_MESSAGE_TEXT;
12
12
 
13
13
  if (!obj) {
@@ -1,9 +0,0 @@
1
- const MIN_TEXT = 'Минимальное значение '
2
-
3
- /**
4
- * Генирирует сообщение об ошибке.
5
- * @param min - Минимальное значение.
6
- */
7
- const getMinError = (min: number) => {
8
- return `${MIN_TEXT}${min}`
9
- }
@@ -1,9 +0,0 @@
1
- const MIN_LENGTH_TEXT = 'Минимальное кол-во символов '
2
-
3
- /**
4
- * Генерирует сообщение об ошибке.
5
- * @param length - Количество символов.
6
- */
7
- const getMinLengthError = (length: number) => {
8
- return `${MIN_LENGTH_TEXT}${length}.`
9
- }