@astral/validations 0.1.0 → 1.0.0-test.1670422830

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 (174) hide show
  1. package/compose/compose.d.ts +7 -0
  2. package/compose/compose.js +10 -0
  3. package/compose/index.d.ts +1 -0
  4. package/{isString → compose}/index.js +1 -1
  5. package/composeAllSettled/composeAllSettled.d.ts +7 -0
  6. package/composeAllSettled/composeAllSettled.js +25 -0
  7. package/composeAllSettled/index.d.ts +1 -0
  8. package/composeAllSettled/index.js +17 -0
  9. package/composeToString/composeToString.d.ts +8 -0
  10. package/composeToString/composeToString.js +18 -0
  11. package/composeToString/index.d.ts +1 -0
  12. package/composeToString/index.js +17 -0
  13. package/constants.d.ts +2 -0
  14. package/constants.js +5 -0
  15. package/createRule/createRule.d.ts +10 -2
  16. package/createRule/createRule.js +12 -5
  17. package/esm/compose/compose.d.ts +7 -0
  18. package/esm/compose/compose.js +6 -0
  19. package/esm/compose/index.d.ts +1 -0
  20. package/esm/compose/index.js +1 -0
  21. package/esm/composeAllSettled/composeAllSettled.d.ts +7 -0
  22. package/esm/composeAllSettled/composeAllSettled.js +21 -0
  23. package/esm/composeAllSettled/index.d.ts +1 -0
  24. package/esm/composeAllSettled/index.js +1 -0
  25. package/esm/composeToString/composeToString.d.ts +8 -0
  26. package/esm/composeToString/composeToString.js +14 -0
  27. package/esm/composeToString/index.d.ts +1 -0
  28. package/esm/composeToString/index.js +1 -0
  29. package/esm/constants.d.ts +2 -0
  30. package/esm/constants.js +2 -0
  31. package/esm/createRule/createRule.d.ts +10 -2
  32. package/esm/createRule/createRule.js +12 -5
  33. package/esm/index.d.ts +18 -0
  34. package/esm/index.js +18 -0
  35. package/esm/isDate/index.d.ts +1 -0
  36. package/esm/isDate/index.js +1 -0
  37. package/esm/isDate/isDate.d.ts +10 -0
  38. package/esm/isDate/isDate.js +23 -0
  39. package/esm/isINNIP/index.d.ts +1 -0
  40. package/esm/isINNIP/index.js +1 -0
  41. package/esm/isINNIP/isINNIP.d.ts +10 -0
  42. package/esm/isINNIP/isINNIP.js +39 -0
  43. package/esm/isINNUL/index.d.ts +1 -0
  44. package/esm/isINNUL/index.js +1 -0
  45. package/esm/isINNUL/isINNUL.d.ts +10 -0
  46. package/esm/isINNUL/isINNUL.js +34 -0
  47. package/esm/isMaxLength/index.d.ts +1 -0
  48. package/esm/isMaxLength/index.js +1 -0
  49. package/esm/isMaxLength/isMaxLength.d.ts +18 -0
  50. package/esm/isMaxLength/isMaxLength.js +34 -0
  51. package/esm/isMaxValue/index.d.ts +1 -0
  52. package/esm/isMaxValue/index.js +1 -0
  53. package/esm/isMaxValue/isMaxValue.d.ts +17 -0
  54. package/esm/isMaxValue/isMaxValue.js +35 -0
  55. package/esm/isMaybeNumber/index.d.ts +1 -0
  56. package/esm/isMaybeNumber/index.js +1 -0
  57. package/esm/isMaybeNumber/isMaybeNumber.d.ts +10 -0
  58. package/esm/isMaybeNumber/isMaybeNumber.js +23 -0
  59. package/esm/isMinLength/index.d.ts +1 -0
  60. package/esm/isMinLength/index.js +1 -0
  61. package/esm/isMinLength/isMinLength.d.ts +18 -0
  62. package/esm/isMinLength/isMinLength.js +34 -0
  63. package/esm/isMinValue/index.d.ts +1 -0
  64. package/esm/isMinValue/index.js +1 -0
  65. package/esm/isMinValue/isMinValue.d.ts +17 -0
  66. package/esm/isMinValue/isMinValue.js +35 -0
  67. package/esm/isMobilePhone/index.d.ts +1 -0
  68. package/esm/isMobilePhone/index.js +1 -0
  69. package/esm/isMobilePhone/isMobilePhone.d.ts +10 -0
  70. package/esm/isMobilePhone/isMobilePhone.js +20 -0
  71. package/esm/isOGRNIP/index.d.ts +1 -0
  72. package/esm/isOGRNIP/index.js +1 -0
  73. package/esm/isOGRNIP/isOGRNIP.d.ts +10 -0
  74. package/esm/isOGRNIP/isOGRNIP.js +26 -0
  75. package/esm/isOGRNUL/index.d.ts +1 -0
  76. package/esm/isOGRNUL/index.js +1 -0
  77. package/esm/isOGRNUL/isOGRNUL.d.ts +10 -0
  78. package/esm/isOGRNUL/isOGRNUL.js +26 -0
  79. package/esm/isRequired/index.d.ts +1 -0
  80. package/esm/isRequired/index.js +1 -0
  81. package/esm/isRequired/isRequired.d.ts +11 -0
  82. package/esm/isRequired/isRequired.js +23 -0
  83. package/esm/isSNILS/index.d.ts +1 -0
  84. package/esm/isSNILS/index.js +1 -0
  85. package/esm/isSNILS/isSNILS.d.ts +10 -0
  86. package/esm/isSNILS/isSNILS.js +62 -0
  87. package/esm/types.d.ts +4 -1
  88. package/esm/utils/index.d.ts +1 -0
  89. package/esm/utils/index.js +1 -0
  90. package/esm/utils/isEmptyString.d.ts +4 -0
  91. package/esm/utils/isEmptyString.js +6 -0
  92. package/esm/yupAdapter/index.d.ts +1 -0
  93. package/esm/yupAdapter/index.js +1 -0
  94. package/esm/yupAdapter/yupAdapter.d.ts +8 -0
  95. package/esm/yupAdapter/yupAdapter.js +11 -0
  96. package/index.d.ts +18 -0
  97. package/index.js +18 -0
  98. package/isDate/index.d.ts +1 -0
  99. package/isDate/index.js +17 -0
  100. package/isDate/isDate.d.ts +10 -0
  101. package/isDate/isDate.js +26 -0
  102. package/isINNIP/index.d.ts +1 -0
  103. package/isINNIP/index.js +17 -0
  104. package/isINNIP/isINNIP.d.ts +10 -0
  105. package/isINNIP/isINNIP.js +42 -0
  106. package/isINNUL/index.d.ts +1 -0
  107. package/isINNUL/index.js +17 -0
  108. package/isINNUL/isINNUL.d.ts +10 -0
  109. package/isINNUL/isINNUL.js +37 -0
  110. package/isMaxLength/index.d.ts +1 -0
  111. package/isMaxLength/index.js +5 -0
  112. package/isMaxLength/isMaxLength.d.ts +18 -0
  113. package/isMaxLength/isMaxLength.js +41 -0
  114. package/isMaxValue/index.d.ts +1 -0
  115. package/isMaxValue/index.js +5 -0
  116. package/isMaxValue/isMaxValue.d.ts +17 -0
  117. package/isMaxValue/isMaxValue.js +39 -0
  118. package/isMaybeNumber/index.d.ts +1 -0
  119. package/isMaybeNumber/index.js +17 -0
  120. package/isMaybeNumber/isMaybeNumber.d.ts +10 -0
  121. package/isMaybeNumber/isMaybeNumber.js +26 -0
  122. package/isMinLength/index.d.ts +1 -0
  123. package/isMinLength/index.js +17 -0
  124. package/isMinLength/isMinLength.d.ts +18 -0
  125. package/isMinLength/isMinLength.js +41 -0
  126. package/isMinValue/index.d.ts +1 -0
  127. package/isMinValue/index.js +5 -0
  128. package/isMinValue/isMinValue.d.ts +17 -0
  129. package/isMinValue/isMinValue.js +39 -0
  130. package/isMobilePhone/index.d.ts +1 -0
  131. package/isMobilePhone/index.js +17 -0
  132. package/isMobilePhone/isMobilePhone.d.ts +10 -0
  133. package/isMobilePhone/isMobilePhone.js +23 -0
  134. package/isOGRNIP/index.d.ts +1 -0
  135. package/isOGRNIP/index.js +17 -0
  136. package/isOGRNIP/isOGRNIP.d.ts +10 -0
  137. package/isOGRNIP/isOGRNIP.js +29 -0
  138. package/isOGRNUL/index.d.ts +1 -0
  139. package/isOGRNUL/index.js +17 -0
  140. package/isOGRNUL/isOGRNUL.d.ts +10 -0
  141. package/isOGRNUL/isOGRNUL.js +29 -0
  142. package/isRequired/index.d.ts +1 -0
  143. package/isRequired/index.js +17 -0
  144. package/isRequired/isRequired.d.ts +11 -0
  145. package/isRequired/isRequired.js +29 -0
  146. package/isSNILS/index.d.ts +1 -0
  147. package/isSNILS/index.js +17 -0
  148. package/isSNILS/isSNILS.d.ts +10 -0
  149. package/isSNILS/isSNILS.js +65 -0
  150. package/package.json +15 -5
  151. package/types.d.ts +4 -1
  152. package/utils/index.d.ts +1 -0
  153. package/utils/index.js +17 -0
  154. package/utils/isEmptyString.d.ts +4 -0
  155. package/utils/isEmptyString.js +10 -0
  156. package/yupAdapter/index.d.ts +1 -0
  157. package/yupAdapter/index.js +17 -0
  158. package/yupAdapter/yupAdapter.d.ts +8 -0
  159. package/yupAdapter/yupAdapter.js +15 -0
  160. package/createRule/createRule.test.d.ts +0 -1
  161. package/createRule/createRule.test.js +0 -9
  162. package/esm/createRule/createRule.test.d.ts +0 -1
  163. package/esm/createRule/createRule.test.js +0 -7
  164. package/esm/isString/index.d.ts +0 -1
  165. package/esm/isString/index.js +0 -1
  166. package/esm/isString/isString.d.ts +0 -6
  167. package/esm/isString/isString.js +0 -12
  168. package/esm/isString/isString.test.d.ts +0 -1
  169. package/esm/isString/isString.test.js +0 -13
  170. package/isString/index.d.ts +0 -1
  171. package/isString/isString.d.ts +0 -6
  172. package/isString/isString.js +0 -15
  173. package/isString/isString.test.d.ts +0 -1
  174. package/isString/isString.test.js +0 -15
@@ -0,0 +1,7 @@
1
+ import { InitializedRule, ValidationResult } from '../types';
2
+ /**
3
+ * @description Объединяет переданные правила в цепочку правил, останавливает выполнение цепочки, если появилась ошибка. Выполняет правила слева направо
4
+ * @example compose(isRequired(), isEmail());
5
+ * @example compose(isRequired(), compose(isIncludeDot(), isIncludeComma()));
6
+ */
7
+ export declare const compose: (...rules: InitializedRule[]) => (value: unknown) => ValidationResult;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compose = void 0;
4
+ /**
5
+ * @description Объединяет переданные правила в цепочку правил, останавливает выполнение цепочки, если появилась ошибка. Выполняет правила слева направо
6
+ * @example compose(isRequired(), isEmail());
7
+ * @example compose(isRequired(), compose(isIncludeDot(), isIncludeComma()));
8
+ */
9
+ const compose = (...rules) => (value) => rules.reduce((result, rule) => result || rule(value), undefined);
10
+ exports.compose = compose;
@@ -0,0 +1 @@
1
+ export * from './compose';
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./isString"), exports);
17
+ __exportStar(require("./compose"), exports);
@@ -0,0 +1,7 @@
1
+ import { InitializedRule, ValidationResult } from '../types';
2
+ /**
3
+ * @description Объединяет переданные правила в цепочку правил, выполняя все переданные правила, независимо от результата выполнения правил. Выполняет правила слева направо
4
+ * @example composeAllSettled(isIncludeDot(), isIncludeComma());
5
+ * @example compose(isRequired(), composeAllSettled(isIncludeDot(), isIncludeComma()));
6
+ */
7
+ export declare const composeAllSettled: (...rules: InitializedRule[]) => (value: unknown) => ValidationResult;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.composeAllSettled = void 0;
4
+ /**
5
+ * @description Объединяет переданные правила в цепочку правил, выполняя все переданные правила, независимо от результата выполнения правил. Выполняет правила слева направо
6
+ * @example composeAllSettled(isIncludeDot(), isIncludeComma());
7
+ * @example compose(isRequired(), composeAllSettled(isIncludeDot(), isIncludeComma()));
8
+ */
9
+ const composeAllSettled = (...rules) => (value) => {
10
+ const errors = [];
11
+ rules.forEach((rule) => {
12
+ const error = rule(value);
13
+ if (Array.isArray(error)) {
14
+ errors.push(...error);
15
+ }
16
+ if (typeof error === 'string') {
17
+ errors.push(error);
18
+ }
19
+ });
20
+ if (!errors.length) {
21
+ return undefined;
22
+ }
23
+ return errors.length === 1 ? errors[0] : errors;
24
+ };
25
+ exports.composeAllSettled = composeAllSettled;
@@ -0,0 +1 @@
1
+ export * from './composeAllSettled';
@@ -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("./composeAllSettled"), exports);
@@ -0,0 +1,8 @@
1
+ import { InitializedRule } from '../types';
2
+ /**
3
+ * @description Объединяет правила в цепочку и форматирует результат в одну строку. Останаваливается при возникновении ошибки. Работает слева направо
4
+ * Подходит в качестве адаптера к react-final-form
5
+ * @example composeToString(isIncludeDot(), isIncludeComma());
6
+ * @example composeToString(isRequired(), composeToString(isIncludeDot(), isIncludeComma()));
7
+ */
8
+ export declare const composeToString: (...rules: InitializedRule[]) => (value?: unknown) => string | undefined;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.composeToString = void 0;
4
+ const compose_1 = require("../compose");
5
+ /**
6
+ * @description Объединяет правила в цепочку и форматирует результат в одну строку. Останаваливается при возникновении ошибки. Работает слева направо
7
+ * Подходит в качестве адаптера к react-final-form
8
+ * @example composeToString(isIncludeDot(), isIncludeComma());
9
+ * @example composeToString(isRequired(), composeToString(isIncludeDot(), isIncludeComma()));
10
+ */
11
+ const composeToString = (...rules) => (value) => {
12
+ const validationResult = (0, compose_1.compose)(...rules)(value);
13
+ if (Array.isArray(validationResult)) {
14
+ return validationResult[0];
15
+ }
16
+ return validationResult;
17
+ };
18
+ exports.composeToString = composeToString;
@@ -0,0 +1 @@
1
+ export * from './composeToString';
@@ -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("./composeToString"), exports);
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
- * @example createRule((max: number, message: string) => value => value > max ? message : undefined)
4
3
  * @description Фабрика по созданию правил валидации.
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
- * @example createRule((max: number, message: string) => value => value > max ? message : undefined)
6
- * @description Фабрика по созданию правил валидации.
7
- */
8
- var createRule = function (creator) { return 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;
@@ -0,0 +1,7 @@
1
+ import { InitializedRule, ValidationResult } from '../types';
2
+ /**
3
+ * @description Объединяет переданные правила в цепочку правил, останавливает выполнение цепочки, если появилась ошибка. Выполняет правила слева направо
4
+ * @example compose(isRequired(), isEmail());
5
+ * @example compose(isRequired(), compose(isIncludeDot(), isIncludeComma()));
6
+ */
7
+ export declare const compose: (...rules: InitializedRule[]) => (value: unknown) => ValidationResult;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @description Объединяет переданные правила в цепочку правил, останавливает выполнение цепочки, если появилась ошибка. Выполняет правила слева направо
3
+ * @example compose(isRequired(), isEmail());
4
+ * @example compose(isRequired(), compose(isIncludeDot(), isIncludeComma()));
5
+ */
6
+ export const compose = (...rules) => (value) => rules.reduce((result, rule) => result || rule(value), undefined);
@@ -0,0 +1 @@
1
+ export * from './compose';
@@ -0,0 +1 @@
1
+ export * from './compose';
@@ -0,0 +1,7 @@
1
+ import { InitializedRule, ValidationResult } from '../types';
2
+ /**
3
+ * @description Объединяет переданные правила в цепочку правил, выполняя все переданные правила, независимо от результата выполнения правил. Выполняет правила слева направо
4
+ * @example composeAllSettled(isIncludeDot(), isIncludeComma());
5
+ * @example compose(isRequired(), composeAllSettled(isIncludeDot(), isIncludeComma()));
6
+ */
7
+ export declare const composeAllSettled: (...rules: InitializedRule[]) => (value: unknown) => ValidationResult;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @description Объединяет переданные правила в цепочку правил, выполняя все переданные правила, независимо от результата выполнения правил. Выполняет правила слева направо
3
+ * @example composeAllSettled(isIncludeDot(), isIncludeComma());
4
+ * @example compose(isRequired(), composeAllSettled(isIncludeDot(), isIncludeComma()));
5
+ */
6
+ export const composeAllSettled = (...rules) => (value) => {
7
+ const errors = [];
8
+ rules.forEach((rule) => {
9
+ const error = rule(value);
10
+ if (Array.isArray(error)) {
11
+ errors.push(...error);
12
+ }
13
+ if (typeof error === 'string') {
14
+ errors.push(error);
15
+ }
16
+ });
17
+ if (!errors.length) {
18
+ return undefined;
19
+ }
20
+ return errors.length === 1 ? errors[0] : errors;
21
+ };
@@ -0,0 +1 @@
1
+ export * from './composeAllSettled';
@@ -0,0 +1 @@
1
+ export * from './composeAllSettled';
@@ -0,0 +1,8 @@
1
+ import { InitializedRule } from '../types';
2
+ /**
3
+ * @description Объединяет правила в цепочку и форматирует результат в одну строку. Останаваливается при возникновении ошибки. Работает слева направо
4
+ * Подходит в качестве адаптера к react-final-form
5
+ * @example composeToString(isIncludeDot(), isIncludeComma());
6
+ * @example composeToString(isRequired(), composeToString(isIncludeDot(), isIncludeComma()));
7
+ */
8
+ export declare const composeToString: (...rules: InitializedRule[]) => (value?: unknown) => string | undefined;
@@ -0,0 +1,14 @@
1
+ import { compose } from '../compose';
2
+ /**
3
+ * @description Объединяет правила в цепочку и форматирует результат в одну строку. Останаваливается при возникновении ошибки. Работает слева направо
4
+ * Подходит в качестве адаптера к react-final-form
5
+ * @example composeToString(isIncludeDot(), isIncludeComma());
6
+ * @example composeToString(isRequired(), composeToString(isIncludeDot(), isIncludeComma()));
7
+ */
8
+ export const composeToString = (...rules) => (value) => {
9
+ const validationResult = compose(...rules)(value);
10
+ if (Array.isArray(validationResult)) {
11
+ return validationResult[0];
12
+ }
13
+ return validationResult;
14
+ };
@@ -0,0 +1 @@
1
+ export * from './composeToString';
@@ -0,0 +1 @@
1
+ export * from './composeToString';
@@ -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
- * @example createRule((max: number, message: string) => value => value > max ? message : undefined)
4
3
  * @description Фабрика по созданию правил валидации.
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
- * @example createRule((max: number, message: string) => value => value > max ? message : undefined)
3
- * @description Фабрика по созданию правил валидации.
4
- */
5
- export var createRule = function (creator) { return 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
@@ -1 +1,19 @@
1
1
  export * from './createRule';
2
+ export * from './yupAdapter';
3
+ export * from './compose';
4
+ export * from './composeAllSettled';
5
+ export * from './composeToString';
6
+ export * from './isRequired';
7
+ export * from './types';
8
+ export * from './isINNUL';
9
+ export * from './isINNIP';
10
+ export * from './isMobilePhone';
11
+ export * from './isOGRNIP';
12
+ export * from './isOGRNUL';
13
+ export * from './isMinLength';
14
+ export * from './isMaxLength';
15
+ export * from './isMaxValue';
16
+ export * from './isMinValue';
17
+ export * from './isMaybeNumber';
18
+ export * from './isDate';
19
+ export * from './isSNILS';
package/esm/index.js CHANGED
@@ -1 +1,19 @@
1
1
  export * from './createRule';
2
+ export * from './yupAdapter';
3
+ export * from './compose';
4
+ export * from './composeAllSettled';
5
+ export * from './composeToString';
6
+ export * from './isRequired';
7
+ export * from './types';
8
+ export * from './isINNUL';
9
+ export * from './isINNIP';
10
+ export * from './isMobilePhone';
11
+ export * from './isOGRNIP';
12
+ export * from './isOGRNUL';
13
+ export * from './isMinLength';
14
+ export * from './isMaxLength';
15
+ export * from './isMaxValue';
16
+ export * from './isMinValue';
17
+ export * from './isMaybeNumber';
18
+ export * from './isDate';
19
+ 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;