@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,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("./
|
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
package/constants.js
ADDED
@@ -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
|
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>;
|
package/createRule/createRule.js
CHANGED
@@ -1,9 +1,16 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.createRule = void 0;
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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';
|
package/esm/constants.js
ADDED
@@ -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
|
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
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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;
|