@astral/validations 1.19.4 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/compose/compose.d.ts +2 -2
  2. package/compose/compose.js +2 -2
  3. package/composeAllSettled/composeAllSettled.d.ts +2 -2
  4. package/composeAllSettled/composeAllSettled.js +3 -3
  5. package/constants.d.ts +2 -0
  6. package/constants.js +5 -0
  7. package/createRule/createRule.d.ts +10 -2
  8. package/createRule/createRule.js +12 -5
  9. package/esm/compose/compose.d.ts +2 -2
  10. package/esm/compose/compose.js +1 -2
  11. package/esm/composeAllSettled/composeAllSettled.d.ts +2 -2
  12. package/esm/composeAllSettled/composeAllSettled.js +2 -3
  13. package/esm/constants.d.ts +2 -0
  14. package/esm/constants.js +2 -0
  15. package/esm/createRule/createRule.d.ts +10 -2
  16. package/esm/createRule/createRule.js +12 -5
  17. package/esm/index.d.ts +11 -0
  18. package/esm/index.js +11 -0
  19. package/esm/isDate/index.d.ts +1 -0
  20. package/esm/isDate/index.js +1 -0
  21. package/esm/isDate/isDate.d.ts +10 -0
  22. package/esm/isDate/isDate.js +23 -0
  23. package/esm/isINNIP/index.d.ts +1 -0
  24. package/esm/isINNIP/index.js +1 -0
  25. package/esm/isINNIP/isINNIP.d.ts +10 -0
  26. package/esm/isINNIP/isINNIP.js +39 -0
  27. package/esm/isINNUL/index.d.ts +1 -0
  28. package/esm/isINNUL/index.js +1 -0
  29. package/esm/isINNUL/isINNUL.d.ts +10 -0
  30. package/esm/isINNUL/isINNUL.js +34 -0
  31. package/esm/isMaxLength/index.d.ts +1 -0
  32. package/esm/isMaxLength/index.js +1 -0
  33. package/esm/isMaxLength/isMaxLength.d.ts +18 -0
  34. package/esm/isMaxLength/isMaxLength.js +34 -0
  35. package/esm/isMaxValue/index.d.ts +1 -0
  36. package/esm/isMaxValue/index.js +1 -0
  37. package/esm/isMaxValue/isMaxValue.d.ts +17 -0
  38. package/esm/isMaxValue/isMaxValue.js +35 -0
  39. package/esm/isMaybeNumber/index.d.ts +1 -0
  40. package/esm/isMaybeNumber/index.js +1 -0
  41. package/esm/isMaybeNumber/isMaybeNumber.d.ts +10 -0
  42. package/esm/isMaybeNumber/isMaybeNumber.js +23 -0
  43. package/esm/isMinLength/index.d.ts +1 -0
  44. package/esm/isMinLength/index.js +1 -0
  45. package/esm/isMinLength/isMinLength.d.ts +18 -0
  46. package/esm/isMinLength/isMinLength.js +34 -0
  47. package/esm/isMinValue/index.d.ts +1 -0
  48. package/esm/isMinValue/index.js +1 -0
  49. package/esm/isMinValue/isMinValue.d.ts +17 -0
  50. package/esm/isMinValue/isMinValue.js +35 -0
  51. package/esm/isOGRNIP/index.d.ts +1 -0
  52. package/esm/isOGRNIP/index.js +1 -0
  53. package/esm/isOGRNIP/isOGRNIP.d.ts +10 -0
  54. package/esm/isOGRNIP/isOGRNIP.js +26 -0
  55. package/esm/isOGRNUL/index.d.ts +1 -0
  56. package/esm/isOGRNUL/index.js +1 -0
  57. package/esm/isOGRNUL/isOGRNUL.d.ts +10 -0
  58. package/esm/isOGRNUL/isOGRNUL.js +26 -0
  59. package/esm/isRequired/isRequired.d.ts +5 -2
  60. package/esm/isRequired/isRequired.js +1 -2
  61. package/esm/isSNILS/index.d.ts +1 -0
  62. package/esm/isSNILS/index.js +1 -0
  63. package/esm/isSNILS/isSNILS.d.ts +10 -0
  64. package/esm/isSNILS/isSNILS.js +62 -0
  65. package/esm/types.d.ts +1 -1
  66. package/esm/utils/index.d.ts +1 -0
  67. package/esm/utils/index.js +1 -0
  68. package/esm/utils/isEmptyString.d.ts +4 -0
  69. package/esm/utils/isEmptyString.js +6 -0
  70. package/index.d.ts +11 -0
  71. package/index.js +11 -0
  72. package/isDate/index.d.ts +1 -0
  73. package/isDate/index.js +17 -0
  74. package/isDate/isDate.d.ts +10 -0
  75. package/isDate/isDate.js +26 -0
  76. package/isINNIP/index.d.ts +1 -0
  77. package/isINNIP/index.js +17 -0
  78. package/isINNIP/isINNIP.d.ts +10 -0
  79. package/isINNIP/isINNIP.js +42 -0
  80. package/isINNUL/index.d.ts +1 -0
  81. package/isINNUL/index.js +17 -0
  82. package/isINNUL/isINNUL.d.ts +10 -0
  83. package/isINNUL/isINNUL.js +37 -0
  84. package/isMaxLength/index.d.ts +1 -0
  85. package/isMaxLength/index.js +5 -0
  86. package/isMaxLength/isMaxLength.d.ts +18 -0
  87. package/isMaxLength/isMaxLength.js +41 -0
  88. package/isMaxValue/index.d.ts +1 -0
  89. package/isMaxValue/index.js +5 -0
  90. package/isMaxValue/isMaxValue.d.ts +17 -0
  91. package/isMaxValue/isMaxValue.js +39 -0
  92. package/isMaybeNumber/index.d.ts +1 -0
  93. package/isMaybeNumber/index.js +17 -0
  94. package/isMaybeNumber/isMaybeNumber.d.ts +10 -0
  95. package/isMaybeNumber/isMaybeNumber.js +26 -0
  96. package/isMinLength/index.d.ts +1 -0
  97. package/isMinLength/index.js +17 -0
  98. package/isMinLength/isMinLength.d.ts +18 -0
  99. package/isMinLength/isMinLength.js +41 -0
  100. package/isMinValue/index.d.ts +1 -0
  101. package/isMinValue/index.js +5 -0
  102. package/isMinValue/isMinValue.d.ts +17 -0
  103. package/isMinValue/isMinValue.js +39 -0
  104. package/isOGRNIP/index.d.ts +1 -0
  105. package/isOGRNIP/index.js +17 -0
  106. package/isOGRNIP/isOGRNIP.d.ts +10 -0
  107. package/isOGRNIP/isOGRNIP.js +29 -0
  108. package/isOGRNUL/index.d.ts +1 -0
  109. package/isOGRNUL/index.js +17 -0
  110. package/isOGRNUL/isOGRNUL.d.ts +10 -0
  111. package/isOGRNUL/isOGRNUL.js +29 -0
  112. package/isRequired/isRequired.d.ts +5 -2
  113. package/isRequired/isRequired.js +1 -2
  114. package/isSNILS/index.d.ts +1 -0
  115. package/isSNILS/index.js +17 -0
  116. package/isSNILS/isSNILS.d.ts +10 -0
  117. package/isSNILS/isSNILS.js +65 -0
  118. package/package.json +1 -1
  119. package/types.d.ts +1 -1
  120. package/utils/index.d.ts +1 -0
  121. package/utils/index.js +17 -0
  122. package/utils/isEmptyString.d.ts +4 -0
  123. package/utils/isEmptyString.js +10 -0
@@ -0,0 +1,17 @@
1
+ export declare const getDefaultMessage: (min: number) => string;
2
+ /**
3
+ * @description Проверяет минимальное значение value
4
+ * @example isMinValue({ min: 10 })(1239123);
5
+ * @param {number} [min] Минимальное значение value
6
+ * @param {string} [message.defaultMessage] Сообщение при неудачной валидации
7
+ * @param {string} [message.incorrectValue] Сообщение при переданном некорректном value
8
+ */
9
+ export declare const isMinValue: (params: {
10
+ min: number;
11
+ message?: {
12
+ defaultMessage?: string | undefined;
13
+ incorrectValue?: string | undefined;
14
+ } | undefined;
15
+ } & {
16
+ exclude?: ((value: unknown) => boolean) | undefined;
17
+ }) => import("..").InitializedRule;
@@ -0,0 +1,35 @@
1
+ import { INCORRECT_MESSAGE } from '../constants';
2
+ import { createRule } from '../createRule';
3
+ import { isMaybeNumber } from '../isMaybeNumber';
4
+ import { isEmptyString } from '../utils';
5
+ export const getDefaultMessage = (min) => {
6
+ return `Должно быть больше чем ${min}`;
7
+ };
8
+ /**
9
+ * @description Проверяет минимальное значение value
10
+ * @example isMinValue({ min: 10 })(1239123);
11
+ * @param {number} [min] Минимальное значение value
12
+ * @param {string} [message.defaultMessage] Сообщение при неудачной валидации
13
+ * @param {string} [message.incorrectValue] Сообщение при переданном некорректном value
14
+ */
15
+ export const isMinValue = createRule(({ min, message = {
16
+ defaultMessage: `Должно быть больше чем ${min}`,
17
+ incorrectValue: INCORRECT_MESSAGE,
18
+ }, } = { min: 0 }) => (value) => {
19
+ if (isEmptyString(value)) {
20
+ return undefined;
21
+ }
22
+ if (typeof value === 'string' && !isMaybeNumber()(value)) {
23
+ if (parseFloat(value) >= min) {
24
+ return undefined;
25
+ }
26
+ return message.defaultMessage;
27
+ }
28
+ if (typeof value !== 'number' || isNaN(value)) {
29
+ return message.incorrectValue;
30
+ }
31
+ if (value >= min) {
32
+ return undefined;
33
+ }
34
+ return message.defaultMessage;
35
+ });
@@ -0,0 +1 @@
1
+ export * from './isOGRNIP';
@@ -0,0 +1 @@
1
+ export * from './isOGRNIP';
@@ -0,0 +1,10 @@
1
+ export declare const IS_OGRNIP_DEFAULT_MESSAGE = "\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 \u041E\u0413\u0420\u041D \u0418\u041F";
2
+ /**
3
+ * @description Проверяет валиден ли ОРГН ИП
4
+ * @example isOGRNIP()('7728168971');
5
+ */
6
+ export declare const isOGRNIP: (params?: ({
7
+ message?: string | undefined;
8
+ } & {
9
+ exclude?: ((value: unknown) => boolean) | undefined;
10
+ }) | undefined) => import("..").InitializedRule;
@@ -0,0 +1,26 @@
1
+ import { createRule } from '../createRule';
2
+ import { isEmptyString } from '../utils';
3
+ export const IS_OGRNIP_DEFAULT_MESSAGE = 'Некорректный ОГРН ИП';
4
+ const OGRNIP_LENGTH = 15;
5
+ /**
6
+ * @description Проверяет валиден ли ОРГН ИП
7
+ * @example isOGRNIP()('7728168971');
8
+ */
9
+ export const isOGRNIP = createRule(({ message = IS_OGRNIP_DEFAULT_MESSAGE } = {}) => (value) => {
10
+ if (isEmptyString(value)) {
11
+ return undefined;
12
+ }
13
+ if (typeof value === 'string') {
14
+ if (value.length !== OGRNIP_LENGTH) {
15
+ return message;
16
+ }
17
+ const checkSum = (parseInt(value.slice(0, -1)) % 13)
18
+ .toString()
19
+ .slice(-1);
20
+ if (value.slice(14, 15) !== checkSum) {
21
+ return message;
22
+ }
23
+ return undefined;
24
+ }
25
+ return message;
26
+ });
@@ -0,0 +1 @@
1
+ export * from './isOGRNUL';
@@ -0,0 +1 @@
1
+ export * from './isOGRNUL';
@@ -0,0 +1,10 @@
1
+ export declare const IS_OGRNUL_DEFAULT_MESSAGE = "\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 \u041E\u0413\u0420\u041D \u042E\u041B";
2
+ /**
3
+ * @description Проверяет валиден ли ОРГН ЮЛ
4
+ * @example isOGRNUL()('7728168971');
5
+ */
6
+ export declare const isOGRNUL: (params?: ({
7
+ message?: string | undefined;
8
+ } & {
9
+ exclude?: ((value: unknown) => boolean) | undefined;
10
+ }) | undefined) => import("..").InitializedRule;
@@ -0,0 +1,26 @@
1
+ import { createRule } from '../createRule';
2
+ import { isEmptyString } from '../utils';
3
+ export const IS_OGRNUL_DEFAULT_MESSAGE = 'Некорректный ОГРН ЮЛ';
4
+ const OGRNUL_LENGTH = 13;
5
+ /**
6
+ * @description Проверяет валиден ли ОРГН ЮЛ
7
+ * @example isOGRNUL()('7728168971');
8
+ */
9
+ export const isOGRNUL = createRule(({ message = IS_OGRNUL_DEFAULT_MESSAGE } = {}) => (value) => {
10
+ if (isEmptyString(value)) {
11
+ return undefined;
12
+ }
13
+ if (typeof value === 'string') {
14
+ if (value.length !== OGRNUL_LENGTH) {
15
+ return message;
16
+ }
17
+ const checkSum = (parseInt(value.slice(0, -1)) % 11)
18
+ .toString()
19
+ .slice(-1);
20
+ if (value.slice(12, 13) !== checkSum) {
21
+ return message;
22
+ }
23
+ return undefined;
24
+ }
25
+ return message;
26
+ });
@@ -3,6 +3,9 @@ export declare const REQUIRED_RULE_DEFAULT_MESSAGE = "\u041D\u0435 \u0437\u0430\
3
3
  * @description Проверяет присутсвует ли value
4
4
  * @example isRequired();
5
5
  * @example isRequired('ИНН обязателен');
6
- * @param {string} [message] - 'Не заполнено'
7
6
  */
8
- export declare const isRequired: import("..").Rule<[message?: string | undefined]>;
7
+ export declare const isRequired: (params?: ({
8
+ message?: string | undefined;
9
+ } & {
10
+ exclude?: ((value: unknown) => boolean) | undefined;
11
+ }) | undefined) => import("..").InitializedRule;
@@ -5,9 +5,8 @@ export const REQUIRED_RULE_DEFAULT_MESSAGE = 'Не заполнено';
5
5
  * @description Проверяет присутсвует ли value
6
6
  * @example isRequired();
7
7
  * @example isRequired('ИНН обязателен');
8
- * @param {string} [message] - 'Не заполнено'
9
8
  */
10
- export const isRequired = createRule((message = REQUIRED_RULE_DEFAULT_MESSAGE) => (value) => {
9
+ export const isRequired = createRule(({ message = REQUIRED_RULE_DEFAULT_MESSAGE } = {}) => (value) => {
11
10
  if (typeof value === 'number' || value instanceof Date) {
12
11
  return undefined;
13
12
  }
@@ -0,0 +1 @@
1
+ export * from './isSNILS';
@@ -0,0 +1 @@
1
+ export * from './isSNILS';
@@ -0,0 +1,10 @@
1
+ export declare const IS_SNILS_DEFAULT_MESSAGE = "\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 \u0421\u041D\u0418\u041B\u0421";
2
+ /**
3
+ * @description Проверяет валиден ли СНИЛС
4
+ * @example isSNILS()('95145370513');
5
+ */
6
+ export declare const isSNILS: (params?: ({
7
+ message?: string | undefined;
8
+ } & {
9
+ exclude?: ((value: unknown) => boolean) | undefined;
10
+ }) | undefined) => import("..").InitializedRule;
@@ -0,0 +1,62 @@
1
+ import { createRule } from '../createRule';
2
+ import { isEmptyString } from '../utils';
3
+ export const IS_SNILS_DEFAULT_MESSAGE = 'Некорректный СНИЛС';
4
+ const RESTRICTED_VALUES = ['00000000000'];
5
+ const DEFAULT_CHECKED_SUM = [0, 100, 101];
6
+ const removeSpecialCharacters = (value) => {
7
+ return value.replace(/\D/g, '');
8
+ };
9
+ const calcCheckSumForSNILS = (digitsOfValue) => digitsOfValue
10
+ .slice(0, 9)
11
+ .split('')
12
+ .map(Number)
13
+ .reduce((sum, currentValue, index) => sum + currentValue * (9 - index), 0);
14
+ const compareCheckSum = (calculatedCheckSum, checkSum) => {
15
+ return (calculatedCheckSum % DEFAULT_CHECKED_SUM[2] === checkSum ||
16
+ (calculatedCheckSum % DEFAULT_CHECKED_SUM[2] === DEFAULT_CHECKED_SUM[1] &&
17
+ checkSum === DEFAULT_CHECKED_SUM[0]));
18
+ };
19
+ /**
20
+ * @description Проверяет валиден ли СНИЛС
21
+ * @example isSNILS()('95145370513');
22
+ */
23
+ export const isSNILS = createRule(({ message = IS_SNILS_DEFAULT_MESSAGE } = {}) => (value) => {
24
+ if (isEmptyString(value)) {
25
+ return undefined;
26
+ }
27
+ if (typeof value !== 'string') {
28
+ return message;
29
+ }
30
+ const formattedValue = removeSpecialCharacters(value);
31
+ if (formattedValue.length !== value.length) {
32
+ return message;
33
+ }
34
+ if (!/^(\d{11})$/.test(formattedValue)) {
35
+ return message;
36
+ }
37
+ if (RESTRICTED_VALUES.includes(formattedValue)) {
38
+ return message;
39
+ }
40
+ const checkSum = Number(formattedValue.slice(9, 11));
41
+ const calculatedCheckSum = calcCheckSumForSNILS(formattedValue);
42
+ if (calculatedCheckSum < DEFAULT_CHECKED_SUM[1]) {
43
+ if (calculatedCheckSum === checkSum) {
44
+ return undefined;
45
+ }
46
+ return message;
47
+ }
48
+ if (calculatedCheckSum === DEFAULT_CHECKED_SUM[1] ||
49
+ calculatedCheckSum === DEFAULT_CHECKED_SUM[2]) {
50
+ if (checkSum === DEFAULT_CHECKED_SUM[0]) {
51
+ return undefined;
52
+ }
53
+ return message;
54
+ }
55
+ if (calculatedCheckSum > DEFAULT_CHECKED_SUM[2]) {
56
+ if (compareCheckSum(calculatedCheckSum, checkSum)) {
57
+ return undefined;
58
+ }
59
+ return message;
60
+ }
61
+ return undefined;
62
+ });
package/esm/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export declare type RuleError = string | string[];
2
2
  export declare type ValidationResult = RuleError | undefined;
3
3
  export declare type InitializedRule = (value?: unknown) => ValidationResult;
4
- export declare type Rule<Args extends unknown[]> = (...args: Args) => InitializedRule;
4
+ export declare type Rule<Params extends object, RequiredParams extends boolean> = RequiredParams extends true ? (params: Params) => InitializedRule : (params?: Params) => InitializedRule;
@@ -0,0 +1 @@
1
+ export * from './isEmptyString';
@@ -0,0 +1 @@
1
+ export * from './isEmptyString';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @description Используется в правилах валидации для проверки того, что проверяемое значение еще не указано
3
+ */
4
+ export declare const isEmptyString: (value: unknown) => boolean;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @description Используется в правилах валидации для проверки того, что проверяемое значение еще не указано
3
+ */
4
+ export const isEmptyString = (value) => {
5
+ return value === '';
6
+ };
package/index.d.ts CHANGED
@@ -5,3 +5,14 @@ export * from './composeAllSettled';
5
5
  export * from './composeToString';
6
6
  export * from './isRequired';
7
7
  export * from './types';
8
+ export * from './isINNUL';
9
+ export * from './isINNIP';
10
+ export * from './isOGRNIP';
11
+ export * from './isOGRNUL';
12
+ export * from './isMinLength';
13
+ export * from './isMaxLength';
14
+ export * from './isMaxValue';
15
+ export * from './isMinValue';
16
+ export * from './isMaybeNumber';
17
+ export * from './isDate';
18
+ export * from './isSNILS';
package/index.js CHANGED
@@ -21,3 +21,14 @@ __exportStar(require("./composeAllSettled"), exports);
21
21
  __exportStar(require("./composeToString"), exports);
22
22
  __exportStar(require("./isRequired"), exports);
23
23
  __exportStar(require("./types"), exports);
24
+ __exportStar(require("./isINNUL"), exports);
25
+ __exportStar(require("./isINNIP"), exports);
26
+ __exportStar(require("./isOGRNIP"), exports);
27
+ __exportStar(require("./isOGRNUL"), exports);
28
+ __exportStar(require("./isMinLength"), exports);
29
+ __exportStar(require("./isMaxLength"), exports);
30
+ __exportStar(require("./isMaxValue"), exports);
31
+ __exportStar(require("./isMinValue"), exports);
32
+ __exportStar(require("./isMaybeNumber"), exports);
33
+ __exportStar(require("./isDate"), exports);
34
+ __exportStar(require("./isSNILS"), exports);
@@ -0,0 +1 @@
1
+ export * from './isDate';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./isDate"), exports);
@@ -0,0 +1,10 @@
1
+ export declare const IS_DATE_RULE_DEFAULT_MESSAGE = "\u041D\u0435\u0432\u0435\u0440\u043D\u044B\u0439 \u0444\u043E\u0440\u043C\u0430\u0442 \u0434\u0430\u0442\u044B";
2
+ /**
3
+ * @description Проверяет валидна ли дата
4
+ * @example isDate()('2011-11-12');
5
+ */
6
+ export declare const isDate: (params?: ({
7
+ message?: string | undefined;
8
+ } & {
9
+ exclude?: ((value: unknown) => boolean) | undefined;
10
+ }) | undefined) => import("..").InitializedRule;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDate = exports.IS_DATE_RULE_DEFAULT_MESSAGE = void 0;
4
+ const createRule_1 = require("../createRule");
5
+ const utils_1 = require("../utils");
6
+ exports.IS_DATE_RULE_DEFAULT_MESSAGE = 'Неверный формат даты';
7
+ /**
8
+ * @description Проверяет валидна ли дата
9
+ * @example isDate()('2011-11-12');
10
+ */
11
+ exports.isDate = (0, createRule_1.createRule)(({ message = exports.IS_DATE_RULE_DEFAULT_MESSAGE } = {}) => (value) => {
12
+ if ((0, utils_1.isEmptyString)(value)) {
13
+ return undefined;
14
+ }
15
+ if (typeof value === 'string') {
16
+ const date = new Date(value);
17
+ if (!isNaN(date.getTime())) {
18
+ return undefined;
19
+ }
20
+ return message;
21
+ }
22
+ if (value instanceof Date && !isNaN(value.getTime())) {
23
+ return undefined;
24
+ }
25
+ return message;
26
+ });
@@ -0,0 +1 @@
1
+ export * from './isINNIP';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./isINNIP"), exports);
@@ -0,0 +1,10 @@
1
+ export declare const IS_INNIP_DEFAULT_MESSAGE = "\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 \u0418\u041D\u041D \u042E\u041B";
2
+ /**
3
+ * @description Проверяет валиден ли ИНН ИП
4
+ * @example isINNIP()('384212952720');
5
+ */
6
+ export declare const isINNIP: (params?: ({
7
+ message?: string | undefined;
8
+ } & {
9
+ exclude?: ((value: unknown) => boolean) | undefined;
10
+ }) | undefined) => import("..").InitializedRule;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isINNIP = exports.IS_INNIP_DEFAULT_MESSAGE = void 0;
4
+ const createRule_1 = require("../createRule");
5
+ const utils_1 = require("../utils");
6
+ exports.IS_INNIP_DEFAULT_MESSAGE = 'Некорректный ИНН ЮЛ';
7
+ const INNIP_LENGTH = 12;
8
+ const FIRST_INN_UL_DECODING = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8];
9
+ const SECOND_INN_UL_DECODING = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8];
10
+ const calcFirstCheckSumForInnUl = (arrSymbols) => (arrSymbols
11
+ .slice(0, -2)
12
+ .reduce((sum, symbol, index) => FIRST_INN_UL_DECODING[index] * Number(symbol) + sum, 0) %
13
+ 11) %
14
+ 10;
15
+ const calcSecondCheckSumForInnUl = (arrSymbols) => (arrSymbols
16
+ .slice(0, -1)
17
+ .reduce((sum, symbol, index) => SECOND_INN_UL_DECODING[index] * Number(symbol) + sum, 0) %
18
+ 11) %
19
+ 10;
20
+ /**
21
+ * @description Проверяет валиден ли ИНН ИП
22
+ * @example isINNIP()('384212952720');
23
+ */
24
+ exports.isINNIP = (0, createRule_1.createRule)(({ message = exports.IS_INNIP_DEFAULT_MESSAGE } = {}) => (value) => {
25
+ if ((0, utils_1.isEmptyString)(value)) {
26
+ return undefined;
27
+ }
28
+ if (typeof value === 'string') {
29
+ if (value.length !== INNIP_LENGTH) {
30
+ return message;
31
+ }
32
+ const arrSymbols = value.split('');
33
+ const firstChecksum = calcFirstCheckSumForInnUl(arrSymbols);
34
+ const secondChecksum = calcSecondCheckSumForInnUl(arrSymbols);
35
+ if (Number(value[10]) !== firstChecksum &&
36
+ Number(value[11]) !== secondChecksum) {
37
+ return message;
38
+ }
39
+ return undefined;
40
+ }
41
+ return message;
42
+ });
@@ -0,0 +1 @@
1
+ export * from './isINNUL';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./isINNUL"), exports);
@@ -0,0 +1,10 @@
1
+ export declare const IS_INNUL_DEFAULT_MESSAGE = "\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 \u0418\u041D\u041D \u042E\u041B";
2
+ /**
3
+ * @description Проверяет валиден ли ИНН ЮЛ
4
+ * @example isINNUL()('7728168971');
5
+ */
6
+ export declare const isINNUL: (params?: ({
7
+ message?: string | undefined;
8
+ } & {
9
+ exclude?: ((value: unknown) => boolean) | undefined;
10
+ }) | undefined) => import("..").InitializedRule;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isINNUL = exports.IS_INNUL_DEFAULT_MESSAGE = void 0;
4
+ const createRule_1 = require("../createRule");
5
+ const utils_1 = require("../utils");
6
+ exports.IS_INNUL_DEFAULT_MESSAGE = 'Некорректный ИНН ЮЛ';
7
+ const INNUL_LENGTH = 10;
8
+ const INN_UL_DECODING = [2, 4, 10, 3, 5, 9, 4, 6, 8];
9
+ const calcCheckSumForInnUl = (arrSymbols) => (arrSymbols
10
+ .slice(0, -1)
11
+ .reduce((sum, symbol, index) => INN_UL_DECODING[index] * Number(symbol) + sum, 0) %
12
+ 11) %
13
+ 10;
14
+ /**
15
+ * @description Проверяет валиден ли ИНН ЮЛ
16
+ * @example isINNUL()('7728168971');
17
+ */
18
+ exports.isINNUL = (0, createRule_1.createRule)(({ message = exports.IS_INNUL_DEFAULT_MESSAGE } = {}) => (value) => {
19
+ if ((0, utils_1.isEmptyString)(value)) {
20
+ return undefined;
21
+ }
22
+ if (typeof value === 'string') {
23
+ if (value.length !== INNUL_LENGTH) {
24
+ return message;
25
+ }
26
+ const arrSymbols = value.split('');
27
+ if (arrSymbols.some((symbol) => isNaN(Number(symbol)))) {
28
+ return message;
29
+ }
30
+ const checksum = calcCheckSumForInnUl(arrSymbols);
31
+ if (Number(value[9]) !== checksum) {
32
+ return message;
33
+ }
34
+ return undefined;
35
+ }
36
+ return message;
37
+ });
@@ -0,0 +1 @@
1
+ export { isMaxLength } from './isMaxLength';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isMaxLength = void 0;
4
+ var isMaxLength_1 = require("./isMaxLength");
5
+ Object.defineProperty(exports, "isMaxLength", { enumerable: true, get: function () { return isMaxLength_1.isMaxLength; } });
@@ -0,0 +1,18 @@
1
+ export declare const getDefaultMessage: (max: number) => string;
2
+ /**
3
+ * @description Проверяет максимальную длину value
4
+ * @example isMaxLength({ max: 10 })(1239123);
5
+ * @example isMaxLength({ max: 10 })('1239123');
6
+ * @param {number} [max] Максимальная длина value
7
+ * @param {string} [message.defaultMessage] Сообщение при неудачной валидации
8
+ * @param {string} [message.incorrectValue] Сообщение при переданном некорректном value
9
+ */
10
+ export declare const isMaxLength: (params: {
11
+ max: number;
12
+ message?: {
13
+ defaultMessage?: string | undefined;
14
+ incorrectValue?: string | undefined;
15
+ } | undefined;
16
+ } & {
17
+ exclude?: ((value: unknown) => boolean) | undefined;
18
+ }) => import("..").InitializedRule;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isMaxLength = exports.getDefaultMessage = void 0;
7
+ const lodash_isempty_1 = __importDefault(require("lodash.isempty"));
8
+ const createRule_1 = require("../createRule");
9
+ const constants_1 = require("../constants");
10
+ const utils_1 = require("../utils");
11
+ const getDefaultMessage = (max) => `Макс. символов: ${max}`;
12
+ exports.getDefaultMessage = getDefaultMessage;
13
+ /**
14
+ * @description Проверяет максимальную длину value
15
+ * @example isMaxLength({ max: 10 })(1239123);
16
+ * @example isMaxLength({ max: 10 })('1239123');
17
+ * @param {number} [max] Максимальная длина value
18
+ * @param {string} [message.defaultMessage] Сообщение при неудачной валидации
19
+ * @param {string} [message.incorrectValue] Сообщение при переданном некорректном value
20
+ */
21
+ exports.isMaxLength = (0, createRule_1.createRule)(({ max, message = {
22
+ defaultMessage: (0, exports.getDefaultMessage)(max),
23
+ incorrectValue: constants_1.INCORRECT_MESSAGE,
24
+ }, }) => (value) => {
25
+ if ((0, utils_1.isEmptyString)(value)) {
26
+ return undefined;
27
+ }
28
+ if (max < 0) {
29
+ throw new Error('Значение параметра `max` должно быть >= 0');
30
+ }
31
+ if (typeof value === 'string' || Array.isArray(value)) {
32
+ return value.length > max ? message.defaultMessage : undefined;
33
+ }
34
+ if (typeof value !== 'string' || !Array.isArray(value)) {
35
+ return message.incorrectValue;
36
+ }
37
+ if ((0, lodash_isempty_1.default)(value)) {
38
+ return undefined;
39
+ }
40
+ return undefined;
41
+ });
@@ -0,0 +1 @@
1
+ export { isMaxValue } from './isMaxValue';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isMaxValue = void 0;
4
+ var isMaxValue_1 = require("./isMaxValue");
5
+ Object.defineProperty(exports, "isMaxValue", { enumerable: true, get: function () { return isMaxValue_1.isMaxValue; } });
@@ -0,0 +1,17 @@
1
+ export declare const getDefaultMessage: (max: number) => string;
2
+ /**
3
+ * @description Проверяет максимальное значение value
4
+ * @example isMaxValue({ max: 10 })(1239123);
5
+ * @param {number} [max] Максимальное значение value
6
+ * @param {string} [message.defaultMessage] Сообщение при неудачной валидации
7
+ * @param {string} [message.incorrectValue] Сообщение при переданном некорректном value
8
+ */
9
+ export declare const isMaxValue: (params: {
10
+ message?: {
11
+ defaultMessage?: string | undefined;
12
+ incorrectValue?: string | undefined;
13
+ } | undefined;
14
+ max: number;
15
+ } & {
16
+ exclude?: ((value: unknown) => boolean) | undefined;
17
+ }) => import("..").InitializedRule;