@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.
- package/compose/compose.d.ts +7 -0
- package/compose/compose.js +10 -0
- package/compose/index.d.ts +1 -0
- package/{isString → compose}/index.js +1 -1
- package/composeAllSettled/composeAllSettled.d.ts +7 -0
- package/composeAllSettled/composeAllSettled.js +25 -0
- package/composeAllSettled/index.d.ts +1 -0
- package/composeAllSettled/index.js +17 -0
- package/composeToString/composeToString.d.ts +8 -0
- package/composeToString/composeToString.js +18 -0
- package/composeToString/index.d.ts +1 -0
- package/composeToString/index.js +17 -0
- package/constants.d.ts +2 -0
- package/constants.js +5 -0
- package/createRule/createRule.d.ts +10 -2
- package/createRule/createRule.js +12 -5
- package/esm/compose/compose.d.ts +7 -0
- package/esm/compose/compose.js +6 -0
- package/esm/compose/index.d.ts +1 -0
- package/esm/compose/index.js +1 -0
- package/esm/composeAllSettled/composeAllSettled.d.ts +7 -0
- package/esm/composeAllSettled/composeAllSettled.js +21 -0
- package/esm/composeAllSettled/index.d.ts +1 -0
- package/esm/composeAllSettled/index.js +1 -0
- package/esm/composeToString/composeToString.d.ts +8 -0
- package/esm/composeToString/composeToString.js +14 -0
- package/esm/composeToString/index.d.ts +1 -0
- package/esm/composeToString/index.js +1 -0
- package/esm/constants.d.ts +2 -0
- package/esm/constants.js +2 -0
- package/esm/createRule/createRule.d.ts +10 -2
- package/esm/createRule/createRule.js +12 -5
- package/esm/index.d.ts +18 -0
- package/esm/index.js +18 -0
- package/esm/isDate/index.d.ts +1 -0
- package/esm/isDate/index.js +1 -0
- package/esm/isDate/isDate.d.ts +10 -0
- package/esm/isDate/isDate.js +23 -0
- package/esm/isINNIP/index.d.ts +1 -0
- package/esm/isINNIP/index.js +1 -0
- package/esm/isINNIP/isINNIP.d.ts +10 -0
- package/esm/isINNIP/isINNIP.js +39 -0
- package/esm/isINNUL/index.d.ts +1 -0
- package/esm/isINNUL/index.js +1 -0
- package/esm/isINNUL/isINNUL.d.ts +10 -0
- package/esm/isINNUL/isINNUL.js +34 -0
- package/esm/isMaxLength/index.d.ts +1 -0
- package/esm/isMaxLength/index.js +1 -0
- package/esm/isMaxLength/isMaxLength.d.ts +18 -0
- package/esm/isMaxLength/isMaxLength.js +34 -0
- package/esm/isMaxValue/index.d.ts +1 -0
- package/esm/isMaxValue/index.js +1 -0
- package/esm/isMaxValue/isMaxValue.d.ts +17 -0
- package/esm/isMaxValue/isMaxValue.js +35 -0
- package/esm/isMaybeNumber/index.d.ts +1 -0
- package/esm/isMaybeNumber/index.js +1 -0
- package/esm/isMaybeNumber/isMaybeNumber.d.ts +10 -0
- package/esm/isMaybeNumber/isMaybeNumber.js +23 -0
- package/esm/isMinLength/index.d.ts +1 -0
- package/esm/isMinLength/index.js +1 -0
- package/esm/isMinLength/isMinLength.d.ts +18 -0
- package/esm/isMinLength/isMinLength.js +34 -0
- package/esm/isMinValue/index.d.ts +1 -0
- package/esm/isMinValue/index.js +1 -0
- package/esm/isMinValue/isMinValue.d.ts +17 -0
- package/esm/isMinValue/isMinValue.js +35 -0
- package/esm/isMobilePhone/index.d.ts +1 -0
- package/esm/isMobilePhone/index.js +1 -0
- package/esm/isMobilePhone/isMobilePhone.d.ts +10 -0
- package/esm/isMobilePhone/isMobilePhone.js +20 -0
- package/esm/isOGRNIP/index.d.ts +1 -0
- package/esm/isOGRNIP/index.js +1 -0
- package/esm/isOGRNIP/isOGRNIP.d.ts +10 -0
- package/esm/isOGRNIP/isOGRNIP.js +26 -0
- package/esm/isOGRNUL/index.d.ts +1 -0
- package/esm/isOGRNUL/index.js +1 -0
- package/esm/isOGRNUL/isOGRNUL.d.ts +10 -0
- package/esm/isOGRNUL/isOGRNUL.js +26 -0
- package/esm/isRequired/index.d.ts +1 -0
- package/esm/isRequired/index.js +1 -0
- package/esm/isRequired/isRequired.d.ts +11 -0
- package/esm/isRequired/isRequired.js +23 -0
- package/esm/isSNILS/index.d.ts +1 -0
- package/esm/isSNILS/index.js +1 -0
- package/esm/isSNILS/isSNILS.d.ts +10 -0
- package/esm/isSNILS/isSNILS.js +62 -0
- package/esm/types.d.ts +4 -1
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.js +1 -0
- package/esm/utils/isEmptyString.d.ts +4 -0
- package/esm/utils/isEmptyString.js +6 -0
- package/esm/yupAdapter/index.d.ts +1 -0
- package/esm/yupAdapter/index.js +1 -0
- package/esm/yupAdapter/yupAdapter.d.ts +8 -0
- package/esm/yupAdapter/yupAdapter.js +11 -0
- package/index.d.ts +18 -0
- package/index.js +18 -0
- package/isDate/index.d.ts +1 -0
- package/isDate/index.js +17 -0
- package/isDate/isDate.d.ts +10 -0
- package/isDate/isDate.js +26 -0
- package/isINNIP/index.d.ts +1 -0
- package/isINNIP/index.js +17 -0
- package/isINNIP/isINNIP.d.ts +10 -0
- package/isINNIP/isINNIP.js +42 -0
- package/isINNUL/index.d.ts +1 -0
- package/isINNUL/index.js +17 -0
- package/isINNUL/isINNUL.d.ts +10 -0
- package/isINNUL/isINNUL.js +37 -0
- package/isMaxLength/index.d.ts +1 -0
- package/isMaxLength/index.js +5 -0
- package/isMaxLength/isMaxLength.d.ts +18 -0
- package/isMaxLength/isMaxLength.js +41 -0
- package/isMaxValue/index.d.ts +1 -0
- package/isMaxValue/index.js +5 -0
- package/isMaxValue/isMaxValue.d.ts +17 -0
- package/isMaxValue/isMaxValue.js +39 -0
- package/isMaybeNumber/index.d.ts +1 -0
- package/isMaybeNumber/index.js +17 -0
- package/isMaybeNumber/isMaybeNumber.d.ts +10 -0
- package/isMaybeNumber/isMaybeNumber.js +26 -0
- package/isMinLength/index.d.ts +1 -0
- package/isMinLength/index.js +17 -0
- package/isMinLength/isMinLength.d.ts +18 -0
- package/isMinLength/isMinLength.js +41 -0
- package/isMinValue/index.d.ts +1 -0
- package/isMinValue/index.js +5 -0
- package/isMinValue/isMinValue.d.ts +17 -0
- package/isMinValue/isMinValue.js +39 -0
- package/isMobilePhone/index.d.ts +1 -0
- package/isMobilePhone/index.js +17 -0
- package/isMobilePhone/isMobilePhone.d.ts +10 -0
- package/isMobilePhone/isMobilePhone.js +23 -0
- package/isOGRNIP/index.d.ts +1 -0
- package/isOGRNIP/index.js +17 -0
- package/isOGRNIP/isOGRNIP.d.ts +10 -0
- package/isOGRNIP/isOGRNIP.js +29 -0
- package/isOGRNUL/index.d.ts +1 -0
- package/isOGRNUL/index.js +17 -0
- package/isOGRNUL/isOGRNUL.d.ts +10 -0
- package/isOGRNUL/isOGRNUL.js +29 -0
- package/isRequired/index.d.ts +1 -0
- package/isRequired/index.js +17 -0
- package/isRequired/isRequired.d.ts +11 -0
- package/isRequired/isRequired.js +29 -0
- package/isSNILS/index.d.ts +1 -0
- package/isSNILS/index.js +17 -0
- package/isSNILS/isSNILS.d.ts +10 -0
- package/isSNILS/isSNILS.js +65 -0
- package/package.json +15 -5
- package/types.d.ts +4 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +17 -0
- package/utils/isEmptyString.d.ts +4 -0
- package/utils/isEmptyString.js +10 -0
- package/yupAdapter/index.d.ts +1 -0
- package/yupAdapter/index.js +17 -0
- package/yupAdapter/yupAdapter.d.ts +8 -0
- package/yupAdapter/yupAdapter.js +15 -0
- package/createRule/createRule.test.d.ts +0 -1
- package/createRule/createRule.test.js +0 -9
- package/esm/createRule/createRule.test.d.ts +0 -1
- package/esm/createRule/createRule.test.js +0 -7
- package/esm/isString/index.d.ts +0 -1
- package/esm/isString/index.js +0 -1
- package/esm/isString/isString.d.ts +0 -6
- package/esm/isString/isString.js +0 -12
- package/esm/isString/isString.test.d.ts +0 -1
- package/esm/isString/isString.test.js +0 -13
- package/isString/index.d.ts +0 -1
- package/isString/isString.d.ts +0 -6
- package/isString/isString.js +0 -15
- package/isString/isString.test.d.ts +0 -1
- package/isString/isString.test.js +0 -15
@@ -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';
|
@@ -0,0 +1,17 @@
|
|
1
|
+
export declare const getDefaultMessage: (min: number) => string;
|
2
|
+
/**
|
3
|
+
* @description Проверяет минимальное значение value
|
4
|
+
* @example isMinValue({ min: 10 })(1239123);
|
5
|
+
* @param {number} [min] Минимальное значение value
|
6
|
+
* @param {string} [message.defaultMessage] Сообщение при неудачной валидации
|
7
|
+
* @param {string} [message.incorrectValue] Сообщение при переданном некорректном value
|
8
|
+
*/
|
9
|
+
export declare const isMinValue: (params: {
|
10
|
+
min: number;
|
11
|
+
message?: {
|
12
|
+
defaultMessage?: string | undefined;
|
13
|
+
incorrectValue?: string | undefined;
|
14
|
+
} | undefined;
|
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 = (min) => {
|
6
|
+
return `Должно быть больше чем ${min}`;
|
7
|
+
};
|
8
|
+
/**
|
9
|
+
* @description Проверяет минимальное значение value
|
10
|
+
* @example isMinValue({ min: 10 })(1239123);
|
11
|
+
* @param {number} [min] Минимальное значение value
|
12
|
+
* @param {string} [message.defaultMessage] Сообщение при неудачной валидации
|
13
|
+
* @param {string} [message.incorrectValue] Сообщение при переданном некорректном value
|
14
|
+
*/
|
15
|
+
export const isMinValue = createRule(({ min, message = {
|
16
|
+
defaultMessage: `Должно быть больше чем ${min}`,
|
17
|
+
incorrectValue: INCORRECT_MESSAGE,
|
18
|
+
}, } = { min: 0 }) => (value) => {
|
19
|
+
if (isEmptyString(value)) {
|
20
|
+
return undefined;
|
21
|
+
}
|
22
|
+
if (typeof value === 'string' && !isMaybeNumber()(value)) {
|
23
|
+
if (parseFloat(value) >= min) {
|
24
|
+
return undefined;
|
25
|
+
}
|
26
|
+
return message.defaultMessage;
|
27
|
+
}
|
28
|
+
if (typeof value !== 'number' || isNaN(value)) {
|
29
|
+
return message.incorrectValue;
|
30
|
+
}
|
31
|
+
if (value >= min) {
|
32
|
+
return undefined;
|
33
|
+
}
|
34
|
+
return message.defaultMessage;
|
35
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isMobilePhone';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isMobilePhone';
|
@@ -0,0 +1,10 @@
|
|
1
|
+
export declare const IS_MOBILE_PHONE_DEFAULT_MESSAGE = "\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 \u043D\u043E\u043C\u0435\u0440 \u0442\u0435\u043B\u0435\u0444\u043E\u043D\u0430";
|
2
|
+
/**
|
3
|
+
* @description Проверяет валиден ли мобильный телефон
|
4
|
+
* @example isMobilePhone()('79999999999');
|
5
|
+
*/
|
6
|
+
export declare const isMobilePhone: (params?: ({
|
7
|
+
message?: string | undefined;
|
8
|
+
} & {
|
9
|
+
exclude?: ((value: unknown) => boolean) | undefined;
|
10
|
+
}) | undefined) => import("..").InitializedRule;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { createRule } from '../createRule';
|
2
|
+
import { isEmptyString } from '../utils';
|
3
|
+
export const IS_MOBILE_PHONE_DEFAULT_MESSAGE = 'Некорректный номер телефона';
|
4
|
+
const MOBILE_PHONE_REGEX = /^(79)\d{9}$/;
|
5
|
+
/**
|
6
|
+
* @description Проверяет валиден ли мобильный телефон
|
7
|
+
* @example isMobilePhone()('79999999999');
|
8
|
+
*/
|
9
|
+
export const isMobilePhone = createRule(({ message = IS_MOBILE_PHONE_DEFAULT_MESSAGE } = {}) => (value) => {
|
10
|
+
if (isEmptyString(value)) {
|
11
|
+
return undefined;
|
12
|
+
}
|
13
|
+
if (typeof value === 'string') {
|
14
|
+
if (!MOBILE_PHONE_REGEX.test(value)) {
|
15
|
+
return message;
|
16
|
+
}
|
17
|
+
return undefined;
|
18
|
+
}
|
19
|
+
return message;
|
20
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isOGRNIP';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isOGRNIP';
|
@@ -0,0 +1,10 @@
|
|
1
|
+
export declare const IS_OGRNIP_DEFAULT_MESSAGE = "\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 \u041E\u0413\u0420\u041D \u0418\u041F";
|
2
|
+
/**
|
3
|
+
* @description Проверяет валиден ли ОРГН ИП
|
4
|
+
* @example isOGRNIP()('7728168971');
|
5
|
+
*/
|
6
|
+
export declare const isOGRNIP: (params?: ({
|
7
|
+
message?: string | undefined;
|
8
|
+
} & {
|
9
|
+
exclude?: ((value: unknown) => boolean) | undefined;
|
10
|
+
}) | undefined) => import("..").InitializedRule;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { createRule } from '../createRule';
|
2
|
+
import { isEmptyString } from '../utils';
|
3
|
+
export const IS_OGRNIP_DEFAULT_MESSAGE = 'Некорректный ОГРН ИП';
|
4
|
+
const OGRNIP_LENGTH = 15;
|
5
|
+
/**
|
6
|
+
* @description Проверяет валиден ли ОРГН ИП
|
7
|
+
* @example isOGRNIP()('7728168971');
|
8
|
+
*/
|
9
|
+
export const isOGRNIP = createRule(({ message = IS_OGRNIP_DEFAULT_MESSAGE } = {}) => (value) => {
|
10
|
+
if (isEmptyString(value)) {
|
11
|
+
return undefined;
|
12
|
+
}
|
13
|
+
if (typeof value === 'string') {
|
14
|
+
if (value.length !== OGRNIP_LENGTH) {
|
15
|
+
return message;
|
16
|
+
}
|
17
|
+
const checkSum = (parseInt(value.slice(0, -1)) % 13)
|
18
|
+
.toString()
|
19
|
+
.slice(-1);
|
20
|
+
if (value.slice(14, 15) !== checkSum) {
|
21
|
+
return message;
|
22
|
+
}
|
23
|
+
return undefined;
|
24
|
+
}
|
25
|
+
return message;
|
26
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isOGRNUL';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isOGRNUL';
|
@@ -0,0 +1,10 @@
|
|
1
|
+
export declare const IS_OGRNUL_DEFAULT_MESSAGE = "\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 \u041E\u0413\u0420\u041D \u042E\u041B";
|
2
|
+
/**
|
3
|
+
* @description Проверяет валиден ли ОРГН ЮЛ
|
4
|
+
* @example isOGRNUL()('7728168971');
|
5
|
+
*/
|
6
|
+
export declare const isOGRNUL: (params?: ({
|
7
|
+
message?: string | undefined;
|
8
|
+
} & {
|
9
|
+
exclude?: ((value: unknown) => boolean) | undefined;
|
10
|
+
}) | undefined) => import("..").InitializedRule;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { createRule } from '../createRule';
|
2
|
+
import { isEmptyString } from '../utils';
|
3
|
+
export const IS_OGRNUL_DEFAULT_MESSAGE = 'Некорректный ОГРН ЮЛ';
|
4
|
+
const OGRNUL_LENGTH = 13;
|
5
|
+
/**
|
6
|
+
* @description Проверяет валиден ли ОРГН ЮЛ
|
7
|
+
* @example isOGRNUL()('7728168971');
|
8
|
+
*/
|
9
|
+
export const isOGRNUL = createRule(({ message = IS_OGRNUL_DEFAULT_MESSAGE } = {}) => (value) => {
|
10
|
+
if (isEmptyString(value)) {
|
11
|
+
return undefined;
|
12
|
+
}
|
13
|
+
if (typeof value === 'string') {
|
14
|
+
if (value.length !== OGRNUL_LENGTH) {
|
15
|
+
return message;
|
16
|
+
}
|
17
|
+
const checkSum = (parseInt(value.slice(0, -1)) % 11)
|
18
|
+
.toString()
|
19
|
+
.slice(-1);
|
20
|
+
if (value.slice(12, 13) !== checkSum) {
|
21
|
+
return message;
|
22
|
+
}
|
23
|
+
return undefined;
|
24
|
+
}
|
25
|
+
return message;
|
26
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isRequired';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isRequired';
|
@@ -0,0 +1,11 @@
|
|
1
|
+
export declare const REQUIRED_RULE_DEFAULT_MESSAGE = "\u041D\u0435 \u0437\u0430\u043F\u043E\u043B\u043D\u0435\u043D\u043E";
|
2
|
+
/**
|
3
|
+
* @description Проверяет присутсвует ли value
|
4
|
+
* @example isRequired();
|
5
|
+
* @example isRequired('ИНН обязателен');
|
6
|
+
*/
|
7
|
+
export declare const isRequired: (params?: ({
|
8
|
+
message?: string | undefined;
|
9
|
+
} & {
|
10
|
+
exclude?: ((value: unknown) => boolean) | undefined;
|
11
|
+
}) | undefined) => import("..").InitializedRule;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import isEmpty from 'lodash.isempty';
|
2
|
+
import { createRule } from '../createRule';
|
3
|
+
export const REQUIRED_RULE_DEFAULT_MESSAGE = 'Не заполнено';
|
4
|
+
/**
|
5
|
+
* @description Проверяет присутсвует ли value
|
6
|
+
* @example isRequired();
|
7
|
+
* @example isRequired('ИНН обязателен');
|
8
|
+
*/
|
9
|
+
export const isRequired = createRule(({ message = REQUIRED_RULE_DEFAULT_MESSAGE } = {}) => (value) => {
|
10
|
+
if (typeof value === 'number' || value instanceof Date) {
|
11
|
+
return undefined;
|
12
|
+
}
|
13
|
+
if (typeof value === 'string') {
|
14
|
+
return value.trim() ? undefined : message;
|
15
|
+
}
|
16
|
+
if (typeof value === 'boolean') {
|
17
|
+
return value ? undefined : message;
|
18
|
+
}
|
19
|
+
if (!isEmpty(value)) {
|
20
|
+
return undefined;
|
21
|
+
}
|
22
|
+
return message;
|
23
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isSNILS';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isSNILS';
|
@@ -0,0 +1,10 @@
|
|
1
|
+
export declare const IS_SNILS_DEFAULT_MESSAGE = "\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 \u0421\u041D\u0418\u041B\u0421";
|
2
|
+
/**
|
3
|
+
* @description Проверяет валиден ли СНИЛС
|
4
|
+
* @example isSNILS()('95145370513');
|
5
|
+
*/
|
6
|
+
export declare const isSNILS: (params?: ({
|
7
|
+
message?: string | undefined;
|
8
|
+
} & {
|
9
|
+
exclude?: ((value: unknown) => boolean) | undefined;
|
10
|
+
}) | undefined) => import("..").InitializedRule;
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import { createRule } from '../createRule';
|
2
|
+
import { isEmptyString } from '../utils';
|
3
|
+
export const IS_SNILS_DEFAULT_MESSAGE = 'Некорректный СНИЛС';
|
4
|
+
const RESTRICTED_VALUES = ['00000000000'];
|
5
|
+
const DEFAULT_CHECKED_SUM = [0, 100, 101];
|
6
|
+
const removeSpecialCharacters = (value) => {
|
7
|
+
return value.replace(/\D/g, '');
|
8
|
+
};
|
9
|
+
const calcCheckSumForSNILS = (digitsOfValue) => digitsOfValue
|
10
|
+
.slice(0, 9)
|
11
|
+
.split('')
|
12
|
+
.map(Number)
|
13
|
+
.reduce((sum, currentValue, index) => sum + currentValue * (9 - index), 0);
|
14
|
+
const compareCheckSum = (calculatedCheckSum, checkSum) => {
|
15
|
+
return (calculatedCheckSum % DEFAULT_CHECKED_SUM[2] === checkSum ||
|
16
|
+
(calculatedCheckSum % DEFAULT_CHECKED_SUM[2] === DEFAULT_CHECKED_SUM[1] &&
|
17
|
+
checkSum === DEFAULT_CHECKED_SUM[0]));
|
18
|
+
};
|
19
|
+
/**
|
20
|
+
* @description Проверяет валиден ли СНИЛС
|
21
|
+
* @example isSNILS()('95145370513');
|
22
|
+
*/
|
23
|
+
export const isSNILS = createRule(({ message = IS_SNILS_DEFAULT_MESSAGE } = {}) => (value) => {
|
24
|
+
if (isEmptyString(value)) {
|
25
|
+
return undefined;
|
26
|
+
}
|
27
|
+
if (typeof value !== 'string') {
|
28
|
+
return message;
|
29
|
+
}
|
30
|
+
const formattedValue = removeSpecialCharacters(value);
|
31
|
+
if (formattedValue.length !== value.length) {
|
32
|
+
return message;
|
33
|
+
}
|
34
|
+
if (!/^(\d{11})$/.test(formattedValue)) {
|
35
|
+
return message;
|
36
|
+
}
|
37
|
+
if (RESTRICTED_VALUES.includes(formattedValue)) {
|
38
|
+
return message;
|
39
|
+
}
|
40
|
+
const checkSum = Number(formattedValue.slice(9, 11));
|
41
|
+
const calculatedCheckSum = calcCheckSumForSNILS(formattedValue);
|
42
|
+
if (calculatedCheckSum < DEFAULT_CHECKED_SUM[1]) {
|
43
|
+
if (calculatedCheckSum === checkSum) {
|
44
|
+
return undefined;
|
45
|
+
}
|
46
|
+
return message;
|
47
|
+
}
|
48
|
+
if (calculatedCheckSum === DEFAULT_CHECKED_SUM[1] ||
|
49
|
+
calculatedCheckSum === DEFAULT_CHECKED_SUM[2]) {
|
50
|
+
if (checkSum === DEFAULT_CHECKED_SUM[0]) {
|
51
|
+
return undefined;
|
52
|
+
}
|
53
|
+
return message;
|
54
|
+
}
|
55
|
+
if (calculatedCheckSum > DEFAULT_CHECKED_SUM[2]) {
|
56
|
+
if (compareCheckSum(calculatedCheckSum, checkSum)) {
|
57
|
+
return undefined;
|
58
|
+
}
|
59
|
+
return message;
|
60
|
+
}
|
61
|
+
return undefined;
|
62
|
+
});
|
package/esm/types.d.ts
CHANGED
@@ -1 +1,4 @@
|
|
1
|
-
export
|
1
|
+
export type RuleError = string | string[];
|
2
|
+
export type ValidationResult = RuleError | undefined;
|
3
|
+
export type InitializedRule = (value?: unknown) => ValidationResult;
|
4
|
+
export type Rule<Params extends object, RequiredParams extends boolean> = RequiredParams extends true ? (params: Params) => InitializedRule : (params?: Params) => InitializedRule;
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isEmptyString';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isEmptyString';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './yupAdapter';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './yupAdapter';
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { InitializedRule } from '../types';
|
2
|
+
type YupValidationResult = boolean | string | string[];
|
3
|
+
/**
|
4
|
+
* @description Адаптирует правило созданное createRule к интерфейсу yup
|
5
|
+
* @example yupAdapter(isMinLength(22))('word')
|
6
|
+
*/
|
7
|
+
export declare const yupAdapter: (rule: InitializedRule) => (value: unknown) => YupValidationResult;
|
8
|
+
export {};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
/**
|
2
|
+
* @description Адаптирует правило созданное createRule к интерфейсу yup
|
3
|
+
* @example yupAdapter(isMinLength(22))('word')
|
4
|
+
*/
|
5
|
+
export const yupAdapter = (rule) => (value) => {
|
6
|
+
const error = rule(value);
|
7
|
+
if (!error) {
|
8
|
+
return false;
|
9
|
+
}
|
10
|
+
return error;
|
11
|
+
};
|
package/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/index.js
CHANGED
@@ -15,3 +15,21 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./createRule"), exports);
|
18
|
+
__exportStar(require("./yupAdapter"), exports);
|
19
|
+
__exportStar(require("./compose"), exports);
|
20
|
+
__exportStar(require("./composeAllSettled"), exports);
|
21
|
+
__exportStar(require("./composeToString"), exports);
|
22
|
+
__exportStar(require("./isRequired"), exports);
|
23
|
+
__exportStar(require("./types"), exports);
|
24
|
+
__exportStar(require("./isINNUL"), exports);
|
25
|
+
__exportStar(require("./isINNIP"), exports);
|
26
|
+
__exportStar(require("./isMobilePhone"), exports);
|
27
|
+
__exportStar(require("./isOGRNIP"), exports);
|
28
|
+
__exportStar(require("./isOGRNUL"), exports);
|
29
|
+
__exportStar(require("./isMinLength"), exports);
|
30
|
+
__exportStar(require("./isMaxLength"), exports);
|
31
|
+
__exportStar(require("./isMaxValue"), exports);
|
32
|
+
__exportStar(require("./isMinValue"), exports);
|
33
|
+
__exportStar(require("./isMaybeNumber"), exports);
|
34
|
+
__exportStar(require("./isDate"), exports);
|
35
|
+
__exportStar(require("./isSNILS"), exports);
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isDate';
|
package/isDate/index.js
ADDED
@@ -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("./isDate"), exports);
|
@@ -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;
|
package/isDate/isDate.js
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.isDate = exports.IS_DATE_RULE_DEFAULT_MESSAGE = void 0;
|
4
|
+
const createRule_1 = require("../createRule");
|
5
|
+
const utils_1 = require("../utils");
|
6
|
+
exports.IS_DATE_RULE_DEFAULT_MESSAGE = 'Неверный формат даты';
|
7
|
+
/**
|
8
|
+
* @description Проверяет валидна ли дата
|
9
|
+
* @example isDate()('2011-11-12');
|
10
|
+
*/
|
11
|
+
exports.isDate = (0, createRule_1.createRule)(({ message = exports.IS_DATE_RULE_DEFAULT_MESSAGE } = {}) => (value) => {
|
12
|
+
if ((0, utils_1.isEmptyString)(value)) {
|
13
|
+
return undefined;
|
14
|
+
}
|
15
|
+
if (typeof value === 'string') {
|
16
|
+
const date = new Date(value);
|
17
|
+
if (!isNaN(date.getTime())) {
|
18
|
+
return undefined;
|
19
|
+
}
|
20
|
+
return message;
|
21
|
+
}
|
22
|
+
if (value instanceof Date && !isNaN(value.getTime())) {
|
23
|
+
return undefined;
|
24
|
+
}
|
25
|
+
return message;
|
26
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isINNIP';
|
package/isINNIP/index.js
ADDED
@@ -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("./isINNIP"), exports);
|