@astral/validations 4.11.0 → 4.12.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.
package/README.md CHANGED
@@ -36,6 +36,8 @@
36
36
  - [mobilePhone](#mobilePhone)
37
37
  - [innUL](#innUL)
38
38
  - [innIP](#innIP)
39
+ - [innFL](#innFL)
40
+ - [innTwelveSymbols](#innTwelveSymbols)
39
41
  - [kpp](#kpp)
40
42
  - [ogrnIP](#ogrnIP)
41
43
  - [ogrnUL](#ogrnUL)
@@ -616,6 +618,51 @@ validate('+384212952720')
616
618
 
617
619
  ---
618
620
 
621
+ ### innFL
622
+
623
+ Проверяет валиден ли ИНН ФЛ
624
+
625
+ ```ts
626
+ import { string, innFL } from '@astral/validations';
627
+
628
+ const validate = string(innFL());
629
+
630
+ // undefined
631
+ validate('384212952720')
632
+ validate('000000000000')
633
+
634
+ // { message: 'Некорректный ИНН ФЛ' }
635
+ validate('3842129527')
636
+ validate('384212952a20')
637
+ validate('+384212952720')
638
+ ```
639
+
640
+ :information_source: Поддерживает [exclude](#exclusion-managing)
641
+
642
+ ---
643
+
644
+ ### innTwelveSymbols
645
+
646
+ Проверяет валиден ли ИНН из 12 символов
647
+
648
+ ```ts
649
+ import { string, innTwelveSymbols } from '@astral/validations';
650
+
651
+ const validate = string(innTwelveSymbols());
652
+
653
+ // undefined
654
+ validate('384212952720')
655
+
656
+ // { message: 'Некорректный ИНН' }
657
+ validate('3842129527')
658
+ validate('384212952a20')
659
+ validate('+384212952720')
660
+ ```
661
+
662
+ :information_source: Поддерживает [exclude](#exclusion-managing)
663
+
664
+ ---
665
+
619
666
  ### kpp
620
667
 
621
668
  Проверяет валиден ли КПП
package/index.d.ts CHANGED
@@ -24,7 +24,9 @@ export { guid, INVALID_GUID_ERROR_INFO } from './guid';
24
24
  export { length, STRING_LENGTH_ERROR_CODE } from './length';
25
25
  export { mobilePhone, MOBILE_PHONE_ERROR_INFO } from './mobilePhone';
26
26
  export { innUL, INN_UL_ERROR_INFO } from './innUL';
27
+ export { innTwelveSymbols, INN_12_SYMBOLS_ERROR_INFO, } from './innTwelveSymbols';
27
28
  export { innIP, INN_IP_ERROR_INFO } from './innIP';
29
+ export { innFL, INN_FL_ERROR_INFO } from './innFL';
28
30
  export { kpp, INVALID_KPP_ERROR_INFO, KPP_DOUBLE_ZERO_START_ERROR_INFO, KPP_ZEROS_ONLY_ERROR_INFO, } from './kpp';
29
31
  export { snils, SNILS_ERROR_INFO } from './snils';
30
32
  export { createRule, REQUIRED_ERROR_INFO, type ValidationRule } from './core';
package/index.js CHANGED
@@ -24,7 +24,9 @@ export { guid, INVALID_GUID_ERROR_INFO } from './guid';
24
24
  export { length, STRING_LENGTH_ERROR_CODE } from './length';
25
25
  export { mobilePhone, MOBILE_PHONE_ERROR_INFO } from './mobilePhone';
26
26
  export { innUL, INN_UL_ERROR_INFO } from './innUL';
27
+ export { innTwelveSymbols, INN_12_SYMBOLS_ERROR_INFO, } from './innTwelveSymbols';
27
28
  export { innIP, INN_IP_ERROR_INFO } from './innIP';
29
+ export { innFL, INN_FL_ERROR_INFO } from './innFL';
28
30
  export { kpp, INVALID_KPP_ERROR_INFO, KPP_DOUBLE_ZERO_START_ERROR_INFO, KPP_ZEROS_ONLY_ERROR_INFO, } from './kpp';
29
31
  export { snils, SNILS_ERROR_INFO } from './snils';
30
32
  export { createRule, REQUIRED_ERROR_INFO } from './core';
@@ -0,0 +1,2 @@
1
+ import { ErrorInfo } from '../core';
2
+ export declare const INN_FL_ERROR_INFO: ErrorInfo;
@@ -0,0 +1,5 @@
1
+ import { createErrorCode } from '../core';
2
+ export const INN_FL_ERROR_INFO = {
3
+ code: createErrorCode('innFL'),
4
+ message: 'Некорректный ИНН ФЛ',
5
+ };
@@ -0,0 +1,2 @@
1
+ export * from './innFL';
2
+ export * from './constants';
package/innFL/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './innFL';
2
+ export * from './constants';
@@ -0,0 +1,17 @@
1
+ import { CommonRuleParams } from '../core';
2
+ type InnFLParams = CommonRuleParams<string> & {
3
+ /**
4
+ * @description Замена стандартного сообщения ошибки.
5
+ */
6
+ message?: string;
7
+ };
8
+ /**
9
+ * @description Проверяет валиден ли ИНН ФЛ
10
+ * @example
11
+ * ```ts
12
+ * const validate = string(innFL());
13
+ * validate('7728168971');
14
+ * ```
15
+ */
16
+ export declare const innFL: <TLastSchemaValues extends Record<string, unknown>>(params?: InnFLParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
17
+ export {};
package/innFL/innFL.js ADDED
@@ -0,0 +1,21 @@
1
+ import { createRule } from '../core';
2
+ import { innTwelveSymbols } from '../innTwelveSymbols';
3
+ import { INN_FL_ERROR_INFO } from './constants';
4
+ /**
5
+ * @description Проверяет валиден ли ИНН ФЛ
6
+ * @example
7
+ * ```ts
8
+ * const validate = string(innFL());
9
+ * validate('7728168971');
10
+ * ```
11
+ */
12
+ export const innFL = (params) => createRule((value, ctx) => {
13
+ const createInnFLError = () => ctx.createError({
14
+ message: (params === null || params === void 0 ? void 0 : params.message) || INN_FL_ERROR_INFO.message,
15
+ code: INN_FL_ERROR_INFO.code,
16
+ });
17
+ if (innTwelveSymbols()(value) !== undefined) {
18
+ return createInnFLError();
19
+ }
20
+ return undefined;
21
+ }, { exclude: params === null || params === void 0 ? void 0 : params.exclude });
@@ -1,5 +1,2 @@
1
1
  import { ErrorInfo } from '../core';
2
2
  export declare const INN_IP_ERROR_INFO: ErrorInfo;
3
- export declare const INN_IP_LENGTH = 12;
4
- export declare const FIRST_INN_IP_DECODING: number[];
5
- export declare const SECOND_INN_IP_DECODING: number[];
@@ -3,6 +3,3 @@ export const INN_IP_ERROR_INFO = {
3
3
  code: createErrorCode('innIP'),
4
4
  message: 'Некорректный ИНН ИП',
5
5
  };
6
- export const INN_IP_LENGTH = 12;
7
- export const FIRST_INN_IP_DECODING = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8];
8
- export const SECOND_INN_IP_DECODING = [3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8];
package/innIP/innIP.js CHANGED
@@ -1,15 +1,6 @@
1
1
  import { createRule, isNoDoubleZeroStart, isStringOfZeros, } from '../core';
2
- import { FIRST_INN_IP_DECODING, INN_IP_ERROR_INFO, INN_IP_LENGTH, SECOND_INN_IP_DECODING, } from './constants';
3
- const calcFirstCheckSumForInnIP = (arrSymbols) => (arrSymbols
4
- .slice(0, -2)
5
- .reduce((sum, symbol, index) => FIRST_INN_IP_DECODING[index] * Number(symbol) + sum, 0) %
6
- 11) %
7
- 10;
8
- const calcSecondCheckSumForInnIP = (arrSymbols) => (arrSymbols
9
- .slice(0, -1)
10
- .reduce((sum, symbol, index) => SECOND_INN_IP_DECODING[index] * Number(symbol) + sum, 0) %
11
- 11) %
12
- 10;
2
+ import { innTwelveSymbols } from '../innTwelveSymbols';
3
+ import { INN_IP_ERROR_INFO } from './constants';
13
4
  /**
14
5
  * @description Проверяет валиден ли ИНН ИП
15
6
  * @example
@@ -29,14 +20,7 @@ export const innIP = (params) => createRule((value, ctx) => {
29
20
  if (!isNoDoubleZeroStart(value)) {
30
21
  return createInnIPError();
31
22
  }
32
- if (value.length !== INN_IP_LENGTH) {
33
- return createInnIPError();
34
- }
35
- const arrSymbols = value.split('');
36
- const firstChecksum = calcFirstCheckSumForInnIP(arrSymbols);
37
- const secondChecksum = calcSecondCheckSumForInnIP(arrSymbols);
38
- if (Number(value[10]) !== firstChecksum &&
39
- Number(value[11]) !== secondChecksum) {
23
+ if (innTwelveSymbols()(value) !== undefined) {
40
24
  return createInnIPError();
41
25
  }
42
26
  return undefined;
@@ -0,0 +1,5 @@
1
+ import { ErrorInfo } from '../core';
2
+ export declare const INN_12_SYMBOLS_ERROR_INFO: ErrorInfo;
3
+ export declare const INN_12_SYMBOLS_LENGTH = 12;
4
+ export declare const FIRST_INN_12_SYMBOLS_DECODING: number[];
5
+ export declare const SECOND_INN_12_SYMBOLS_DECODING: number[];
@@ -0,0 +1,10 @@
1
+ import { createErrorCode } from '../core';
2
+ export const INN_12_SYMBOLS_ERROR_INFO = {
3
+ code: createErrorCode('innTwelveSymbols'),
4
+ message: 'Некорректный ИНН',
5
+ };
6
+ export const INN_12_SYMBOLS_LENGTH = 12;
7
+ export const FIRST_INN_12_SYMBOLS_DECODING = [7, 2, 4, 10, 3, 5, 9, 4, 6, 8];
8
+ export const SECOND_INN_12_SYMBOLS_DECODING = [
9
+ 3, 7, 2, 4, 10, 3, 5, 9, 4, 6, 8,
10
+ ];
@@ -0,0 +1,2 @@
1
+ export * from './innTwelveSymbols';
2
+ export * from './constants';
@@ -0,0 +1,2 @@
1
+ export * from './innTwelveSymbols';
2
+ export * from './constants';
@@ -0,0 +1,17 @@
1
+ import { CommonRuleParams } from '../core';
2
+ type InnTwelveSymbolsParams = CommonRuleParams<string> & {
3
+ /**
4
+ * @description Замена стандартного сообщения ошибки.
5
+ */
6
+ message?: string;
7
+ };
8
+ /**
9
+ * @description Проверяет, валиден ли ИНН из 12 символов
10
+ * @example
11
+ * ```ts
12
+ * const validate = string(innTwelveSymbols());
13
+ * validate('7728168971');
14
+ * ```
15
+ */
16
+ export declare const innTwelveSymbols: <TLastSchemaValues extends Record<string, unknown>>(params?: InnTwelveSymbolsParams) => (value: string, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => import("../core").ValidationResult;
17
+ export {};
@@ -0,0 +1,37 @@
1
+ import { createRule } from '../core';
2
+ import { FIRST_INN_12_SYMBOLS_DECODING, INN_12_SYMBOLS_ERROR_INFO, INN_12_SYMBOLS_LENGTH, SECOND_INN_12_SYMBOLS_DECODING, } from './constants';
3
+ const firstCheckSumForInnTwelveSymbols = (arrSymbols) => (arrSymbols
4
+ .slice(0, -2)
5
+ .reduce((sum, symbol, index) => FIRST_INN_12_SYMBOLS_DECODING[index] * Number(symbol) + sum, 0) %
6
+ 11) %
7
+ 10;
8
+ const secondCheckSumForInnTwelveSymbols = (arrSymbols) => (arrSymbols
9
+ .slice(0, -1)
10
+ .reduce((sum, symbol, index) => SECOND_INN_12_SYMBOLS_DECODING[index] * Number(symbol) + sum, 0) %
11
+ 11) %
12
+ 10;
13
+ /**
14
+ * @description Проверяет, валиден ли ИНН из 12 символов
15
+ * @example
16
+ * ```ts
17
+ * const validate = string(innTwelveSymbols());
18
+ * validate('7728168971');
19
+ * ```
20
+ */
21
+ export const innTwelveSymbols = (params) => createRule((value, ctx) => {
22
+ const createInnTwelveSymbolsError = () => ctx.createError({
23
+ message: (params === null || params === void 0 ? void 0 : params.message) || INN_12_SYMBOLS_ERROR_INFO.message,
24
+ code: INN_12_SYMBOLS_ERROR_INFO.code,
25
+ });
26
+ if (value.length !== INN_12_SYMBOLS_LENGTH) {
27
+ return createInnTwelveSymbolsError();
28
+ }
29
+ const arrSymbols = value.split('');
30
+ const firstChecksum = firstCheckSumForInnTwelveSymbols(arrSymbols);
31
+ const secondChecksum = secondCheckSumForInnTwelveSymbols(arrSymbols);
32
+ if (Number(value[10]) !== firstChecksum ||
33
+ Number(value[11]) !== secondChecksum) {
34
+ return createInnTwelveSymbolsError();
35
+ }
36
+ return undefined;
37
+ }, { exclude: params === null || params === void 0 ? void 0 : params.exclude });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astral/validations",
3
- "version": "4.11.0",
3
+ "version": "4.12.0",
4
4
  "browser": "./index.js",
5
5
  "main": "./index.js",
6
6
  "dependencies": {