@astral/validations 4.2.0 → 4.3.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/index.d.ts +1 -1
- package/index.js +1 -1
- package/kpp/constants.d.ts +2 -0
- package/kpp/constants.js +10 -2
- package/kpp/kpp.js +14 -4
- package/package.json +1 -1
package/index.d.ts
CHANGED
@@ -19,7 +19,7 @@ export { email, LENGTH_EMAIL_ERROR_INFO, INVALID_EMAIL_ERROR_INFO, } from './ema
|
|
19
19
|
export { mobilePhone, MOBILE_PHONE_ERROR_INFO } from './mobilePhone';
|
20
20
|
export { innUL, INN_UL_ERROR_INFO } from './innUL';
|
21
21
|
export { innIP, INN_IP_ERROR_INFO } from './innIP';
|
22
|
-
export { kpp, INVALID_KPP_ERROR_INFO } from './kpp';
|
22
|
+
export { kpp, INVALID_KPP_ERROR_INFO, KPP_DOUBLE_ZERO_START_ERROR_INFO, KPP_ZEROS_ONLY_ERROR_INFO, } from './kpp';
|
23
23
|
export { snils, SNILS_ERROR_INFO } from './snils';
|
24
24
|
export { createRule, REQUIRED_ERROR_INFO, type ValidationRule } from './core';
|
25
25
|
export { ogrnUL, OGRN_UL_ERROR_INFO } from './ogrnUL';
|
package/index.js
CHANGED
@@ -19,7 +19,7 @@ export { email, LENGTH_EMAIL_ERROR_INFO, INVALID_EMAIL_ERROR_INFO, } from './ema
|
|
19
19
|
export { mobilePhone, MOBILE_PHONE_ERROR_INFO } from './mobilePhone';
|
20
20
|
export { innUL, INN_UL_ERROR_INFO } from './innUL';
|
21
21
|
export { innIP, INN_IP_ERROR_INFO } from './innIP';
|
22
|
-
export { kpp, INVALID_KPP_ERROR_INFO } from './kpp';
|
22
|
+
export { kpp, INVALID_KPP_ERROR_INFO, KPP_DOUBLE_ZERO_START_ERROR_INFO, KPP_ZEROS_ONLY_ERROR_INFO, } from './kpp';
|
23
23
|
export { snils, SNILS_ERROR_INFO } from './snils';
|
24
24
|
export { createRule, REQUIRED_ERROR_INFO } from './core';
|
25
25
|
export { ogrnUL, OGRN_UL_ERROR_INFO } from './ogrnUL';
|
package/kpp/constants.d.ts
CHANGED
package/kpp/constants.js
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
import { createErrorCode } from '../core';
|
2
2
|
export const INVALID_KPP_ERROR_INFO = {
|
3
|
-
code: createErrorCode('kpp-invalid'),
|
4
|
-
message: '
|
3
|
+
code: createErrorCode('kpp-invalid-pattern'),
|
4
|
+
message: 'Проверьте КПП',
|
5
|
+
};
|
6
|
+
export const KPP_ZEROS_ONLY_ERROR_INFO = {
|
7
|
+
code: createErrorCode('kpp-invalid-zeros-only'),
|
8
|
+
message: 'Не может состоять только из нулей',
|
9
|
+
};
|
10
|
+
export const KPP_DOUBLE_ZERO_START_ERROR_INFO = {
|
11
|
+
code: createErrorCode('kpp-invalid-double-zero-start'),
|
12
|
+
message: 'Не может начинаться с 00',
|
5
13
|
};
|
6
14
|
export const KPP_REGEX = /^(\d{4}([A-Z]|\d){2}\d{3})$/;
|
package/kpp/kpp.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { createRule, isStringOfZeros } from '../core';
|
2
|
-
import { INVALID_KPP_ERROR_INFO, KPP_REGEX } from './constants';
|
1
|
+
import { createRule, isNoDoubleZeroStart, isStringOfZeros, } from '../core';
|
2
|
+
import { INVALID_KPP_ERROR_INFO, KPP_DOUBLE_ZERO_START_ERROR_INFO, KPP_REGEX, KPP_ZEROS_ONLY_ERROR_INFO, } from './constants';
|
3
3
|
/**
|
4
4
|
* @description Проверяет валидность кода КПП
|
5
5
|
* @example
|
@@ -9,8 +9,18 @@ import { INVALID_KPP_ERROR_INFO, KPP_REGEX } from './constants';
|
|
9
9
|
* ```
|
10
10
|
*/
|
11
11
|
export const kpp = (params) => createRule((value, ctx) => {
|
12
|
-
|
13
|
-
|
12
|
+
const createKppError = (errorInfoObj) => ctx.createError({
|
13
|
+
message: (params === null || params === void 0 ? void 0 : params.message) || errorInfoObj.message,
|
14
|
+
code: errorInfoObj.code,
|
15
|
+
});
|
16
|
+
if (!KPP_REGEX.test(value)) {
|
17
|
+
return createKppError(INVALID_KPP_ERROR_INFO);
|
18
|
+
}
|
19
|
+
if (isStringOfZeros(value)) {
|
20
|
+
return createKppError(KPP_ZEROS_ONLY_ERROR_INFO);
|
21
|
+
}
|
22
|
+
if (!isNoDoubleZeroStart(value)) {
|
23
|
+
return createKppError(KPP_DOUBLE_ZERO_START_ERROR_INFO);
|
14
24
|
}
|
15
25
|
return undefined;
|
16
26
|
}, { exclude: params === null || params === void 0 ? void 0 : params.exclude });
|