@astral/validations 4.21.2 → 4.22.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/README.md +55 -2
  2. package/any/any.d.ts +1 -1
  3. package/array/array.d.ts +2 -2
  4. package/arrayItem/arrayItem.d.ts +2 -2
  5. package/containsDifferentCases/containsDifferentCases.d.ts +1 -1
  6. package/containsNumbers/containsNumbers.d.ts +1 -1
  7. package/containsPunctuationMarks/containsPunctuationMarks.d.ts +1 -1
  8. package/core/errors/ArrayError/createArrayError/createArrayError.d.ts +1 -1
  9. package/core/errors/ErrorMap/createErrorMap/createErrorMap.d.ts +1 -1
  10. package/core/rule/createRule/createRule.d.ts +1 -1
  11. package/core/rule/required/required.d.ts +1 -1
  12. package/core/utils/index.d.ts +1 -0
  13. package/core/utils/index.js +1 -0
  14. package/core/utils/removeNonDigits/index.d.ts +1 -0
  15. package/core/utils/removeNonDigits/index.js +1 -0
  16. package/core/utils/removeNonDigits/removeNonDigits.d.ts +4 -0
  17. package/core/utils/removeNonDigits/removeNonDigits.js +6 -0
  18. package/deepPartial/deepPartial.d.ts +1 -1
  19. package/email/email.d.ts +2 -3
  20. package/emailOrPhone/constants.d.ts +2 -0
  21. package/emailOrPhone/constants.js +5 -0
  22. package/emailOrPhone/emailOrPhone.d.ts +15 -0
  23. package/emailOrPhone/emailOrPhone.js +29 -0
  24. package/emailOrPhone/index.d.ts +2 -0
  25. package/emailOrPhone/index.js +2 -0
  26. package/enabled/enabled.d.ts +1 -1
  27. package/guid/guid.d.ts +1 -1
  28. package/index.d.ts +1 -0
  29. package/index.js +1 -0
  30. package/innFL/innFL.d.ts +1 -1
  31. package/innIP/innIP.d.ts +1 -1
  32. package/innTwelveSymbols/innTwelveSymbols.d.ts +1 -1
  33. package/innUL/innUL.d.ts +1 -1
  34. package/integer/integer.d.ts +1 -1
  35. package/kpp/kpp.d.ts +1 -1
  36. package/length/length.d.ts +1 -1
  37. package/minYearsOld/minYearsOld.d.ts +1 -1
  38. package/mobilePhone/mobilePhone.d.ts +2 -3
  39. package/node/any/any.d.ts +1 -1
  40. package/node/array/array.d.ts +2 -2
  41. package/node/arrayItem/arrayItem.d.ts +2 -2
  42. package/node/containsDifferentCases/containsDifferentCases.d.ts +1 -1
  43. package/node/containsNumbers/containsNumbers.d.ts +1 -1
  44. package/node/containsPunctuationMarks/containsPunctuationMarks.d.ts +1 -1
  45. package/node/core/context/createContext/createContext.js +1 -2
  46. package/node/core/errors/ArrayError/createArrayError/createArrayError.d.ts +1 -1
  47. package/node/core/errors/ErrorMap/createErrorMap/createErrorMap.d.ts +1 -1
  48. package/node/core/guard/createGuard/createGuard.js +1 -2
  49. package/node/core/rule/createRule/createRule.d.ts +1 -1
  50. package/node/core/rule/required/required.d.ts +1 -1
  51. package/node/core/utils/index.d.ts +1 -0
  52. package/node/core/utils/index.js +1 -0
  53. package/node/core/utils/removeNonDigits/index.d.ts +1 -0
  54. package/node/core/utils/removeNonDigits/index.js +17 -0
  55. package/node/core/utils/removeNonDigits/removeNonDigits.d.ts +4 -0
  56. package/node/core/utils/removeNonDigits/removeNonDigits.js +10 -0
  57. package/node/deepPartial/deepPartial.d.ts +1 -1
  58. package/node/email/email.d.ts +2 -3
  59. package/node/emailOrPhone/constants.d.ts +2 -0
  60. package/node/emailOrPhone/constants.js +8 -0
  61. package/node/emailOrPhone/emailOrPhone.d.ts +15 -0
  62. package/node/emailOrPhone/emailOrPhone.js +33 -0
  63. package/node/emailOrPhone/index.d.ts +2 -0
  64. package/node/emailOrPhone/index.js +18 -0
  65. package/node/enabled/enabled.d.ts +1 -1
  66. package/node/guid/guid.d.ts +1 -1
  67. package/node/index.d.ts +1 -0
  68. package/node/index.js +5 -2
  69. package/node/innFL/innFL.d.ts +1 -1
  70. package/node/innIP/innIP.d.ts +1 -1
  71. package/node/innTwelveSymbols/innTwelveSymbols.d.ts +1 -1
  72. package/node/innUL/innUL.d.ts +1 -1
  73. package/node/integer/integer.d.ts +1 -1
  74. package/node/kpp/kpp.d.ts +1 -1
  75. package/node/length/length.d.ts +1 -1
  76. package/node/max/max.js +1 -2
  77. package/node/min/min.js +1 -2
  78. package/node/minYearsOld/minYearsOld.d.ts +1 -1
  79. package/node/minYearsOld/minYearsOld.js +1 -2
  80. package/node/mobilePhone/mobilePhone.d.ts +2 -3
  81. package/node/ogrnIP/ogrnIP.d.ts +1 -1
  82. package/node/ogrnUL/ogrnUL.d.ts +1 -1
  83. package/node/onlyNumber/onlyNumber.d.ts +1 -1
  84. package/node/or/or.d.ts +2 -2
  85. package/node/partial/partial.d.ts +1 -1
  86. package/node/passportCode/passportCode.d.ts +1 -1
  87. package/node/passportNumber/passportNumber.d.ts +1 -1
  88. package/node/passportSeries/passportSeries.d.ts +1 -1
  89. package/node/pattern/pattern.d.ts +1 -1
  90. package/node/personName/personName.d.ts +1 -1
  91. package/node/personPatronymic/personPatronymic.d.ts +1 -1
  92. package/node/personSurname/personSurname.d.ts +1 -1
  93. package/node/positiveNumber/positiveNumber.d.ts +1 -1
  94. package/node/rangeDateInterval/rangeDateInterval.d.ts +1 -1
  95. package/node/rangeDateMinMax/rangeDateMinMax.d.ts +1 -1
  96. package/node/rangeDateNotEqual/rangeDateNotEqual.d.ts +1 -1
  97. package/node/snils/snils.d.ts +1 -1
  98. package/node/snils/snils.js +1 -4
  99. package/node/textField/textField.d.ts +1 -1
  100. package/node/transform/transform.d.ts +2 -2
  101. package/node/when/when.d.ts +1 -1
  102. package/ogrnIP/ogrnIP.d.ts +1 -1
  103. package/ogrnUL/ogrnUL.d.ts +1 -1
  104. package/onlyNumber/onlyNumber.d.ts +1 -1
  105. package/or/or.d.ts +2 -2
  106. package/package.json +4 -4
  107. package/partial/partial.d.ts +1 -1
  108. package/passportCode/passportCode.d.ts +1 -1
  109. package/passportNumber/passportNumber.d.ts +1 -1
  110. package/passportSeries/passportSeries.d.ts +1 -1
  111. package/pattern/pattern.d.ts +1 -1
  112. package/personName/personName.d.ts +1 -1
  113. package/personPatronymic/personPatronymic.d.ts +1 -1
  114. package/personSurname/personSurname.d.ts +1 -1
  115. package/positiveNumber/positiveNumber.d.ts +1 -1
  116. package/rangeDateInterval/rangeDateInterval.d.ts +1 -1
  117. package/rangeDateMinMax/rangeDateMinMax.d.ts +1 -1
  118. package/rangeDateNotEqual/rangeDateNotEqual.d.ts +1 -1
  119. package/snils/snils.d.ts +1 -1
  120. package/snils/snils.js +2 -5
  121. package/textField/textField.d.ts +1 -1
  122. package/transform/transform.d.ts +2 -2
  123. package/when/when.d.ts +1 -1
package/README.md CHANGED
@@ -398,9 +398,9 @@ validate('example.ru');
398
398
 
399
399
 
400
400
  //Пользовательское сообщение для ошибки с максимальным количеством символов
401
- const validateEmail = email({ invalidLengthMessage: 'слишком длинный email' });
401
+ const validateEmail = email({ invalidLengthMessage: 'Слишком длинный email' });
402
402
 
403
- // { message: 'слишком длинный email' }
403
+ // { message: 'Слишком длинный email' }
404
404
  validateEmail('longlonglong.......')
405
405
 
406
406
  //Проверка email с разрешенной кирилицей и punycode
@@ -415,6 +415,59 @@ validateCyrillicEmail('asdasd@xn--h1alffa9fa.xn--p1ai')
415
415
 
416
416
  ---
417
417
 
418
+ ### emailOrPhone
419
+
420
+ Проверяет валиден ли email или мобильный телефон.
421
+ - Если строка содержит кириллицу, латиницу или символ @ - проверяется как email
422
+ - Иначе убираются все символы, кроме digits, и проверяется как mobilePhone
423
+
424
+
425
+ - для email работает с русскими доменами и punycode,
426
+ ```ts
427
+ import { string, emailOrPhone } from '@astral/validations';
428
+
429
+ const validate = string(emailOrPhone());
430
+
431
+ // undefined
432
+ validate('example@mail.ru');
433
+
434
+ // { message: 'Некорректный E-mail' }
435
+ validate('example.ru');
436
+
437
+
438
+ // Пользовательское сообщение для ошибки с максимальным количеством символов
439
+ const validateEmail = emailOrPhone({ invalidLengthMessage: 'Слишком длинный email' });
440
+
441
+ // { message: 'Слишком длинный email' }
442
+ validateEmail('longlonglong.......')
443
+
444
+ //Проверка email с разрешенной кирилицей и punycode
445
+ const validateCyrillicEmail = emailOrPhone({ allowCyrillic: true });
446
+
447
+ // undefined
448
+ validateCyrillicEmail('test@домен.рф')
449
+ validateCyrillicEmail('asdasd@xn--h1alffa9fa.xn--p1ai')
450
+
451
+ ```
452
+ - для телефона работает с произвольными масками
453
+ ```ts
454
+ import { string, emailOrPhone } from '@astral/validations';
455
+
456
+ const validate = string(emailOrPhone());
457
+
458
+ // undefined
459
+ validate('79999999999')
460
+ validate('7 (999) 99-99-999')
461
+ validate('+79999999999')
462
+ validate('89999999999')
463
+
464
+ // { message: 'Некорректный формат' }
465
+ validate('8999999')
466
+ validate('%$^*%$(')
467
+ ```
468
+
469
+ ---
470
+
418
471
  ### guid
419
472
 
420
473
  Проверяет валиден ли GUID.
package/any/any.d.ts CHANGED
@@ -20,4 +20,4 @@ import { type ValidationRule } from '../core';
20
20
  * validate('13.22.2022');
21
21
  * ```
22
22
  */
23
- export declare const any: <TLastSchemaValues extends Record<string, unknown>>(...rules: ValidationRule<unknown, TLastSchemaValues>[]) => (value: unknown, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
23
+ export declare const any: <TLastSchemaValues extends Record<string, unknown>>(...rules: ValidationRule<unknown, TLastSchemaValues>[]) => (value: unknown, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<unknown, TLastSchemaValues>>;
package/array/array.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type ValidationRule } from '../core';
1
+ import { type ValidationRule, type ValidationTypes } from '../core';
2
2
  /**
3
3
  * Guard для массива. Проверяет value на соответствие типу array
4
4
  * @param rules - правила валидаций, применяющиеся ко всему массиву
@@ -12,4 +12,4 @@ import { type ValidationRule } from '../core';
12
12
  * validateArray(value);
13
13
  * ```
14
14
  */
15
- export declare const array: <TItem extends unknown, TLastSchemaValues extends Record<string, unknown> = {}>(...rules: ValidationRule<Array<TItem>, TLastSchemaValues>[]) => import("../core").Guard<TLastSchemaValues, {}>;
15
+ export declare const array: <TItem extends ValidationTypes, TLastSchemaValues extends Record<string, unknown> = {}>(...rules: ValidationRule<Array<TItem>, TLastSchemaValues>[]) => import("../core").Guard<TLastSchemaValues, {}>;
@@ -1,4 +1,4 @@
1
- import { type ValidationRule } from '../core';
1
+ import { type ValidationRule, type ValidationTypes } from '../core';
2
2
  /**
3
3
  * Применяет правила к каждому элементу массива
4
4
  * @param rules - правила валидации, которое применится к каждому элементу массива
@@ -24,4 +24,4 @@ import { type ValidationRule } from '../core';
24
24
  * validateArray(values);
25
25
  * ```
26
26
  */
27
- export declare const arrayItem: <TItem extends unknown, TLastSchemaValues extends Record<string, unknown> = {}>(...rules: ValidationRule<TItem, TLastSchemaValues>[]) => (value: TItem[], prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
27
+ export declare const arrayItem: <TItem extends ValidationTypes, TLastSchemaValues extends Record<string, unknown> = {}>(...rules: ValidationRule<TItem, TLastSchemaValues>[]) => (value: TItem[], prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<TItem[], TLastSchemaValues>>;
@@ -12,5 +12,5 @@ type ContainsDifferentCasesParams = {
12
12
  * validate('testTEST');
13
13
  * ```
14
14
  */
15
- export declare const containsDifferentCases: <TLastSchemaValues extends Record<string, unknown>>(params?: ContainsDifferentCasesParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
15
+ export declare const containsDifferentCases: <TLastSchemaValues extends Record<string, unknown>>(params?: ContainsDifferentCasesParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<string, TLastSchemaValues>>;
16
16
  export {};
@@ -12,5 +12,5 @@ type ContainsNumbersParams = {
12
12
  * validate('test123');
13
13
  * ```
14
14
  */
15
- export declare const containsNumbers: <TLastSchemaValues extends Record<string, unknown>>(params?: ContainsNumbersParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
15
+ export declare const containsNumbers: <TLastSchemaValues extends Record<string, unknown>>(params?: ContainsNumbersParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<string, TLastSchemaValues>>;
16
16
  export {};
@@ -12,5 +12,5 @@ type ContainsPunctuationMarksParams = {
12
12
  * validate('test?');
13
13
  * ```
14
14
  */
15
- export declare const containsPunctuationMarks: <TLastSchemaValues extends Record<string, unknown>>(params?: ContainsPunctuationMarksParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
15
+ export declare const containsPunctuationMarks: <TLastSchemaValues extends Record<string, unknown>>(params?: ContainsPunctuationMarksParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<string, TLastSchemaValues>>;
16
16
  export {};
@@ -2,4 +2,4 @@ import { ValidationArrayError, type ValidationArrayErrorCause } from '../ArrayEr
2
2
  /**
3
3
  * Создает array ошибок. Ошибка предназначена для результата валидации массива
4
4
  */
5
- export declare const createArrayError: (errorArray: ValidationArrayErrorCause['errorArray']) => ValidationArrayError;
5
+ export declare const createArrayError: (errorArray: ValidationArrayErrorCause["errorArray"]) => ValidationArrayError;
@@ -2,4 +2,4 @@ import { ValidationErrorMap, type ValidationObjectErrorCause } from '../ErrorMap
2
2
  /**
3
3
  * Создает map ошибок валидаций. Ошибка предназначена для генерации результата валидации объекта
4
4
  */
5
- export declare const createErrorMap: (errorMap: ValidationObjectErrorCause['errorMap']) => ValidationErrorMap;
5
+ export declare const createErrorMap: (errorMap: ValidationObjectErrorCause["errorMap"]) => ValidationErrorMap;
@@ -30,5 +30,5 @@ type RuleExecutor<ValidationType extends ValidationTypes, TLastSchemaValues exte
30
30
  * }, params);
31
31
  * ```
32
32
  */
33
- export declare const createRule: <ValidationType extends unknown, TLastSchemaValues extends Record<string, unknown> = {}>(executor: RuleExecutor<ValidationType, TLastSchemaValues>, commonParams?: CommonRuleParams<ValidationType>) => (value: Parameters<IndependentValidationRule<ValidationType, TLastSchemaValues>>[0], prevCtx?: Parameters<IndependentValidationRule<ValidationType, TLastSchemaValues>>[1]) => ReturnType<IndependentValidationRule<ValidationType, TLastSchemaValues>>;
33
+ export declare const createRule: <ValidationType extends ValidationTypes, TLastSchemaValues extends Record<string, unknown> = {}>(executor: RuleExecutor<ValidationType, TLastSchemaValues>, commonParams?: CommonRuleParams<ValidationType>) => (value: Parameters<IndependentValidationRule<ValidationType, TLastSchemaValues>>[0], prevCtx?: Parameters<IndependentValidationRule<ValidationType, TLastSchemaValues>>[1]) => ReturnType<IndependentValidationRule<ValidationType, TLastSchemaValues>>;
34
34
  export {};
@@ -8,4 +8,4 @@ export declare const required: ({ message, }?: {
8
8
  * @default Обязательно
9
9
  */
10
10
  message?: string;
11
- }) => (value: unknown, prevCtx?: import("../..").ValidationContext<{}> | undefined) => import("../..").ValidationResult;
11
+ }) => (value: unknown, prevCtx?: import("../..").ValidationContext<{}> | undefined) => ReturnType<import("..").IndependentValidationRule<unknown, {}>>;
@@ -6,3 +6,4 @@ export * from './isStartsWithAndEndsWithLetter';
6
6
  export * from './isStringOfZeros';
7
7
  export * from './isValidFullNameLength';
8
8
  export * from './resetTime';
9
+ export * from './removeNonDigits';
@@ -6,3 +6,4 @@ export * from './isStartsWithAndEndsWithLetter';
6
6
  export * from './isStringOfZeros';
7
7
  export * from './isValidFullNameLength';
8
8
  export * from './resetTime';
9
+ export * from './removeNonDigits';
@@ -0,0 +1 @@
1
+ export * from './removeNonDigits';
@@ -0,0 +1 @@
1
+ export * from './removeNonDigits';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Удаляет из строки все символы, кроме цифр
3
+ */
4
+ export declare const removeNonDigits: (value: string) => string;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Удаляет из строки все символы, кроме цифр
3
+ */
4
+ export const removeNonDigits = (value) => {
5
+ return value.replace(/\D/g, '');
6
+ };
@@ -18,4 +18,4 @@ import { type Guard } from '../core';
18
18
  * const result = validate({ info: { info: {} } });
19
19
  * ```
20
20
  */
21
- export declare const deepPartial: <TLastSchemaValues extends Record<string, unknown>>(guard: Guard<TLastSchemaValues>) => (value: unknown, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
21
+ export declare const deepPartial: <TLastSchemaValues extends Record<string, unknown>>(guard: Guard<TLastSchemaValues>) => (value: unknown, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<unknown, TLastSchemaValues>>;
package/email/email.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- type EmailParams = {
1
+ export type EmailParams = {
2
2
  /**
3
3
  * Замена стандартного сообщения ошибки.
4
4
  */
@@ -26,5 +26,4 @@ type EmailParams = {
26
26
  * validate('example@mail.ru');
27
27
  * ```
28
28
  */
29
- export declare const email: <TLastSchemaValues extends Record<string, unknown>>(params?: EmailParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
30
- export {};
29
+ export declare const email: <TLastSchemaValues extends Record<string, unknown>>(params?: EmailParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<string, TLastSchemaValues>>;
@@ -0,0 +1,2 @@
1
+ import { type ErrorInfo } from '../core';
2
+ export declare const EMAIL_OR_PHONE_ERROR_INFO: ErrorInfo;
@@ -0,0 +1,5 @@
1
+ import { createErrorCode } from '../core';
2
+ export const EMAIL_OR_PHONE_ERROR_INFO = {
3
+ code: createErrorCode('mobileOrPhone'),
4
+ message: 'Некорректный формат',
5
+ };
@@ -0,0 +1,15 @@
1
+ import { type EmailParams } from '../email';
2
+ import { type MobilePhoneParams } from '../mobilePhone';
3
+ export type EmailOrPhoneParams = EmailParams & MobilePhoneParams;
4
+ /**
5
+ * Проверяет валидность email или мобильного телефона.
6
+ * - Если строка содержит кириллицу, латиницу или символ @ - проверяется как email
7
+ * - Иначе убираются все символы, кроме digits, и проверяется как mobilePhone
8
+ * @example
9
+ * ```ts
10
+ * const validate = string(emailOrPhone());
11
+ * validate('example@mail.ru');
12
+ * validate('79999999999');
13
+ * ```
14
+ */
15
+ export declare const emailOrPhone: <TLastSchemaValues extends Record<string, unknown>>(params?: EmailOrPhoneParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<string, TLastSchemaValues>>;
@@ -0,0 +1,29 @@
1
+ import { checkPhone, checkProbablyEmail, normalizePhone } from '@astral/utils';
2
+ import { createRule } from '../core';
3
+ import { email } from '../email';
4
+ import { mobilePhone } from '../mobilePhone';
5
+ import { EMAIL_OR_PHONE_ERROR_INFO } from './constants';
6
+ /**
7
+ * Проверяет валидность email или мобильного телефона.
8
+ * - Если строка содержит кириллицу, латиницу или символ @ - проверяется как email
9
+ * - Иначе убираются все символы, кроме digits, и проверяется как mobilePhone
10
+ * @example
11
+ * ```ts
12
+ * const validate = string(emailOrPhone());
13
+ * validate('example@mail.ru');
14
+ * validate('79999999999');
15
+ * ```
16
+ */
17
+ export const emailOrPhone = (params) => createRule((value, ctx) => {
18
+ if (checkProbablyEmail(value)) {
19
+ return email(params)(value, ctx);
20
+ }
21
+ const normalizedPhone = normalizePhone(value);
22
+ if (checkPhone(normalizedPhone)) {
23
+ return mobilePhone(params)(normalizedPhone, ctx);
24
+ }
25
+ return ctx.createError({
26
+ message: (params === null || params === void 0 ? void 0 : params.message) || EMAIL_OR_PHONE_ERROR_INFO.message,
27
+ code: EMAIL_OR_PHONE_ERROR_INFO.code,
28
+ });
29
+ }, { exclude: params === null || params === void 0 ? void 0 : params.exclude });
@@ -0,0 +1,2 @@
1
+ export * from './constants';
2
+ export * from './emailOrPhone';
@@ -0,0 +1,2 @@
1
+ export * from './constants';
2
+ export * from './emailOrPhone';
@@ -30,5 +30,5 @@ type Params<TLastSchemaValues extends Record<string, unknown>> = {
30
30
  * const result2 = validate({ isAgree: true, name: '' });
31
31
  * ```
32
32
  */
33
- export declare const enabled: <TLastSchemaValues extends Record<string, unknown>>({ is, then, }: Params<TLastSchemaValues>) => (value: unknown, prevCtx?: ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
33
+ export declare const enabled: <TLastSchemaValues extends Record<string, unknown>>({ is, then, }: Params<TLastSchemaValues>) => (value: unknown, prevCtx?: ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<unknown, TLastSchemaValues>>;
34
34
  export {};
package/guid/guid.d.ts CHANGED
@@ -12,5 +12,5 @@ type GuidParams = {
12
12
  * validate('C56A4180-65AA-42EC-A945-5FD21DEC0538');
13
13
  * ```
14
14
  */
15
- export declare const guid: <TLastSchemaValues extends Record<string, unknown>>(params?: GuidParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
15
+ export declare const guid: <TLastSchemaValues extends Record<string, unknown>>(params?: GuidParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<string, TLastSchemaValues>>;
16
16
  export {};
package/index.d.ts CHANGED
@@ -22,6 +22,7 @@ export { containsPunctuationMarks, CONTAINS_PUNCTUATION_MARKS_ERROR_CODE, } from
22
22
  export { containsDifferentCases, CONTAINS_DIFFERENT_CASES_ERROR_CODE, } from './containsDifferentCases';
23
23
  export { toPlainError } from './toPlainError';
24
24
  export { email, LENGTH_EMAIL_ERROR_INFO, INVALID_EMAIL_ERROR_INFO, } from './email';
25
+ export { emailOrPhone, EMAIL_OR_PHONE_ERROR_INFO } from './emailOrPhone';
25
26
  export { guid, INVALID_GUID_ERROR_INFO } from './guid';
26
27
  export { length, STRING_LENGTH_ERROR_CODE } from './length';
27
28
  export { mobilePhone, MOBILE_PHONE_ERROR_INFO } from './mobilePhone';
package/index.js CHANGED
@@ -22,6 +22,7 @@ export { containsPunctuationMarks, CONTAINS_PUNCTUATION_MARKS_ERROR_CODE, } from
22
22
  export { containsDifferentCases, CONTAINS_DIFFERENT_CASES_ERROR_CODE, } from './containsDifferentCases';
23
23
  export { toPlainError } from './toPlainError';
24
24
  export { email, LENGTH_EMAIL_ERROR_INFO, INVALID_EMAIL_ERROR_INFO, } from './email';
25
+ export { emailOrPhone, EMAIL_OR_PHONE_ERROR_INFO } from './emailOrPhone';
25
26
  export { guid, INVALID_GUID_ERROR_INFO } from './guid';
26
27
  export { length, STRING_LENGTH_ERROR_CODE } from './length';
27
28
  export { mobilePhone, MOBILE_PHONE_ERROR_INFO } from './mobilePhone';
package/innFL/innFL.d.ts CHANGED
@@ -13,5 +13,5 @@ type InnFLParams = CommonRuleParams<string> & {
13
13
  * validate('7728168971');
14
14
  * ```
15
15
  */
16
- export declare const innFL: <TLastSchemaValues extends Record<string, unknown>>(params?: InnFLParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
16
+ export declare const innFL: <TLastSchemaValues extends Record<string, unknown>>(params?: InnFLParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<string, TLastSchemaValues>>;
17
17
  export {};
package/innIP/innIP.d.ts CHANGED
@@ -13,5 +13,5 @@ type InnIPParams = CommonRuleParams<string> & {
13
13
  * validate('384212952720');
14
14
  * ```
15
15
  */
16
- export declare const innIP: <TLastSchemaValues extends Record<string, unknown>>(params?: InnIPParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
16
+ export declare const innIP: <TLastSchemaValues extends Record<string, unknown>>(params?: InnIPParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<string, TLastSchemaValues>>;
17
17
  export {};
@@ -13,5 +13,5 @@ type InnTwelveSymbolsParams = CommonRuleParams<string> & {
13
13
  * validate('7728168971');
14
14
  * ```
15
15
  */
16
- export declare const innTwelveSymbols: <TLastSchemaValues extends Record<string, unknown>>(params?: InnTwelveSymbolsParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
16
+ export declare const innTwelveSymbols: <TLastSchemaValues extends Record<string, unknown>>(params?: InnTwelveSymbolsParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<string, TLastSchemaValues>>;
17
17
  export {};
package/innUL/innUL.d.ts CHANGED
@@ -13,5 +13,5 @@ type InnULParams = CommonRuleParams<string> & {
13
13
  * validate('7728168971');
14
14
  * ```
15
15
  */
16
- export declare const innUL: <TLastSchemaValues extends Record<string, unknown>>(params?: InnULParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
16
+ export declare const innUL: <TLastSchemaValues extends Record<string, unknown>>(params?: InnULParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<string, TLastSchemaValues>>;
17
17
  export {};
@@ -21,5 +21,5 @@ type IntegerParams = {
21
21
  * validate(3.14)
22
22
  * ```
23
23
  */
24
- export declare const integer: <TLastSchemaValues extends Record<string, unknown>>(params?: IntegerParams) => (value: number, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
24
+ export declare const integer: <TLastSchemaValues extends Record<string, unknown>>(params?: IntegerParams) => (value: number, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<number, TLastSchemaValues>>;
25
25
  export {};
package/kpp/kpp.d.ts CHANGED
@@ -13,5 +13,5 @@ type KPPParams = CommonRuleParams<string> & {
13
13
  * validate('770201001');
14
14
  * ```
15
15
  */
16
- export declare const kpp: <TLastSchemaValues extends Record<string, unknown>>(params?: KPPParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
16
+ export declare const kpp: <TLastSchemaValues extends Record<string, unknown>>(params?: KPPParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<string, TLastSchemaValues>>;
17
17
  export {};
@@ -18,5 +18,5 @@ type LengthParams = {
18
18
  * validate('va')
19
19
  *
20
20
  */
21
- export declare const length: <TLastSchemaValues extends Record<string, unknown>>(len: number, params?: LengthParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
21
+ export declare const length: <TLastSchemaValues extends Record<string, unknown>>(len: number, params?: LengthParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<string, TLastSchemaValues>>;
22
22
  export {};
@@ -20,5 +20,5 @@ type MinYearsOldParams = {
20
20
  * );
21
21
  * ```
22
22
  */
23
- export declare function minYearsOld<ValidationType, TLastSchemaValues extends Record<string, unknown> = {}>(age: number, params?: MinYearsOldParams): (value: ValidationType, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
23
+ export declare function minYearsOld<ValidationType, TLastSchemaValues extends Record<string, unknown> = {}>(age: number, params?: MinYearsOldParams): (value: ValidationType, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<ValidationType, TLastSchemaValues>>;
24
24
  export {};
@@ -1,5 +1,5 @@
1
1
  import { type CommonRuleParams } from '../core';
2
- type MobilePhoneParams = CommonRuleParams<string> & {
2
+ export type MobilePhoneParams = CommonRuleParams<string> & {
3
3
  /**
4
4
  * Замена стандартного сообщения ошибки.
5
5
  */
@@ -15,5 +15,4 @@ type MobilePhoneParams = CommonRuleParams<string> & {
15
15
  * validate('79999999999');
16
16
  * ```
17
17
  */
18
- export declare const mobilePhone: <TLastSchemaValues extends Record<string, unknown>>(params?: MobilePhoneParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
19
- export {};
18
+ export declare const mobilePhone: <TLastSchemaValues extends Record<string, unknown>>(params?: MobilePhoneParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<string, TLastSchemaValues>>;
package/node/any/any.d.ts CHANGED
@@ -20,4 +20,4 @@ import { type ValidationRule } from '../core';
20
20
  * validate('13.22.2022');
21
21
  * ```
22
22
  */
23
- export declare const any: <TLastSchemaValues extends Record<string, unknown>>(...rules: ValidationRule<unknown, TLastSchemaValues>[]) => (value: unknown, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
23
+ export declare const any: <TLastSchemaValues extends Record<string, unknown>>(...rules: ValidationRule<unknown, TLastSchemaValues>[]) => (value: unknown, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<unknown, TLastSchemaValues>>;
@@ -1,4 +1,4 @@
1
- import { type ValidationRule } from '../core';
1
+ import { type ValidationRule, type ValidationTypes } from '../core';
2
2
  /**
3
3
  * Guard для массива. Проверяет value на соответствие типу array
4
4
  * @param rules - правила валидаций, применяющиеся ко всему массиву
@@ -12,4 +12,4 @@ import { type ValidationRule } from '../core';
12
12
  * validateArray(value);
13
13
  * ```
14
14
  */
15
- export declare const array: <TItem extends unknown, TLastSchemaValues extends Record<string, unknown> = {}>(...rules: ValidationRule<Array<TItem>, TLastSchemaValues>[]) => import("../core").Guard<TLastSchemaValues, {}>;
15
+ export declare const array: <TItem extends ValidationTypes, TLastSchemaValues extends Record<string, unknown> = {}>(...rules: ValidationRule<Array<TItem>, TLastSchemaValues>[]) => import("../core").Guard<TLastSchemaValues, {}>;
@@ -1,4 +1,4 @@
1
- import { type ValidationRule } from '../core';
1
+ import { type ValidationRule, type ValidationTypes } from '../core';
2
2
  /**
3
3
  * Применяет правила к каждому элементу массива
4
4
  * @param rules - правила валидации, которое применится к каждому элементу массива
@@ -24,4 +24,4 @@ import { type ValidationRule } from '../core';
24
24
  * validateArray(values);
25
25
  * ```
26
26
  */
27
- export declare const arrayItem: <TItem extends unknown, TLastSchemaValues extends Record<string, unknown> = {}>(...rules: ValidationRule<TItem, TLastSchemaValues>[]) => (value: TItem[], prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
27
+ export declare const arrayItem: <TItem extends ValidationTypes, TLastSchemaValues extends Record<string, unknown> = {}>(...rules: ValidationRule<TItem, TLastSchemaValues>[]) => (value: TItem[], prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<TItem[], TLastSchemaValues>>;
@@ -12,5 +12,5 @@ type ContainsDifferentCasesParams = {
12
12
  * validate('testTEST');
13
13
  * ```
14
14
  */
15
- export declare const containsDifferentCases: <TLastSchemaValues extends Record<string, unknown>>(params?: ContainsDifferentCasesParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
15
+ export declare const containsDifferentCases: <TLastSchemaValues extends Record<string, unknown>>(params?: ContainsDifferentCasesParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<string, TLastSchemaValues>>;
16
16
  export {};
@@ -12,5 +12,5 @@ type ContainsNumbersParams = {
12
12
  * validate('test123');
13
13
  * ```
14
14
  */
15
- export declare const containsNumbers: <TLastSchemaValues extends Record<string, unknown>>(params?: ContainsNumbersParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
15
+ export declare const containsNumbers: <TLastSchemaValues extends Record<string, unknown>>(params?: ContainsNumbersParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<string, TLastSchemaValues>>;
16
16
  export {};
@@ -12,5 +12,5 @@ type ContainsPunctuationMarksParams = {
12
12
  * validate('test?');
13
13
  * ```
14
14
  */
15
- export declare const containsPunctuationMarks: <TLastSchemaValues extends Record<string, unknown>>(params?: ContainsPunctuationMarksParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
15
+ export declare const containsPunctuationMarks: <TLastSchemaValues extends Record<string, unknown>>(params?: ContainsPunctuationMarksParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<string, TLastSchemaValues>>;
16
16
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createContext = void 0;
3
+ exports.createContext = createContext;
4
4
  const errors_1 = require("../../errors");
5
5
  /**
6
6
  * Создает context валидации. Используется внутри фабрик guard и rule
@@ -22,4 +22,3 @@ function createContext(prevCtx, value, { lastSchemaValue, isOptional } = {}) {
22
22
  createError: errors_1.createSimpleError,
23
23
  };
24
24
  }
25
- exports.createContext = createContext;
@@ -2,4 +2,4 @@ import { ValidationArrayError, type ValidationArrayErrorCause } from '../ArrayEr
2
2
  /**
3
3
  * Создает array ошибок. Ошибка предназначена для результата валидации массива
4
4
  */
5
- export declare const createArrayError: (errorArray: ValidationArrayErrorCause['errorArray']) => ValidationArrayError;
5
+ export declare const createArrayError: (errorArray: ValidationArrayErrorCause["errorArray"]) => ValidationArrayError;
@@ -2,4 +2,4 @@ import { ValidationErrorMap, type ValidationObjectErrorCause } from '../ErrorMap
2
2
  /**
3
3
  * Создает map ошибок валидаций. Ошибка предназначена для генерации результата валидации объекта
4
4
  */
5
- export declare const createErrorMap: (errorMap: ValidationObjectErrorCause['errorMap']) => ValidationErrorMap;
5
+ export declare const createErrorMap: (errorMap: ValidationObjectErrorCause["errorMap"]) => ValidationErrorMap;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createGuard = void 0;
3
+ exports.createGuard = createGuard;
4
4
  const rule_1 = require("../../rule");
5
5
  const context_1 = require("../../context");
6
6
  function createGuard(executor) {
@@ -25,4 +25,3 @@ function createGuard(executor) {
25
25
  };
26
26
  return createInnerGuard();
27
27
  }
28
- exports.createGuard = createGuard;
@@ -30,5 +30,5 @@ type RuleExecutor<ValidationType extends ValidationTypes, TLastSchemaValues exte
30
30
  * }, params);
31
31
  * ```
32
32
  */
33
- export declare const createRule: <ValidationType extends unknown, TLastSchemaValues extends Record<string, unknown> = {}>(executor: RuleExecutor<ValidationType, TLastSchemaValues>, commonParams?: CommonRuleParams<ValidationType>) => (value: Parameters<IndependentValidationRule<ValidationType, TLastSchemaValues>>[0], prevCtx?: Parameters<IndependentValidationRule<ValidationType, TLastSchemaValues>>[1]) => ReturnType<IndependentValidationRule<ValidationType, TLastSchemaValues>>;
33
+ export declare const createRule: <ValidationType extends ValidationTypes, TLastSchemaValues extends Record<string, unknown> = {}>(executor: RuleExecutor<ValidationType, TLastSchemaValues>, commonParams?: CommonRuleParams<ValidationType>) => (value: Parameters<IndependentValidationRule<ValidationType, TLastSchemaValues>>[0], prevCtx?: Parameters<IndependentValidationRule<ValidationType, TLastSchemaValues>>[1]) => ReturnType<IndependentValidationRule<ValidationType, TLastSchemaValues>>;
34
34
  export {};
@@ -8,4 +8,4 @@ export declare const required: ({ message, }?: {
8
8
  * @default Обязательно
9
9
  */
10
10
  message?: string;
11
- }) => (value: unknown, prevCtx?: import("../..").ValidationContext<{}> | undefined) => import("../..").ValidationResult;
11
+ }) => (value: unknown, prevCtx?: import("../..").ValidationContext<{}> | undefined) => ReturnType<import("..").IndependentValidationRule<unknown, {}>>;
@@ -6,3 +6,4 @@ export * from './isStartsWithAndEndsWithLetter';
6
6
  export * from './isStringOfZeros';
7
7
  export * from './isValidFullNameLength';
8
8
  export * from './resetTime';
9
+ export * from './removeNonDigits';
@@ -22,3 +22,4 @@ __exportStar(require("./isStartsWithAndEndsWithLetter"), exports);
22
22
  __exportStar(require("./isStringOfZeros"), exports);
23
23
  __exportStar(require("./isValidFullNameLength"), exports);
24
24
  __exportStar(require("./resetTime"), exports);
25
+ __exportStar(require("./removeNonDigits"), exports);
@@ -0,0 +1 @@
1
+ export * from './removeNonDigits';
@@ -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("./removeNonDigits"), exports);
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Удаляет из строки все символы, кроме цифр
3
+ */
4
+ export declare const removeNonDigits: (value: string) => string;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.removeNonDigits = void 0;
4
+ /**
5
+ * Удаляет из строки все символы, кроме цифр
6
+ */
7
+ const removeNonDigits = (value) => {
8
+ return value.replace(/\D/g, '');
9
+ };
10
+ exports.removeNonDigits = removeNonDigits;
@@ -18,4 +18,4 @@ import { type Guard } from '../core';
18
18
  * const result = validate({ info: { info: {} } });
19
19
  * ```
20
20
  */
21
- export declare const deepPartial: <TLastSchemaValues extends Record<string, unknown>>(guard: Guard<TLastSchemaValues>) => (value: unknown, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
21
+ export declare const deepPartial: <TLastSchemaValues extends Record<string, unknown>>(guard: Guard<TLastSchemaValues>) => (value: unknown, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<unknown, TLastSchemaValues>>;
@@ -1,4 +1,4 @@
1
- type EmailParams = {
1
+ export type EmailParams = {
2
2
  /**
3
3
  * Замена стандартного сообщения ошибки.
4
4
  */
@@ -26,5 +26,4 @@ type EmailParams = {
26
26
  * validate('example@mail.ru');
27
27
  * ```
28
28
  */
29
- export declare const email: <TLastSchemaValues extends Record<string, unknown>>(params?: EmailParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
30
- export {};
29
+ export declare const email: <TLastSchemaValues extends Record<string, unknown>>(params?: EmailParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<string, TLastSchemaValues>>;