@astral/validations 2.7.1 → 2.7.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.
Files changed (124) hide show
  1. package/compose/compose.js +1 -5
  2. package/compose/index.js +1 -17
  3. package/composeSome/composeSome.js +1 -5
  4. package/composeSome/index.js +1 -17
  5. package/constants.js +2 -5
  6. package/createRule/createRule.js +1 -5
  7. package/createRule/index.js +1 -17
  8. package/index.js +19 -35
  9. package/isDate/index.js +1 -17
  10. package/isDate/isDate.js +5 -8
  11. package/isEmail/index.js +1 -17
  12. package/isEmail/isEmail.js +8 -11
  13. package/isINNIP/index.js +1 -17
  14. package/isINNIP/isINNIP.js +5 -8
  15. package/isINNUL/index.js +1 -17
  16. package/isINNUL/isINNUL.js +5 -8
  17. package/isMaxLength/index.js +1 -5
  18. package/isMaxLength/isMaxLength.js +10 -17
  19. package/isMaxValue/index.js +1 -5
  20. package/isMaxValue/isMaxValue.js +9 -13
  21. package/isMaybeNumber/index.js +1 -17
  22. package/isMaybeNumber/isMaybeNumber.js +7 -10
  23. package/isMinLength/index.js +1 -17
  24. package/isMinLength/isMinLength.js +9 -16
  25. package/isMinValue/index.js +1 -5
  26. package/isMinValue/isMinValue.js +9 -13
  27. package/isMobilePhone/index.js +1 -17
  28. package/isMobilePhone/isMobilePhone.js +5 -8
  29. package/isOGRNIP/index.js +1 -17
  30. package/isOGRNIP/isOGRNIP.js +5 -8
  31. package/isOGRNUL/index.js +1 -17
  32. package/isOGRNUL/isOGRNUL.js +5 -8
  33. package/isRequired/index.js +1 -17
  34. package/isRequired/isRequired.js +5 -11
  35. package/isSNILS/index.js +1 -17
  36. package/isSNILS/isSNILS.js +5 -8
  37. package/package.json +5 -8
  38. package/types.js +1 -2
  39. package/utils/index.js +1 -17
  40. package/utils/isEmptyString.js +1 -5
  41. package/yupAdapter/index.js +1 -17
  42. package/yupAdapter/yupAdapter.js +1 -5
  43. package/esm/compose/compose.d.ts +0 -7
  44. package/esm/compose/compose.js +0 -6
  45. package/esm/compose/index.d.ts +0 -1
  46. package/esm/compose/index.js +0 -1
  47. package/esm/composeSome/composeSome.d.ts +0 -8
  48. package/esm/composeSome/composeSome.js +0 -25
  49. package/esm/composeSome/index.d.ts +0 -1
  50. package/esm/composeSome/index.js +0 -1
  51. package/esm/constants.d.ts +0 -2
  52. package/esm/constants.js +0 -2
  53. package/esm/createRule/createRule.d.ts +0 -14
  54. package/esm/createRule/createRule.js +0 -12
  55. package/esm/createRule/index.d.ts +0 -1
  56. package/esm/createRule/index.js +0 -1
  57. package/esm/index.d.ts +0 -19
  58. package/esm/index.js +0 -19
  59. package/esm/isDate/index.d.ts +0 -1
  60. package/esm/isDate/index.js +0 -1
  61. package/esm/isDate/isDate.d.ts +0 -10
  62. package/esm/isDate/isDate.js +0 -23
  63. package/esm/isEmail/index.d.ts +0 -1
  64. package/esm/isEmail/index.js +0 -1
  65. package/esm/isEmail/isEmail.d.ts +0 -13
  66. package/esm/isEmail/isEmail.js +0 -25
  67. package/esm/isINNIP/index.d.ts +0 -1
  68. package/esm/isINNIP/index.js +0 -1
  69. package/esm/isINNIP/isINNIP.d.ts +0 -10
  70. package/esm/isINNIP/isINNIP.js +0 -39
  71. package/esm/isINNUL/index.d.ts +0 -1
  72. package/esm/isINNUL/index.js +0 -1
  73. package/esm/isINNUL/isINNUL.d.ts +0 -10
  74. package/esm/isINNUL/isINNUL.js +0 -34
  75. package/esm/isMaxLength/index.d.ts +0 -1
  76. package/esm/isMaxLength/index.js +0 -1
  77. package/esm/isMaxLength/isMaxLength.d.ts +0 -18
  78. package/esm/isMaxLength/isMaxLength.js +0 -34
  79. package/esm/isMaxValue/index.d.ts +0 -1
  80. package/esm/isMaxValue/index.js +0 -1
  81. package/esm/isMaxValue/isMaxValue.d.ts +0 -17
  82. package/esm/isMaxValue/isMaxValue.js +0 -35
  83. package/esm/isMaybeNumber/index.d.ts +0 -1
  84. package/esm/isMaybeNumber/index.js +0 -1
  85. package/esm/isMaybeNumber/isMaybeNumber.d.ts +0 -10
  86. package/esm/isMaybeNumber/isMaybeNumber.js +0 -23
  87. package/esm/isMinLength/index.d.ts +0 -1
  88. package/esm/isMinLength/index.js +0 -1
  89. package/esm/isMinLength/isMinLength.d.ts +0 -18
  90. package/esm/isMinLength/isMinLength.js +0 -34
  91. package/esm/isMinValue/index.d.ts +0 -1
  92. package/esm/isMinValue/index.js +0 -1
  93. package/esm/isMinValue/isMinValue.d.ts +0 -17
  94. package/esm/isMinValue/isMinValue.js +0 -35
  95. package/esm/isMobilePhone/index.d.ts +0 -1
  96. package/esm/isMobilePhone/index.js +0 -1
  97. package/esm/isMobilePhone/isMobilePhone.d.ts +0 -10
  98. package/esm/isMobilePhone/isMobilePhone.js +0 -20
  99. package/esm/isOGRNIP/index.d.ts +0 -1
  100. package/esm/isOGRNIP/index.js +0 -1
  101. package/esm/isOGRNIP/isOGRNIP.d.ts +0 -10
  102. package/esm/isOGRNIP/isOGRNIP.js +0 -26
  103. package/esm/isOGRNUL/index.d.ts +0 -1
  104. package/esm/isOGRNUL/index.js +0 -1
  105. package/esm/isOGRNUL/isOGRNUL.d.ts +0 -10
  106. package/esm/isOGRNUL/isOGRNUL.js +0 -26
  107. package/esm/isRequired/index.d.ts +0 -1
  108. package/esm/isRequired/index.js +0 -1
  109. package/esm/isRequired/isRequired.d.ts +0 -11
  110. package/esm/isRequired/isRequired.js +0 -23
  111. package/esm/isSNILS/index.d.ts +0 -1
  112. package/esm/isSNILS/index.js +0 -1
  113. package/esm/isSNILS/isSNILS.d.ts +0 -10
  114. package/esm/isSNILS/isSNILS.js +0 -62
  115. package/esm/types.d.ts +0 -4
  116. package/esm/types.js +0 -1
  117. package/esm/utils/index.d.ts +0 -1
  118. package/esm/utils/index.js +0 -1
  119. package/esm/utils/isEmptyString.d.ts +0 -4
  120. package/esm/utils/isEmptyString.js +0 -6
  121. package/esm/yupAdapter/index.d.ts +0 -1
  122. package/esm/yupAdapter/index.js +0 -1
  123. package/esm/yupAdapter/yupAdapter.d.ts +0 -8
  124. package/esm/yupAdapter/yupAdapter.js +0 -11
@@ -1,10 +0,0 @@
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;
@@ -1,34 +0,0 @@
1
- import { createRule } from '../createRule';
2
- import { isEmptyString } from '../utils';
3
- export const IS_INNUL_DEFAULT_MESSAGE = 'Некорректный ИНН ЮЛ';
4
- const INNUL_LENGTH = 10;
5
- const INN_UL_DECODING = [2, 4, 10, 3, 5, 9, 4, 6, 8];
6
- const calcCheckSumForInnUl = (arrSymbols) => (arrSymbols
7
- .slice(0, -1)
8
- .reduce((sum, symbol, index) => INN_UL_DECODING[index] * Number(symbol) + sum, 0) %
9
- 11) %
10
- 10;
11
- /**
12
- * @description Проверяет валиден ли ИНН ЮЛ
13
- * @example isINNUL()('7728168971');
14
- */
15
- export const isINNUL = createRule(({ message = IS_INNUL_DEFAULT_MESSAGE } = {}) => (value) => {
16
- if (isEmptyString(value)) {
17
- return undefined;
18
- }
19
- if (typeof value === 'string') {
20
- if (value.length !== INNUL_LENGTH) {
21
- return message;
22
- }
23
- const arrSymbols = value.split('');
24
- if (arrSymbols.some((symbol) => isNaN(Number(symbol)))) {
25
- return message;
26
- }
27
- const checksum = calcCheckSumForInnUl(arrSymbols);
28
- if (Number(value[9]) !== checksum) {
29
- return message;
30
- }
31
- return undefined;
32
- }
33
- return message;
34
- });
@@ -1 +0,0 @@
1
- export { isMaxLength } from './isMaxLength';
@@ -1 +0,0 @@
1
- export { isMaxLength } from './isMaxLength';
@@ -1,18 +0,0 @@
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;
@@ -1,34 +0,0 @@
1
- import isEmpty from 'lodash.isempty';
2
- import { createRule } from '../createRule';
3
- import { INCORRECT_MESSAGE } from '../constants';
4
- import { isEmptyString } from '../utils';
5
- export const getDefaultMessage = (max) => `Макс. символов: ${max}`;
6
- /**
7
- * @description Проверяет максимальную длину value
8
- * @example isMaxLength({ max: 10 })(1239123);
9
- * @example isMaxLength({ max: 10 })('1239123');
10
- * @param {number} [max] Максимальная длина value
11
- * @param {string} [message.defaultMessage] Сообщение при неудачной валидации
12
- * @param {string} [message.incorrectValue] Сообщение при переданном некорректном value
13
- */
14
- export const isMaxLength = createRule(({ max, message = {
15
- defaultMessage: getDefaultMessage(max),
16
- incorrectValue: INCORRECT_MESSAGE,
17
- }, }) => (value) => {
18
- if (isEmptyString(value)) {
19
- return undefined;
20
- }
21
- if (max < 0) {
22
- throw new Error('Значение параметра `max` должно быть >= 0');
23
- }
24
- if (typeof value === 'string' || Array.isArray(value)) {
25
- return value.length > max ? message.defaultMessage : undefined;
26
- }
27
- if (typeof value !== 'string' || !Array.isArray(value)) {
28
- return message.incorrectValue;
29
- }
30
- if (isEmpty(value)) {
31
- return undefined;
32
- }
33
- return undefined;
34
- });
@@ -1 +0,0 @@
1
- export { isMaxValue } from './isMaxValue';
@@ -1 +0,0 @@
1
- export { isMaxValue } from './isMaxValue';
@@ -1,17 +0,0 @@
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;
@@ -1,35 +0,0 @@
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 = (max) => {
6
- return `Должно быть меньше чем ${max}`;
7
- };
8
- /**
9
- * @description Проверяет максимальное значение value
10
- * @example isMaxValue({ max: 10 })(1239123);
11
- * @param {number} [max] Максимальное значение value
12
- * @param {string} [message.defaultMessage] Сообщение при неудачной валидации
13
- * @param {string} [message.incorrectValue] Сообщение при переданном некорректном value
14
- */
15
- export const isMaxValue = createRule(({ max, message = {
16
- defaultMessage: `Должно быть меньше чем ${max}`,
17
- incorrectValue: INCORRECT_MESSAGE,
18
- }, }) => (value) => {
19
- if (isEmptyString(value)) {
20
- return undefined;
21
- }
22
- if (typeof value === 'string' && !isMaybeNumber()(value)) {
23
- if (parseFloat(value) <= max) {
24
- return undefined;
25
- }
26
- return message.defaultMessage;
27
- }
28
- if (typeof value !== 'number' || isNaN(value)) {
29
- return message.incorrectValue;
30
- }
31
- if (value <= max) {
32
- return undefined;
33
- }
34
- return message.defaultMessage;
35
- });
@@ -1 +0,0 @@
1
- export * from './isMaybeNumber';
@@ -1 +0,0 @@
1
- export * from './isMaybeNumber';
@@ -1,10 +0,0 @@
1
- export declare const IS_MAYBE_NUMBER_RULE_DEFAULT_MESSAGE = "\u041D\u0435 \u043C\u043E\u0436\u0435\u0442 \u0431\u044B\u0442\u044C \u043F\u0440\u0435\u043E\u0431\u0440\u0430\u0437\u043E\u0432\u0430\u043D\u043E \u0432 \u0447\u0438\u0441\u043B\u043E";
2
- /**
3
- * @description Проверяет может ли значение быть преобразованным в число
4
- * @example isMaybeNumber()('7728168971');
5
- */
6
- export declare const isMaybeNumber: (params?: ({
7
- message?: string | undefined;
8
- } & {
9
- exclude?: ((value: unknown) => boolean) | undefined;
10
- }) | undefined) => import("..").InitializedRule;
@@ -1,23 +0,0 @@
1
- import { createRule } from '../createRule';
2
- import { CONTAINS_SPACES_REGEX } from '../constants';
3
- import { isEmptyString } from '../utils';
4
- export const IS_MAYBE_NUMBER_RULE_DEFAULT_MESSAGE = 'Не может быть преобразовано в число';
5
- /**
6
- * @description Проверяет может ли значение быть преобразованным в число
7
- * @example isMaybeNumber()('7728168971');
8
- */
9
- export const isMaybeNumber = createRule(({ message = IS_MAYBE_NUMBER_RULE_DEFAULT_MESSAGE } = {}) => (value) => {
10
- if (isEmptyString(value)) {
11
- return undefined;
12
- }
13
- if (typeof value === 'string' &&
14
- !isNaN(Number(value)) &&
15
- !CONTAINS_SPACES_REGEX.test(value) &&
16
- value !== '') {
17
- return undefined;
18
- }
19
- if (typeof value === 'number' && !isNaN(value)) {
20
- return undefined;
21
- }
22
- return message;
23
- });
@@ -1 +0,0 @@
1
- export * from './isMinLength';
@@ -1 +0,0 @@
1
- export * from './isMinLength';
@@ -1,18 +0,0 @@
1
- export declare const getDefaultMessage: (min: number) => string;
2
- /**
3
- * @description Проверяет минимальную длину value
4
- * @example isMinLength({ min: 10 })(1239123);
5
- * @example isMinLength({ min: 10 })('1239123');
6
- * @param {number} [min] Минимальная длина value
7
- * @param {string} [message.defaultMessage] Сообщение при неудачной валидации
8
- * @param {string} [message.incorrectValue] Сообщение при переданном некорректном value
9
- */
10
- export declare const isMinLength: (params: {
11
- message?: {
12
- defaultMessage?: string | undefined;
13
- incorrectValue?: string | undefined;
14
- } | undefined;
15
- min: number;
16
- } & {
17
- exclude?: ((value: unknown) => boolean) | undefined;
18
- }) => import("..").InitializedRule;
@@ -1,34 +0,0 @@
1
- import isEmpty from 'lodash.isempty';
2
- import { createRule } from '../createRule';
3
- import { INCORRECT_MESSAGE } from '../constants';
4
- import { isEmptyString } from '../utils';
5
- export const getDefaultMessage = (min) => `Мин. символов: ${min}`;
6
- /**
7
- * @description Проверяет минимальную длину value
8
- * @example isMinLength({ min: 10 })(1239123);
9
- * @example isMinLength({ min: 10 })('1239123');
10
- * @param {number} [min] Минимальная длина value
11
- * @param {string} [message.defaultMessage] Сообщение при неудачной валидации
12
- * @param {string} [message.incorrectValue] Сообщение при переданном некорректном value
13
- */
14
- export const isMinLength = createRule(({ min, message = {
15
- defaultMessage: `Мин. символов: ${min}`,
16
- incorrectValue: INCORRECT_MESSAGE,
17
- }, } = { min: 0 }) => (value) => {
18
- if (isEmptyString(value)) {
19
- return undefined;
20
- }
21
- if (min < 0) {
22
- throw new Error('Значение параметра `min` должно быть >= 0');
23
- }
24
- if (typeof value === 'string' || Array.isArray(value)) {
25
- return value.length < min ? message.defaultMessage : undefined;
26
- }
27
- if (typeof value !== 'string' || !Array.isArray(value)) {
28
- return message.incorrectValue;
29
- }
30
- if (isEmpty(value)) {
31
- return undefined;
32
- }
33
- return undefined;
34
- });
@@ -1 +0,0 @@
1
- export { isMinValue } from './isMinValue';
@@ -1 +0,0 @@
1
- export { isMinValue } from './isMinValue';
@@ -1,17 +0,0 @@
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;
@@ -1,35 +0,0 @@
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
- });
@@ -1 +0,0 @@
1
- export * from './isMobilePhone';
@@ -1 +0,0 @@
1
- export * from './isMobilePhone';
@@ -1,10 +0,0 @@
1
- export declare const IS_MOBILE_PHONE_DEFAULT_MESSAGE = "\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 \u043D\u043E\u043C\u0435\u0440 \u0442\u0435\u043B\u0435\u0444\u043E\u043D\u0430";
2
- /**
3
- * @description Проверяет валиден ли мобильный телефон
4
- * @example isMobilePhone()('79999999999');
5
- */
6
- export declare const isMobilePhone: (params?: ({
7
- message?: string | undefined;
8
- } & {
9
- exclude?: ((value: unknown) => boolean) | undefined;
10
- }) | undefined) => import("..").InitializedRule;
@@ -1,20 +0,0 @@
1
- import { createRule } from '../createRule';
2
- import { isEmptyString } from '../utils';
3
- export const IS_MOBILE_PHONE_DEFAULT_MESSAGE = 'Некорректный номер телефона';
4
- const MOBILE_PHONE_REGEX = /^(79)\d{9}$/;
5
- /**
6
- * @description Проверяет валиден ли мобильный телефон
7
- * @example isMobilePhone()('79999999999');
8
- */
9
- export const isMobilePhone = createRule(({ message = IS_MOBILE_PHONE_DEFAULT_MESSAGE } = {}) => (value) => {
10
- if (isEmptyString(value)) {
11
- return undefined;
12
- }
13
- if (typeof value === 'string') {
14
- if (!MOBILE_PHONE_REGEX.test(value)) {
15
- return message;
16
- }
17
- return undefined;
18
- }
19
- return message;
20
- });
@@ -1 +0,0 @@
1
- export * from './isOGRNIP';
@@ -1 +0,0 @@
1
- export * from './isOGRNIP';
@@ -1,10 +0,0 @@
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;
@@ -1,26 +0,0 @@
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
- });
@@ -1 +0,0 @@
1
- export * from './isOGRNUL';
@@ -1 +0,0 @@
1
- export * from './isOGRNUL';
@@ -1,10 +0,0 @@
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;
@@ -1,26 +0,0 @@
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
- });
@@ -1 +0,0 @@
1
- export * from './isRequired';
@@ -1 +0,0 @@
1
- export * from './isRequired';
@@ -1,11 +0,0 @@
1
- export declare const REQUIRED_RULE_DEFAULT_MESSAGE = "\u041D\u0435 \u0437\u0430\u043F\u043E\u043B\u043D\u0435\u043D\u043E";
2
- /**
3
- * @description Проверяет присутсвует ли value
4
- * @example isRequired();
5
- * @example isRequired('ИНН обязателен');
6
- */
7
- export declare const isRequired: (params?: ({
8
- message?: string | undefined;
9
- } & {
10
- exclude?: ((value: unknown) => boolean) | undefined;
11
- }) | undefined) => import("..").InitializedRule;
@@ -1,23 +0,0 @@
1
- import isEmpty from 'lodash.isempty';
2
- import { createRule } from '../createRule';
3
- export const REQUIRED_RULE_DEFAULT_MESSAGE = 'Не заполнено';
4
- /**
5
- * @description Проверяет присутсвует ли value
6
- * @example isRequired();
7
- * @example isRequired('ИНН обязателен');
8
- */
9
- export const isRequired = createRule(({ message = REQUIRED_RULE_DEFAULT_MESSAGE } = {}) => (value) => {
10
- if (typeof value === 'number' || value instanceof Date) {
11
- return undefined;
12
- }
13
- if (typeof value === 'string') {
14
- return value.trim() ? undefined : message;
15
- }
16
- if (typeof value === 'boolean') {
17
- return value ? undefined : message;
18
- }
19
- if (!isEmpty(value)) {
20
- return undefined;
21
- }
22
- return message;
23
- });
@@ -1 +0,0 @@
1
- export * from './isSNILS';
@@ -1 +0,0 @@
1
- export * from './isSNILS';
@@ -1,10 +0,0 @@
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;
@@ -1,62 +0,0 @@
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 DELETED
@@ -1,4 +0,0 @@
1
- export type RuleError = string;
2
- export type ValidationResult = RuleError | undefined;
3
- export type InitializedRule = (value?: unknown) => ValidationResult;
4
- export type Rule<Params extends object, RequiredParams extends boolean> = RequiredParams extends true ? (params: Params) => InitializedRule : (params?: Params) => InitializedRule;
package/esm/types.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export * from './isEmptyString';
@@ -1 +0,0 @@
1
- export * from './isEmptyString';
@@ -1,4 +0,0 @@
1
- /**
2
- * @description Используется в правилах валидации для проверки того, что проверяемое значение еще не указано
3
- */
4
- export declare const isEmptyString: (value: unknown) => boolean;
@@ -1,6 +0,0 @@
1
- /**
2
- * @description Используется в правилах валидации для проверки того, что проверяемое значение еще не указано
3
- */
4
- export const isEmptyString = (value) => {
5
- return value === '';
6
- };
@@ -1 +0,0 @@
1
- export * from './yupAdapter';
@@ -1 +0,0 @@
1
- export * from './yupAdapter';
@@ -1,8 +0,0 @@
1
- import { InitializedRule } from '../types';
2
- type YupValidationResult = boolean | string | string[];
3
- /**
4
- * @description Адаптирует правило созданное createRule к интерфейсу yup
5
- * @example yupAdapter(isMinLength(22))('word')
6
- */
7
- export declare const yupAdapter: (rule: InitializedRule) => (value: unknown) => YupValidationResult;
8
- export {};