react-hook-form-rules 1.7.3 → 1.7.4

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 (36) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +12 -1
  3. package/.github/workflows/release.yml +0 -53
  4. package/.github/workflows/test.yml +0 -17
  5. package/i18n.ts +0 -28
  6. package/index.ts +0 -36
  7. package/jest.config.js +0 -8
  8. package/locales/en.json +0 -12
  9. package/locales/ru.json +0 -11
  10. package/release.config.cjs +0 -81
  11. package/rules/array/get-max-array-length-rule.ts +0 -19
  12. package/rules/array/get-min-array-length-rule.ts +0 -19
  13. package/rules/array/get-required-array-rule.ts +0 -12
  14. package/rules/array/tests/get-max-array-length-rule.test.ts +0 -17
  15. package/rules/array/tests/get-min-array-length-rule.test.ts +0 -17
  16. package/rules/array/tests/get-required-array-rule.test.ts +0 -16
  17. package/rules/constants.ts +0 -1
  18. package/rules/default/get-max-length-rule.ts +0 -15
  19. package/rules/default/get-max-rule.ts +0 -13
  20. package/rules/default/get-min-length-rule.ts +0 -16
  21. package/rules/default/get-min-rule.ts +0 -15
  22. package/rules/default/get-require-rule.ts +0 -16
  23. package/rules/default/tests/get-max-length-rule.test.ts +0 -24
  24. package/rules/default/tests/get-max-rule.test.ts +0 -24
  25. package/rules/default/tests/get-min-length-rule.test.ts +0 -24
  26. package/rules/default/tests/get-min-rule.test.ts +0 -24
  27. package/rules/default/tests/get-required-rule.test.ts +0 -10
  28. package/rules/object/get-required-object-rule.ts +0 -20
  29. package/rules/object/tests/get-require-object-rule.test.ts +0 -18
  30. package/rules/patterns/get-email-rule.ts +0 -22
  31. package/rules/patterns/get-pattern-rule.ts +0 -12
  32. package/rules/patterns/get-url-rule.ts +0 -23
  33. package/rules/patterns/tests/get-email-rule.test.ts +0 -27
  34. package/rules/patterns/tests/get-pattern-rule.test.ts +0 -10
  35. package/rules/patterns/tests/get-url-rule.test.ts +0 -28
  36. package/tsconfig.json +0 -12
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [1.7.4](https://github.com/chopperqt/react-hook-form-rules/compare/v1.7.3...v1.7.4) (2025-12-28)
2
+
3
+ ### 🐞 Bug Fixes
4
+
5
+ * исправлен импорт i18n ([ed61898](https://github.com/chopperqt/react-hook-form-rules/commit/ed61898b211aba638837104ec3215e84840c444b))
6
+ * исправление конфликтов ([9ae79a4](https://github.com/chopperqt/react-hook-form-rules/commit/9ae79a4b9328afba1fcb2250e64fa3836edc4f87))
7
+ * испралвение package.json ([8165b1a](https://github.com/chopperqt/react-hook-form-rules/commit/8165b1ad0ab39b0ad28bb92a3ba14ee976f17378))
8
+
1
9
  ## [1.7.3](https://github.com/chopperqt/react-hook-form-rules/compare/v1.7.2...v1.7.3) (2025-12-28)
2
10
 
3
11
  ### 🐞 Bug Fixes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-hook-form-rules",
3
- "version": "1.7.3",
3
+ "version": "1.7.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,6 +12,11 @@
12
12
  "deploy": "npm run build && npm publish",
13
13
  "commit": "cz"
14
14
  },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "CHANGELOG.md"
19
+ ],
15
20
  "keywords": [],
16
21
  "author": "chopperqt",
17
22
  "license": "ISC",
@@ -19,6 +24,12 @@
19
24
  "@types/node": "^22.7.0",
20
25
  "typescript": "^5.6.2"
21
26
  },
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "require": "./dist/index.js"
31
+ }
32
+ },
22
33
  "devDependencies": {
23
34
  "@semantic-release/changelog": "^6.0.3",
24
35
  "@semantic-release/exec": "^7.0.3",
@@ -1,53 +0,0 @@
1
- name: Release and Publish
2
-
3
- on:
4
- push:
5
- branches:
6
- - release
7
-
8
- permissions:
9
- contents: write
10
- packages: write
11
- issues: write # to be able to comment on released issues
12
- pull-requests: write # to be able to comment on released pull requests
13
- id-token: write
14
-
15
- jobs:
16
- release:
17
- runs-on: ubuntu-latest
18
- env:
19
- GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
21
- GH_PACKAGES_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}
22
-
23
- steps:
24
- - name: Checkout repository
25
- uses: actions/checkout@v4
26
- with:
27
- fetch-depth: 0
28
-
29
- - name: Setup Node.js
30
- uses: actions/setup-node@v4
31
- with:
32
- node-version: 20
33
-
34
- - name: Install dependencies
35
- run: npm ci
36
-
37
- - name: Authenticate with npm
38
- run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
39
-
40
- - name: Authenticate with GitHub Packages
41
- run: echo "@chopperqt:registry=https://npm.pkg.github.com/" >> ~/.npmrc && echo "//npm.pkg.github.com/:_authToken=${{ secrets.GH_PACKAGES_TOKEN }}" >> ~/.npmrc
42
-
43
- - name: Check .npmrc
44
- run: npm run check-npmrc
45
-
46
- - name: Debug env variables
47
- run: |
48
- echo "NPM_TOKEN=${{ secrets.NPM_TOKEN }}"
49
- echo "GH_PACKAGES_TOKEN=${{ secrets.GH_PACKAGES_TOKEN }}"
50
- echo $NPM_TOKEN | wc -c
51
-
52
- - name: Run semantic-release
53
- run: npx semantic-release
@@ -1,17 +0,0 @@
1
- name: Unit Tests
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
-
8
- jobs:
9
- test:
10
- runs-on: ubuntu-latest
11
- steps:
12
- - uses: actions/checkout@v3
13
- - uses: actions/setup-node@v3
14
- with:
15
- node-version: 20
16
- - run: npm ci
17
- - run: npm run test
package/i18n.ts DELETED
@@ -1,28 +0,0 @@
1
- import en from './locales/en.json'
2
- import ru from './locales/ru.json'
3
-
4
- const translataions = {
5
- en,
6
- ru,
7
- };
8
-
9
- let currentLang = 'en'
10
-
11
- export const setLanguage = (lang: string) => {
12
- if ((translataions as any)[lang]) {
13
- currentLang = lang;
14
- } else {
15
- console.warn(`⚠️ Language "${lang}" is not supported. Defaulting to English.`);
16
- }
17
- }
18
-
19
- export const translate = (key: string, params = {}) => {
20
- let text = (translataions as any)[currentLang][key] || key;
21
-
22
- // Подставляем параметры (например, {{min}})
23
- Object.keys(params).forEach((param) => {
24
- text = text.replace(`{{${param}}}`, (params as any)[param]);
25
- });
26
-
27
- return text;
28
- }
package/index.ts DELETED
@@ -1,36 +0,0 @@
1
- import { getEmailRule } from "./rules/patterns/get-email-rule";
2
- import { getUrlRule } from "./rules/patterns/get-url-rule";
3
- import { getPatternRule } from "./rules/patterns/get-pattern-rule";
4
-
5
- import { getMaxArrayLengthRule } from "./rules/array/get-max-array-length-rule";
6
- import { getMinArrayLengthRule } from "./rules/array/get-min-array-length-rule";
7
- import { getRequiredArrayRule } from "./rules/array/get-required-array-rule";
8
-
9
- import { getMaxLengthRule } from "./rules/default/get-max-length-rule";
10
- import { getMaxRule } from "./rules/default/get-max-rule";
11
- import { getMinLengthRule } from "./rules/default/get-min-length-rule";
12
- import { getMinRule } from "./rules/default/get-min-rule";
13
- import { getRequiredRule } from "./rules/default/get-require-rule";
14
-
15
- import { getRequiredObjectRule } from "./rules/object/get-required-object-rule";
16
-
17
- import { translate } from "./i18n";
18
- import { setLanguage } from "./i18n";
19
-
20
- export {
21
- getPatternRule,
22
- getMaxRule,
23
- getRequiredObjectRule,
24
- getRequiredArrayRule,
25
- getEmailRule,
26
- getMaxLengthRule,
27
- getMaxArrayLengthRule,
28
- getMinArrayLengthRule,
29
- getMinLengthRule,
30
- getMinRule,
31
- getRequiredRule,
32
- getUrlRule,
33
- translate,
34
- setLanguage,
35
- };
36
-
package/jest.config.js DELETED
@@ -1,8 +0,0 @@
1
- /** @type {import('ts-jest').JestConfigWithTsJest} **/
2
- module.exports = {
3
- testEnvironment: "node",
4
- transform: {
5
- "^.+\.tsx?$": ["ts-jest", {}],
6
- },
7
- testPathIgnorePatterns: ['./dist']
8
- };
package/locales/en.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "required": "This field is required.",
3
- "maxArrayLength": "Maximum number of values - {{max}}.",
4
- "minArrayLength": "Minimum number of values - {{min}}.",
5
- "min": "Minimum value - {{min}}.",
6
- "max": "Maximum value - {{max}}.",
7
- "minLength": "Minimum length - {{min}}.",
8
- "maxLength": "Maximum length - {{max}}.",
9
- "email": "Please check the correctness of the entered email address.",
10
- "url": "The URL does not match the format."
11
- }
12
-
package/locales/ru.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "required": "Поле объязательное.",
3
- "maxArrayLength": "Максимальное количество значений - {{max}}.",
4
- "minArrayLength": "Минимальное количество значений - {{min}}.",
5
- "min": "Минимальное значение - {{min}}.",
6
- "max": "Максимальное значение - {{max}}.",
7
- "minLength": "Минимальная длина - {{min}}.",
8
- "maxLength": "Максимальная длина - {{max}}.",
9
- "email": "Проверьте правильность введенного адреса электронной почты.",
10
- "url": "URL не соответствует формату."
11
- }
@@ -1,81 +0,0 @@
1
- /**
2
- * @type {import('semantic-release').GlobalConfig}
3
- */
4
- module.exports = {
5
- branches: ["release"],
6
- plugins: [
7
- [
8
- '@semantic-release/commit-analyzer',
9
- {
10
- releaseRules: [
11
- { breaking: true, release: 'major' },
12
- { revert: true, release: 'patch' },
13
- { type: 'feat', release: 'minor' },
14
- { type: 'fix', release: 'patch' },
15
- { type: 'docs', release: 'patch' },
16
- { type: 'style', release: 'patch' },
17
- { type: 'refactor', release: 'patch' },
18
- { type: 'perf', release: 'patch' },
19
- { type: 'test', release: 'patch' },
20
- { type: 'chore', release: 'patch' },
21
- ],
22
- },
23
- ],
24
- [
25
- '@semantic-release/release-notes-generator',
26
- {
27
- parserOpts: {
28
- noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES', 'BREAKING'],
29
- },
30
- preset: 'conventionalcommits',
31
- presetConfig: {
32
- types: [
33
- { type: 'build', section: '📦 Build System', hidden: false },
34
- { type: 'chore', section: '📦 Build System', hidden: true },
35
- { type: 'ci', section: '💿 Continuous Integration', hidden: false },
36
- { type: 'docs', section: '📄 Documentation', hidden: false },
37
- { type: 'feat', section: '🆕 Features', hidden: false },
38
- { type: 'fix', section: '🐞 Bug Fixes', hidden: false },
39
- { type: 'perf', section: '⚡️ Performance Improvements', hidden: false },
40
- { type: 'refactor', section: '🔥 Code Refactoring', hidden: false },
41
- { type: 'style', section: '🛠 Styles', hidden: false },
42
- { type: 'test', section: '🧪 Tests', hidden: false },
43
- ],
44
- },
45
- writerOpts: {
46
- commitsSort: ['subject', 'scope'],
47
- },
48
- },
49
- ],
50
- "@semantic-release/changelog",
51
- [
52
- "@semantic-release/npm",
53
- {
54
- "npmPublish": true,
55
- "pkgRoot": ".",
56
- "publishConfig": {
57
- "registry": "https://registry.npmjs.org/",
58
- }
59
- }
60
- ],
61
- [
62
- "@semantic-release/npm",
63
- {
64
- "npmPublish": false,
65
- "pkgRoot": ".",
66
- "publishConfig": {
67
- "registry": "https://npm.pkg.github.com/",
68
- }
69
- }
70
- ],
71
- [
72
- "@semantic-release/github",
73
- {
74
- assets: [
75
- { path: "dist/*.tgz", label: "Package Distribution" },
76
- ],
77
- },
78
- ],
79
- "@semantic-release/git",
80
- ]
81
- };
@@ -1,19 +0,0 @@
1
- import { translate } from "../../i18n";
2
-
3
- /**
4
- * Validates an array for the maximum number of values.
5
- * @param arr - Array of values.
6
- * @param maxLength - Maximum number of values.
7
- * @param message - Custom message.
8
- *
9
- * @example getMaxArrayLengthRule(2, "Maximum number of values is 2").
10
- */
11
- export const getMaxArrayLengthRule = (
12
- arr: unknown[],
13
- maxLength: number,
14
- message?: string,
15
- ) => {
16
- const formattedMessage = message || translate('maxArrayLength', { max: maxLength });
17
-
18
- return arr.length < maxLength || formattedMessage;
19
- };
@@ -1,19 +0,0 @@
1
- import { translate } from "../../i18n";
2
-
3
- /**
4
- * Validates an array for the maximum number of values.
5
- * @param arr - Array of values.
6
- * @param maxLength - Maximum number of values.
7
- * @param message - Custom message.
8
- *
9
- * @example getMaxArrayLengthRule(3, "Maximum number of values is 2").
10
- */
11
- export const getMinArrayLengthRule = (
12
- arr: unknown[],
13
- minLength: number,
14
- message?: string,
15
- ) => {
16
- const formattedMessage = message || translate('minArrayLength', { min: minLength });
17
-
18
- return arr.length >= minLength || formattedMessage;
19
- };
@@ -1,12 +0,0 @@
1
- import { translate } from "../../i18n";
2
-
3
- /**
4
- * Validates an array, checking if it contains values.
5
- * @param arr - Array of values.
6
- * @param {string} message - Custom message.
7
- *
8
- * @example rules: { validate: (arr) => getRequiredArrayRule(arr) }
9
- */
10
- export const getRequiredArrayRule = (arr: unknown[], message?: string) => {
11
- return arr.length > 0 || (message || translate('required'));
12
- };
@@ -1,17 +0,0 @@
1
- import { getMaxArrayLengthRule } from '../get-max-array-length-rule'
2
-
3
- const MAX_LENGTH = 2;
4
-
5
- describe('Тестирование функции getMaxArrayLengthRule', () => {
6
- test('Проверка, что функция возвращает текстовое сообщение с ошибкой если длинна массива превышает максимальную.', () => {
7
- expect(getMaxArrayLengthRule([1, 2, 3], MAX_LENGTH)).toBe(`Maximum number of values - ${MAX_LENGTH}.`)
8
- })
9
-
10
- test('Проверка, что функция возвращает true, если длинна массива меньше, либо равна максимальной.', () => {
11
- expect(getMaxArrayLengthRule([1], MAX_LENGTH)).toBe(true)
12
- })
13
-
14
- test('Проверка, что функция возвращает кастомное сообщение, если кол-во заначений превышает максимальное.', () => {
15
- expect(getMaxArrayLengthRule([1, 2, 3, 4], MAX_LENGTH, 'test message')).toBe('test message')
16
- })
17
- })
@@ -1,17 +0,0 @@
1
- import { getMinArrayLengthRule } from "../get-min-array-length-rule";
2
-
3
- const MIN_LENGTH = 2;
4
-
5
- describe('Тестирование функции getMinArrayLengthRule', () => {
6
- test('Проверка, что функция возвращает текстовое сообщение с ошибкой если длинна массива меньше минимальной.', () => {
7
- expect(getMinArrayLengthRule([1], MIN_LENGTH)).toBe(`Minimum number of values - ${MIN_LENGTH}.`)
8
- })
9
-
10
- test('Проверка, что функция возвращает true, если длинна массива большe, либо равна минимальной.', () => {
11
- expect(getMinArrayLengthRule([1, 3, 4], MIN_LENGTH)).toBe(true)
12
- })
13
-
14
- test('Проверка, что функция возвращает кастомное сообщение, если кол-во заначений меньше минимальной.', () => {
15
- expect(getMinArrayLengthRule([1], MIN_LENGTH, 'test message')).toBe('test message')
16
- })
17
- })
@@ -1,16 +0,0 @@
1
- import { REQUIRED_MESSAGE_TEXT } from '../../constants'
2
- import { getRequiredArrayRule } from '../get-required-array-rule'
3
-
4
- describe('Тестирование функции getRequiredArrayRule', () => {
5
- test('Проверка, что функция возвращает кастомное сообщение с ошибкой, когда массив не содержит значения.', () => {
6
- expect(getRequiredArrayRule([], 'test message')).toBe('test message')
7
- })
8
-
9
- test('Проверка, что функция возвращает true, когда массив не пустой.', () => {
10
- expect(getRequiredArrayRule([1, 2, 3])).toBe(true)
11
- })
12
-
13
- test('Проверка, что функция возвращает базовое сообщение, когда массив пустой.', () => {
14
- expect(getRequiredArrayRule([])).toBe(REQUIRED_MESSAGE_TEXT)
15
- })
16
- })
@@ -1 +0,0 @@
1
- export const REQUIRED_MESSAGE_TEXT = 'This field is required.';
@@ -1,15 +0,0 @@
1
- import { translate } from "../../i18n";
2
-
3
- /**
4
- * Validates the maximum length of a string.
5
- * @param maxLength - Maximum number of characters allowed.
6
- * @param message - Custom message.
7
- *
8
- * @example rules: { maxLength: getMaxLengthRule(1000) }
9
- */
10
- export const getMaxLengthRule = (maxLength: number, message?: string) => ({
11
- value: maxLength,
12
- message: message || translate('maxLength', {
13
- max: maxLength,
14
- }),
15
- })
@@ -1,13 +0,0 @@
1
- import { translate } from "../../i18n";
2
-
3
- /**
4
- * Returns an error if the number exceeds the specified value.
5
- * @param max - Maximum number.
6
- * @param message - Custom message.
7
- *
8
- * @example rules: { max: getMaxRule(20) }
9
- */
10
- export const getMaxRule = (max: number, message?: string) => ({
11
- value: max,
12
- message: message || translate('max', { max }),
13
- });
@@ -1,16 +0,0 @@
1
- import { translate } from "../../i18n";
2
-
3
- /**
4
- * Returns a rule that validates the minimum length of a string.
5
- * @param minLength - Minimum number of characters allowed.
6
- * @param message - Custom message.
7
- *
8
- * @example rules: { minLength: getMinLengthRule(20) }
9
- */
10
- export const getMinLengthRule = (minLength: number, message?: string) => {
11
-
12
- return {
13
- value: minLength,
14
- message: message || translate('minLength', { min: minLength }),
15
- };
16
- };
@@ -1,15 +0,0 @@
1
- import { translate } from "../../i18n"
2
-
3
- /**
4
- * Returns an error if the number is less than the specified value.
5
- * @param min - Minimum number.
6
- * @param message - Custom message.
7
- *
8
- * @example rules: { min: getMinRule(20) }
9
- */
10
- export const getMinRule = (min: number, message?: string) => ({
11
- value: min,
12
- message: message || translate('min', {
13
- min,
14
- }),
15
- })
@@ -1,16 +0,0 @@
1
- import { translate } from "../../i18n";
2
-
3
- /**
4
- * Validates a required field.
5
- * @param isRequired - Dynamic parameter that indicates whether the field is required.
6
- * @param message - Custom message.
7
- *
8
- * @example rules: { required: getRequiredRule() }
9
- */
10
- export const getRequiredRule = (
11
- isRequired = true,
12
- message = translate('required')
13
- ) => ({
14
- value: isRequired,
15
- message,
16
- })
@@ -1,24 +0,0 @@
1
- import { getMaxLengthRule } from "../get-max-length-rule"
2
-
3
- describe('Тестирование функции getMinLengthRule', () => {
4
- test('Проверка, что функция возвращает кастомное сообщение с ошибкой.', () => {
5
- expect(getMaxLengthRule(1, 'test message')).toEqual({
6
- value: 1,
7
- message: 'test message',
8
- })
9
- })
10
-
11
- test('Проверка, что функция возвращает базовую ошибку.', () => {
12
- expect(getMaxLengthRule(1)).toEqual({
13
- value: 1,
14
- message: `Maximum length - ${1}.`
15
- })
16
- })
17
-
18
- test('Проверка, что функция возвращает базовую ошибку и переданное минимальное значение.', () => {
19
- expect(getMaxLengthRule(111)).toEqual({
20
- value: 111,
21
- message: `Maximum length - 111.`
22
- })
23
- })
24
- })
@@ -1,24 +0,0 @@
1
- import { getMaxRule } from "../get-max-rule"
2
-
3
- describe('Тестирование функции getMaxRule', () => {
4
- test('Проверка, что функция возвращает кастомное сообщение с ошибкой.', () => {
5
- expect(getMaxRule(1, 'test message')).toEqual({
6
- value: 1,
7
- message: 'test message',
8
- })
9
- })
10
-
11
- test('Проверка, что функция возвращает базовую ошибку.', () => {
12
- expect(getMaxRule(1)).toEqual({
13
- value: 1,
14
- message: `Maximum value - 1.`
15
- })
16
- })
17
-
18
- test('Проверка, что функция возвращает базовую ошибку и переданное минимальное значение.', () => {
19
- expect(getMaxRule(111)).toEqual({
20
- value: 111,
21
- message: `Maximum value - 111.`
22
- })
23
- })
24
- })
@@ -1,24 +0,0 @@
1
- import { getMinLengthRule } from "../get-min-length-rule"
2
-
3
- describe('Тестирование функции getMinLengthRule', () => {
4
- test('Проверка, что функция возвращает кастомное сообщение с ошибкой.', () => {
5
- expect(getMinLengthRule(1, 'test message')).toEqual({
6
- value: 1,
7
- message: 'test message',
8
- })
9
- })
10
-
11
- test('Проверка, что функция возвращает базовую ошибку.', () => {
12
- expect(getMinLengthRule(1)).toEqual({
13
- value: 1,
14
- message: `Minimum length - ${1}.`
15
- })
16
- })
17
-
18
- test('Проверка, что функция возвращает базовую ошибку и переданное минимальное значение.', () => {
19
- expect(getMinLengthRule(111)).toEqual({
20
- value: 111,
21
- message: `Minimum length - 111.`
22
- })
23
- })
24
- })
@@ -1,24 +0,0 @@
1
- import { getMinRule } from "../get-min-rule";
2
-
3
- describe('Тестирование функции getMinRule', () => {
4
- test('Проверка, что функция возвращает кастомное сообщение с ошибкой.', () => {
5
- expect(getMinRule(1, 'test message')).toEqual({
6
- value: 1,
7
- message: 'test message',
8
- })
9
- })
10
-
11
- test('Проверка, что функция возвращает базовую ошибку.', () => {
12
- expect(getMinRule(1)).toEqual({
13
- value: 1,
14
- message: `Minimum value - 1.`
15
- })
16
- })
17
-
18
- test('Проверка, что функция возвращает базовую ошибку и переданное минимальное значение.', () => {
19
- expect(getMinRule(111)).toEqual({
20
- value: 111,
21
- message: `Minimum value - 111.`
22
- })
23
- })
24
- })
@@ -1,10 +0,0 @@
1
- import { getRequiredRule } from '../get-require-rule'
2
-
3
- describe('Тестирование функции getRequiredRule', () => {
4
- test('Проверка, что функция возвращает кастомное сообщение с ошибкой.', () => {
5
- expect(getRequiredRule(true, 'test message')).toEqual({
6
- value: true,
7
- message: 'test message',
8
- })
9
- })
10
- })
@@ -1,20 +0,0 @@
1
- import { translate } from "../../i18n";
2
-
3
- /**
4
- * Validates an object, checking if it contains values.
5
- * @param {Object} obj - Object with values.
6
- * @param {string} message - Custom message.
7
- *
8
- * @example rules: { validate: (obj) => getRequiredObjectRule(obj) }
9
- */
10
- export const getRequiredObjectRule = (obj: Record<string, unknown>, message?: string) => {
11
- const formattedMessage = message || translate("required");
12
-
13
- if (!obj) {
14
- return false || formattedMessage;
15
- }
16
-
17
- const isEmpty = Object?.keys(obj)?.length > 0;
18
-
19
- return isEmpty || formattedMessage;
20
- };
@@ -1,18 +0,0 @@
1
- import { REQUIRED_MESSAGE_TEXT } from '../../constants'
2
- import { getRequiredObjectRule } from '../get-required-object-rule'
3
-
4
- describe('Тестирование функции getRequireObjectRule', () => {
5
- test('Проверка, что функция возвращает кастомное сообщение с ошибкой, когда объект не содержит значения.', () => {
6
- expect(getRequiredObjectRule({}, 'test message')).toBe('test message')
7
- })
8
-
9
- test('Проверка, что функция возвращает true, когда объект не пустой.', () => {
10
- expect(getRequiredObjectRule({ test: '123' })).toBe(true)
11
- })
12
-
13
- test('Проверка, что функция возвращает базовое сообщение, когда объект пустой.', () => {
14
- expect(getRequiredObjectRule({})).toBe(REQUIRED_MESSAGE_TEXT)
15
- })
16
- })
17
-
18
-
@@ -1,22 +0,0 @@
1
- import { getPatternRule } from "./get-pattern-rule";
2
- import { translate } from "../../i18n";
3
-
4
- const DEFAULT_PATTERN = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
5
-
6
- interface EmailRule {
7
- pattern?: RegExp;
8
- message?: string;
9
- }
10
-
11
- /**
12
- * Validates an email address.
13
- * @param options - Parameters.
14
- * @param {string} options.pattern - Regular expression.
15
- * @param {string} options.message - Custom message.
16
- *
17
- * @example rules: { pattern: getEmailRule({}) }
18
- */
19
- export const getEmailRule = ({
20
- pattern = DEFAULT_PATTERN,
21
- message = translate('email'),
22
- }: EmailRule) => getPatternRule(pattern, message)
@@ -1,12 +0,0 @@
1
- /**
2
- * Returns a rule that validates the pattern.
3
- * @param options - Parameters.
4
- * @param options.pattern - Regular expression.
5
- * @param options.message - Custom message.
6
- *
7
- * @example rules: { pattern: getPatternRule(pattern) }
8
- */
9
- export const getPatternRule = (pattern: RegExp, message: string) => ({
10
- value: pattern,
11
- message,
12
- })
@@ -1,23 +0,0 @@
1
- import { translate } from "../../i18n";
2
- import { getPatternRule } from "./get-pattern-rule";
3
-
4
- const DEFAULT_PATTERN =
5
- /(http(s)?):\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
6
-
7
- interface UrlRule {
8
- message?: string;
9
- pattern?: RegExp;
10
- }
11
-
12
- /**
13
- * Returns a rule that validates the input URL.
14
- * @param options - Parameters.
15
- * @param options.pattern - Regular expression.
16
- * @param options.message - Custom message.
17
- *
18
- * @example rules: { pattern: getUrlRule() }
19
- */
20
- export const getUrlRule = ({
21
- pattern = DEFAULT_PATTERN,
22
- message = translate('url'),
23
- }: UrlRule) => getPatternRule(pattern, message)
@@ -1,27 +0,0 @@
1
- import { getEmailRule } from "../get-email-rule";
2
-
3
- const DEFAULT_MESSAGE = "Please check the correctness of the entered email address.";
4
- const DEFAULT_PATTERN = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
5
-
6
- describe('Тестирование функции getEmailRule', () => {
7
- test('Проверка значения по умолчанию', () => {
8
- expect(getEmailRule({})).toEqual({
9
- message: DEFAULT_MESSAGE,
10
- value: DEFAULT_PATTERN
11
- });
12
- });
13
-
14
- test('Проверка передачи кастомного сообщения', () => {
15
- expect(getEmailRule({ message: 'Custom message' })).toEqual({
16
- message: 'Custom message',
17
- value: DEFAULT_PATTERN
18
- });
19
- })
20
-
21
- test('Проверка передачи камсного паттерна', () => {
22
- expect(getEmailRule({ pattern: /test/ })).toEqual({
23
- message: DEFAULT_MESSAGE,
24
- value: /test/
25
- });
26
- })
27
- })
@@ -1,10 +0,0 @@
1
- import { getPatternRule } from "../get-pattern-rule";
2
-
3
- describe('Тестирование функции getEmailRule', () => {
4
- test('Проверка кастомного сообщения', () => {
5
- expect(getPatternRule(/-/, 'test message')).toEqual({
6
- message: 'test message',
7
- value: /-/
8
- });
9
- });
10
- })
@@ -1,28 +0,0 @@
1
- import { getUrlRule } from "../get-url-rule";
2
-
3
- const DEFAULT_MESSAGE = "The URL does not match the format.";
4
- const DEFAULT_PATTERN =
5
- /(http(s)?):\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
6
-
7
- describe('Тестирование функции getEmailRule', () => {
8
- test('Проверка значения по умолчанию', () => {
9
- expect(getUrlRule({})).toEqual({
10
- message: DEFAULT_MESSAGE,
11
- value: DEFAULT_PATTERN
12
- });
13
- });
14
-
15
- test('Проверка передачи кастомного сообщения', () => {
16
- expect(getUrlRule({ message: 'Custom message' })).toEqual({
17
- message: 'Custom message',
18
- value: DEFAULT_PATTERN
19
- });
20
- })
21
-
22
- test('Проверка передачи камсного паттерна', () => {
23
- expect(getUrlRule({ pattern: /test/ })).toEqual({
24
- message: DEFAULT_MESSAGE,
25
- value: /test/
26
- });
27
- })
28
- })
package/tsconfig.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
4
- "module": "commonjs" /* Specify what module code is generated. */,
5
- "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
6
- "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
7
- "strict": true /* Enable all strict type-checking options. */,
8
- "skipLibCheck": true /* Skip type checking all .d.ts files. */,
9
- "outDir": "./dist",
10
- "resolveJsonModule": true
11
- }
12
- }