@astral/validations 1.19.3 → 1.20.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
@@ -1,7 +1,7 @@
1
- import { InitializedRule } from '../types';
1
+ import { InitializedRule, ValidationResult } from '../types';
2
2
  /**
3
3
  * @description Объединяет переданные правила в цепочку правил, останавливает выполнение цепочки, если появилась ошибка. Выполняет правила слева направо
4
4
  * @example compose(isRequired(), isEmail());
5
5
  * @example compose(isRequired(), compose(isIncludeDot(), isIncludeComma()));
6
6
  */
7
- export declare const compose: import("../types").Rule<InitializedRule[]>;
7
+ export declare const compose: (...rules: InitializedRule[]) => (value: unknown) => ValidationResult;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.compose = void 0;
4
- const createRule_1 = require("../createRule");
5
4
  /**
6
5
  * @description Объединяет переданные правила в цепочку правил, останавливает выполнение цепочки, если появилась ошибка. Выполняет правила слева направо
7
6
  * @example compose(isRequired(), isEmail());
8
7
  * @example compose(isRequired(), compose(isIncludeDot(), isIncludeComma()));
9
8
  */
10
- exports.compose = (0, createRule_1.createRule)((...rules) => (value) => rules.reduce((result, rule) => result || rule(value), undefined));
9
+ const compose = (...rules) => (value) => rules.reduce((result, rule) => result || rule(value), undefined);
10
+ exports.compose = compose;
@@ -1,7 +1,7 @@
1
- import { InitializedRule } from '../types';
1
+ import { InitializedRule, ValidationResult } from '../types';
2
2
  /**
3
3
  * @description Объединяет переданные правила в цепочку правил, выполняя все переданные правила, независимо от результата выполнения правил. Выполняет правила слева направо
4
4
  * @example composeAllSettled(isIncludeDot(), isIncludeComma());
5
5
  * @example compose(isRequired(), composeAllSettled(isIncludeDot(), isIncludeComma()));
6
6
  */
7
- export declare const composeAllSettled: import("../types").Rule<InitializedRule[]>;
7
+ export declare const composeAllSettled: (...rules: InitializedRule[]) => (value: unknown) => ValidationResult;
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.composeAllSettled = void 0;
4
- const createRule_1 = require("../createRule");
5
4
  /**
6
5
  * @description Объединяет переданные правила в цепочку правил, выполняя все переданные правила, независимо от результата выполнения правил. Выполняет правила слева направо
7
6
  * @example composeAllSettled(isIncludeDot(), isIncludeComma());
8
7
  * @example compose(isRequired(), composeAllSettled(isIncludeDot(), isIncludeComma()));
9
8
  */
10
- exports.composeAllSettled = (0, createRule_1.createRule)((...rules) => (value) => {
9
+ const composeAllSettled = (...rules) => (value) => {
11
10
  const errors = [];
12
11
  rules.forEach((rule) => {
13
12
  const error = rule(value);
@@ -22,4 +21,5 @@ exports.composeAllSettled = (0, createRule_1.createRule)((...rules) => (value) =
22
21
  return undefined;
23
22
  }
24
23
  return errors.length === 1 ? errors[0] : errors;
25
- });
24
+ };
25
+ exports.composeAllSettled = composeAllSettled;
package/constants.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const INCORRECT_MESSAGE = "\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u043E\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435";
2
+ export declare const CONTAINS_SPACES_REGEX: RegExp;
package/constants.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CONTAINS_SPACES_REGEX = exports.INCORRECT_MESSAGE = void 0;
4
+ exports.INCORRECT_MESSAGE = 'Некорректное значение';
5
+ exports.CONTAINS_SPACES_REGEX = /\s/g;
@@ -1,6 +1,14 @@
1
1
  import { Rule } from '../types';
2
2
  /**
3
3
  * @description Фабрика по созданию правил валидации.
4
- * @example createRule((max: number, message: string) => value => value > max ? message : undefined)
5
4
  */
6
- export declare const createRule: <Args extends unknown[]>(creator: Rule<Args>) => Rule<Args>;
5
+ export declare function createRule<Params extends object, RequiredParams extends true>(creator: Rule<Params & {
6
+ exclude?: (value: unknown) => boolean;
7
+ }, RequiredParams>): Rule<Params & {
8
+ exclude?: (value: unknown) => boolean;
9
+ }, RequiredParams>;
10
+ export declare function createRule<Params extends object, RequiredParams extends false>(creator: Rule<Params & {
11
+ exclude?: (value: unknown) => boolean;
12
+ }, RequiredParams>): Rule<Params & {
13
+ exclude?: (value: unknown) => boolean;
14
+ }, RequiredParams>;
@@ -1,9 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createRule = void 0;
4
- /**
5
- * @description Фабрика по созданию правил валидации.
6
- * @example createRule((max: number, message: string) => value => value > max ? message : undefined)
7
- */
8
- const createRule = (creator) => creator;
4
+ // Реализована перегрузка, поэтому используется any
5
+ // eslint-disable-next-line
6
+ function createRule(creator) {
7
+ // eslint-disable-next-line
8
+ return (params) => (value) => {
9
+ var _a;
10
+ if ((_a = params === null || params === void 0 ? void 0 : params.exclude) === null || _a === void 0 ? void 0 : _a.call(params, value)) {
11
+ return undefined;
12
+ }
13
+ return creator(params)(value);
14
+ };
15
+ }
9
16
  exports.createRule = createRule;
@@ -1,7 +1,7 @@
1
- import { InitializedRule } from '../types';
1
+ import { InitializedRule, ValidationResult } from '../types';
2
2
  /**
3
3
  * @description Объединяет переданные правила в цепочку правил, останавливает выполнение цепочки, если появилась ошибка. Выполняет правила слева направо
4
4
  * @example compose(isRequired(), isEmail());
5
5
  * @example compose(isRequired(), compose(isIncludeDot(), isIncludeComma()));
6
6
  */
7
- export declare const compose: import("../types").Rule<InitializedRule[]>;
7
+ export declare const compose: (...rules: InitializedRule[]) => (value: unknown) => ValidationResult;
@@ -1,7 +1,6 @@
1
- import { createRule } from '../createRule';
2
1
  /**
3
2
  * @description Объединяет переданные правила в цепочку правил, останавливает выполнение цепочки, если появилась ошибка. Выполняет правила слева направо
4
3
  * @example compose(isRequired(), isEmail());
5
4
  * @example compose(isRequired(), compose(isIncludeDot(), isIncludeComma()));
6
5
  */
7
- export const compose = createRule((...rules) => (value) => rules.reduce((result, rule) => result || rule(value), undefined));
6
+ export const compose = (...rules) => (value) => rules.reduce((result, rule) => result || rule(value), undefined);
@@ -1,7 +1,7 @@
1
- import { InitializedRule } from '../types';
1
+ import { InitializedRule, ValidationResult } from '../types';
2
2
  /**
3
3
  * @description Объединяет переданные правила в цепочку правил, выполняя все переданные правила, независимо от результата выполнения правил. Выполняет правила слева направо
4
4
  * @example composeAllSettled(isIncludeDot(), isIncludeComma());
5
5
  * @example compose(isRequired(), composeAllSettled(isIncludeDot(), isIncludeComma()));
6
6
  */
7
- export declare const composeAllSettled: import("../types").Rule<InitializedRule[]>;
7
+ export declare const composeAllSettled: (...rules: InitializedRule[]) => (value: unknown) => ValidationResult;
@@ -1,10 +1,9 @@
1
- import { createRule } from '../createRule';
2
1
  /**
3
2
  * @description Объединяет переданные правила в цепочку правил, выполняя все переданные правила, независимо от результата выполнения правил. Выполняет правила слева направо
4
3
  * @example composeAllSettled(isIncludeDot(), isIncludeComma());
5
4
  * @example compose(isRequired(), composeAllSettled(isIncludeDot(), isIncludeComma()));
6
5
  */
7
- export const composeAllSettled = createRule((...rules) => (value) => {
6
+ export const composeAllSettled = (...rules) => (value) => {
8
7
  const errors = [];
9
8
  rules.forEach((rule) => {
10
9
  const error = rule(value);
@@ -19,4 +18,4 @@ export const composeAllSettled = createRule((...rules) => (value) => {
19
18
  return undefined;
20
19
  }
21
20
  return errors.length === 1 ? errors[0] : errors;
22
- });
21
+ };
@@ -0,0 +1,2 @@
1
+ export declare const INCORRECT_MESSAGE = "\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u043E\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435";
2
+ export declare const CONTAINS_SPACES_REGEX: RegExp;
@@ -0,0 +1,2 @@
1
+ export const INCORRECT_MESSAGE = 'Некорректное значение';
2
+ export const CONTAINS_SPACES_REGEX = /\s/g;
@@ -1,6 +1,14 @@
1
1
  import { Rule } from '../types';
2
2
  /**
3
3
  * @description Фабрика по созданию правил валидации.
4
- * @example createRule((max: number, message: string) => value => value > max ? message : undefined)
5
4
  */
6
- export declare const createRule: <Args extends unknown[]>(creator: Rule<Args>) => Rule<Args>;
5
+ export declare function createRule<Params extends object, RequiredParams extends true>(creator: Rule<Params & {
6
+ exclude?: (value: unknown) => boolean;
7
+ }, RequiredParams>): Rule<Params & {
8
+ exclude?: (value: unknown) => boolean;
9
+ }, RequiredParams>;
10
+ export declare function createRule<Params extends object, RequiredParams extends false>(creator: Rule<Params & {
11
+ exclude?: (value: unknown) => boolean;
12
+ }, RequiredParams>): Rule<Params & {
13
+ exclude?: (value: unknown) => boolean;
14
+ }, RequiredParams>;
@@ -1,5 +1,12 @@
1
- /**
2
- * @description Фабрика по созданию правил валидации.
3
- * @example createRule((max: number, message: string) => value => value > max ? message : undefined)
4
- */
5
- export const createRule = (creator) => creator;
1
+ // Реализована перегрузка, поэтому используется any
2
+ // eslint-disable-next-line
3
+ export function createRule(creator) {
4
+ // eslint-disable-next-line
5
+ return (params) => (value) => {
6
+ var _a;
7
+ if ((_a = params === null || params === void 0 ? void 0 : params.exclude) === null || _a === void 0 ? void 0 : _a.call(params, value)) {
8
+ return undefined;
9
+ }
10
+ return creator(params)(value);
11
+ };
12
+ }
package/esm/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/esm/index.js 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';
@@ -0,0 +1 @@
1
+ export * from './isDate';
@@ -0,0 +1 @@
1
+ export * from './isDate';
@@ -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,23 @@
1
+ import { createRule } from '../createRule';
2
+ import { isEmptyString } from '../utils';
3
+ export const IS_DATE_RULE_DEFAULT_MESSAGE = 'Неверный формат даты';
4
+ /**
5
+ * @description Проверяет валидна ли дата
6
+ * @example isDate()('2011-11-12');
7
+ */
8
+ export const isDate = createRule(({ message = IS_DATE_RULE_DEFAULT_MESSAGE } = {}) => (value) => {
9
+ if (isEmptyString(value)) {
10
+ return undefined;
11
+ }
12
+ if (typeof value === 'string') {
13
+ const date = new Date(value);
14
+ if (!isNaN(date.getTime())) {
15
+ return undefined;
16
+ }
17
+ return message;
18
+ }
19
+ if (value instanceof Date && !isNaN(value.getTime())) {
20
+ return undefined;
21
+ }
22
+ return message;
23
+ });
@@ -0,0 +1 @@
1
+ export * from './isINNIP';
@@ -0,0 +1 @@
1
+ export * from './isINNIP';
@@ -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,39 @@
1
+ import { createRule } from '../createRule';
2
+ import { isEmptyString } from '../utils';
3
+ export const IS_INNIP_DEFAULT_MESSAGE = 'Некорректный ИНН ЮЛ';
4
+ const INNIP_LENGTH = 12;
5
+ const FIRST_INN_UL_DECODING = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8];
6
+ const SECOND_INN_UL_DECODING = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8];
7
+ const calcFirstCheckSumForInnUl = (arrSymbols) => (arrSymbols
8
+ .slice(0, -2)
9
+ .reduce((sum, symbol, index) => FIRST_INN_UL_DECODING[index] * Number(symbol) + sum, 0) %
10
+ 11) %
11
+ 10;
12
+ const calcSecondCheckSumForInnUl = (arrSymbols) => (arrSymbols
13
+ .slice(0, -1)
14
+ .reduce((sum, symbol, index) => SECOND_INN_UL_DECODING[index] * Number(symbol) + sum, 0) %
15
+ 11) %
16
+ 10;
17
+ /**
18
+ * @description Проверяет валиден ли ИНН ИП
19
+ * @example isINNIP()('384212952720');
20
+ */
21
+ export const isINNIP = createRule(({ message = IS_INNIP_DEFAULT_MESSAGE } = {}) => (value) => {
22
+ if (isEmptyString(value)) {
23
+ return undefined;
24
+ }
25
+ if (typeof value === 'string') {
26
+ if (value.length !== INNIP_LENGTH) {
27
+ return message;
28
+ }
29
+ const arrSymbols = value.split('');
30
+ const firstChecksum = calcFirstCheckSumForInnUl(arrSymbols);
31
+ const secondChecksum = calcSecondCheckSumForInnUl(arrSymbols);
32
+ if (Number(value[10]) !== firstChecksum &&
33
+ Number(value[11]) !== secondChecksum) {
34
+ return message;
35
+ }
36
+ return undefined;
37
+ }
38
+ return message;
39
+ });
@@ -0,0 +1 @@
1
+ export * from './isINNUL';
@@ -0,0 +1 @@
1
+ export * from './isINNUL';
@@ -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,34 @@
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
+ });
@@ -0,0 +1 @@
1
+ export { isMaxLength } from './isMaxLength';
@@ -0,0 +1 @@
1
+ export { isMaxLength } from './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,34 @@
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
+ });
@@ -0,0 +1 @@
1
+ export { isMaxValue } from './isMaxValue';
@@ -0,0 +1 @@
1
+ export { isMaxValue } from './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;
@@ -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 = (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
+ });
@@ -0,0 +1 @@
1
+ export * from './isMaybeNumber';
@@ -0,0 +1 @@
1
+ export * from './isMaybeNumber';
@@ -0,0 +1,10 @@
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;
@@ -0,0 +1,23 @@
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
+ });
@@ -0,0 +1 @@
1
+ export * from './isMinLength';
@@ -0,0 +1 @@
1
+ export * from './isMinLength';
@@ -0,0 +1,18 @@
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;
@@ -0,0 +1,34 @@
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
+ });
@@ -0,0 +1 @@
1
+ export { isMinValue } from './isMinValue';
@@ -0,0 +1 @@
1
+ export { isMinValue } from './isMinValue';