@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,29 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.isOGRNUL = exports.IS_OGRNUL_DEFAULT_MESSAGE = void 0;
|
4
|
+
const createRule_1 = require("../createRule");
|
5
|
+
const utils_1 = require("../utils");
|
6
|
+
exports.IS_OGRNUL_DEFAULT_MESSAGE = 'Некорректный ОГРН ЮЛ';
|
7
|
+
const OGRNUL_LENGTH = 13;
|
8
|
+
/**
|
9
|
+
* @description Проверяет валиден ли ОРГН ЮЛ
|
10
|
+
* @example isOGRNUL()('7728168971');
|
11
|
+
*/
|
12
|
+
exports.isOGRNUL = (0, createRule_1.createRule)(({ message = exports.IS_OGRNUL_DEFAULT_MESSAGE } = {}) => (value) => {
|
13
|
+
if ((0, utils_1.isEmptyString)(value)) {
|
14
|
+
return undefined;
|
15
|
+
}
|
16
|
+
if (typeof value === 'string') {
|
17
|
+
if (value.length !== OGRNUL_LENGTH) {
|
18
|
+
return message;
|
19
|
+
}
|
20
|
+
const checkSum = (parseInt(value.slice(0, -1)) % 11)
|
21
|
+
.toString()
|
22
|
+
.slice(-1);
|
23
|
+
if (value.slice(12, 13) !== checkSum) {
|
24
|
+
return message;
|
25
|
+
}
|
26
|
+
return undefined;
|
27
|
+
}
|
28
|
+
return message;
|
29
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isRequired';
|
@@ -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("./isRequired"), exports);
|
@@ -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,29 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.isRequired = exports.REQUIRED_RULE_DEFAULT_MESSAGE = void 0;
|
7
|
+
const lodash_isempty_1 = __importDefault(require("lodash.isempty"));
|
8
|
+
const createRule_1 = require("../createRule");
|
9
|
+
exports.REQUIRED_RULE_DEFAULT_MESSAGE = 'Не заполнено';
|
10
|
+
/**
|
11
|
+
* @description Проверяет присутсвует ли value
|
12
|
+
* @example isRequired();
|
13
|
+
* @example isRequired('ИНН обязателен');
|
14
|
+
*/
|
15
|
+
exports.isRequired = (0, createRule_1.createRule)(({ message = exports.REQUIRED_RULE_DEFAULT_MESSAGE } = {}) => (value) => {
|
16
|
+
if (typeof value === 'number' || value instanceof Date) {
|
17
|
+
return undefined;
|
18
|
+
}
|
19
|
+
if (typeof value === 'string') {
|
20
|
+
return value.trim() ? undefined : message;
|
21
|
+
}
|
22
|
+
if (typeof value === 'boolean') {
|
23
|
+
return value ? undefined : message;
|
24
|
+
}
|
25
|
+
if (!(0, lodash_isempty_1.default)(value)) {
|
26
|
+
return undefined;
|
27
|
+
}
|
28
|
+
return message;
|
29
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isSNILS';
|
package/isSNILS/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("./isSNILS"), exports);
|
@@ -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,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.isSNILS = exports.IS_SNILS_DEFAULT_MESSAGE = void 0;
|
4
|
+
const createRule_1 = require("../createRule");
|
5
|
+
const utils_1 = require("../utils");
|
6
|
+
exports.IS_SNILS_DEFAULT_MESSAGE = 'Некорректный СНИЛС';
|
7
|
+
const RESTRICTED_VALUES = ['00000000000'];
|
8
|
+
const DEFAULT_CHECKED_SUM = [0, 100, 101];
|
9
|
+
const removeSpecialCharacters = (value) => {
|
10
|
+
return value.replace(/\D/g, '');
|
11
|
+
};
|
12
|
+
const calcCheckSumForSNILS = (digitsOfValue) => digitsOfValue
|
13
|
+
.slice(0, 9)
|
14
|
+
.split('')
|
15
|
+
.map(Number)
|
16
|
+
.reduce((sum, currentValue, index) => sum + currentValue * (9 - index), 0);
|
17
|
+
const compareCheckSum = (calculatedCheckSum, checkSum) => {
|
18
|
+
return (calculatedCheckSum % DEFAULT_CHECKED_SUM[2] === checkSum ||
|
19
|
+
(calculatedCheckSum % DEFAULT_CHECKED_SUM[2] === DEFAULT_CHECKED_SUM[1] &&
|
20
|
+
checkSum === DEFAULT_CHECKED_SUM[0]));
|
21
|
+
};
|
22
|
+
/**
|
23
|
+
* @description Проверяет валиден ли СНИЛС
|
24
|
+
* @example isSNILS()('95145370513');
|
25
|
+
*/
|
26
|
+
exports.isSNILS = (0, createRule_1.createRule)(({ message = exports.IS_SNILS_DEFAULT_MESSAGE } = {}) => (value) => {
|
27
|
+
if ((0, utils_1.isEmptyString)(value)) {
|
28
|
+
return undefined;
|
29
|
+
}
|
30
|
+
if (typeof value !== 'string') {
|
31
|
+
return message;
|
32
|
+
}
|
33
|
+
const formattedValue = removeSpecialCharacters(value);
|
34
|
+
if (formattedValue.length !== value.length) {
|
35
|
+
return message;
|
36
|
+
}
|
37
|
+
if (!/^(\d{11})$/.test(formattedValue)) {
|
38
|
+
return message;
|
39
|
+
}
|
40
|
+
if (RESTRICTED_VALUES.includes(formattedValue)) {
|
41
|
+
return message;
|
42
|
+
}
|
43
|
+
const checkSum = Number(formattedValue.slice(9, 11));
|
44
|
+
const calculatedCheckSum = calcCheckSumForSNILS(formattedValue);
|
45
|
+
if (calculatedCheckSum < DEFAULT_CHECKED_SUM[1]) {
|
46
|
+
if (calculatedCheckSum === checkSum) {
|
47
|
+
return undefined;
|
48
|
+
}
|
49
|
+
return message;
|
50
|
+
}
|
51
|
+
if (calculatedCheckSum === DEFAULT_CHECKED_SUM[1] ||
|
52
|
+
calculatedCheckSum === DEFAULT_CHECKED_SUM[2]) {
|
53
|
+
if (checkSum === DEFAULT_CHECKED_SUM[0]) {
|
54
|
+
return undefined;
|
55
|
+
}
|
56
|
+
return message;
|
57
|
+
}
|
58
|
+
if (calculatedCheckSum > DEFAULT_CHECKED_SUM[2]) {
|
59
|
+
if (compareCheckSum(calculatedCheckSum, checkSum)) {
|
60
|
+
return undefined;
|
61
|
+
}
|
62
|
+
return message;
|
63
|
+
}
|
64
|
+
return undefined;
|
65
|
+
});
|
package/package.json
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "@astral/validations",
|
3
|
-
"browser": "./
|
3
|
+
"browser": "./esm/index.js",
|
4
4
|
"main": "./index.js",
|
5
|
-
"version": "0.1.0",
|
6
5
|
"dependencies": {
|
7
|
-
"lodash
|
6
|
+
"lodash.isempty": "^4.4.0"
|
8
7
|
},
|
8
|
+
"version": "1.0.0-test.1670422830",
|
9
9
|
"author": "Astral.Soft",
|
10
10
|
"license": "MIT",
|
11
11
|
"repository": {
|
@@ -18,5 +18,15 @@
|
|
18
18
|
"keywords": [],
|
19
19
|
"sideEffects": false,
|
20
20
|
"types": "./esm/index.d.ts",
|
21
|
-
"module": "./esm/index.js"
|
22
|
-
|
21
|
+
"module": "./esm/index.js",
|
22
|
+
"exports": {
|
23
|
+
".": {
|
24
|
+
"import": "./esm/index.js",
|
25
|
+
"require": "./index.js"
|
26
|
+
},
|
27
|
+
"./server": {
|
28
|
+
"import": "./esm/server/index.js",
|
29
|
+
"require": "./server/index.js"
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
package/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;
|
package/utils/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isEmptyString';
|
package/utils/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("./isEmptyString"), exports);
|
@@ -0,0 +1,10 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.isEmptyString = void 0;
|
4
|
+
/**
|
5
|
+
* @description Используется в правилах валидации для проверки того, что проверяемое значение еще не указано
|
6
|
+
*/
|
7
|
+
const isEmptyString = (value) => {
|
8
|
+
return value === '';
|
9
|
+
};
|
10
|
+
exports.isEmptyString = isEmptyString;
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './yupAdapter';
|
@@ -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("./yupAdapter"), exports);
|
@@ -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,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.yupAdapter = void 0;
|
4
|
+
/**
|
5
|
+
* @description Адаптирует правило созданное createRule к интерфейсу yup
|
6
|
+
* @example yupAdapter(isMinLength(22))('word')
|
7
|
+
*/
|
8
|
+
const yupAdapter = (rule) => (value) => {
|
9
|
+
const error = rule(value);
|
10
|
+
if (!error) {
|
11
|
+
return false;
|
12
|
+
}
|
13
|
+
return error;
|
14
|
+
};
|
15
|
+
exports.yupAdapter = yupAdapter;
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,9 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
var createRule_1 = require("./createRule");
|
4
|
-
describe('createRule', function () {
|
5
|
-
it('Не модифицирует переданный rule', function () {
|
6
|
-
var rule = (0, createRule_1.createRule)(function () { return function () { return 'Ошибка'; }; });
|
7
|
-
expect(rule()()).toBe('Ошибка');
|
8
|
-
});
|
9
|
-
});
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
package/esm/isString/index.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './isString';
|
package/esm/isString/index.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './isString';
|
@@ -1,6 +0,0 @@
|
|
1
|
-
export declare const STRING_RULE_MESSAGE = "\u0414\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u0441\u0442\u0440\u043E\u043A\u043E\u0439";
|
2
|
-
/**
|
3
|
-
* @example isString('Не строка')('string')
|
4
|
-
* @description Правило проверки на строку.
|
5
|
-
*/
|
6
|
-
export declare const isString: import("../types").Rule<[message?: string | undefined]>;
|
package/esm/isString/isString.js
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
import { createRule } from '../createRule';
|
2
|
-
export var STRING_RULE_MESSAGE = 'Должно быть строкой';
|
3
|
-
/**
|
4
|
-
* @example isString('Не строка')('string')
|
5
|
-
* @description Правило проверки на строку.
|
6
|
-
*/
|
7
|
-
export var isString = createRule(function (message) {
|
8
|
-
if (message === void 0) { message = STRING_RULE_MESSAGE; }
|
9
|
-
return function (value) {
|
10
|
-
return typeof value === 'string' ? undefined : message;
|
11
|
-
};
|
12
|
-
});
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import { STRING_RULE_MESSAGE, isString } from './isString';
|
2
|
-
describe('isString', function () {
|
3
|
-
it.each(['string', '', '22', 'null', '[Object object]'])('Valid for value: %s', function (value) {
|
4
|
-
expect(isString()(value)).toBe(undefined);
|
5
|
-
});
|
6
|
-
it.each([0, 22, null, {}, undefined, []])('Invalid for value: %s', function (value) {
|
7
|
-
expect(isString()(value)).toBe(STRING_RULE_MESSAGE);
|
8
|
-
});
|
9
|
-
it('Можно прокинуть кастомный текст ошибки', function () {
|
10
|
-
var errorMessage = 'test';
|
11
|
-
expect(isString(errorMessage)(22)).toBe(errorMessage);
|
12
|
-
});
|
13
|
-
});
|
package/isString/index.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './isString';
|
package/isString/isString.d.ts
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
export declare const STRING_RULE_MESSAGE = "\u0414\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u0441\u0442\u0440\u043E\u043A\u043E\u0439";
|
2
|
-
/**
|
3
|
-
* @example isString('Не строка')('string')
|
4
|
-
* @description Правило проверки на строку.
|
5
|
-
*/
|
6
|
-
export declare const isString: import("../types").Rule<[message?: string | undefined]>;
|
package/isString/isString.js
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.isString = exports.STRING_RULE_MESSAGE = void 0;
|
4
|
-
var createRule_1 = require("../createRule");
|
5
|
-
exports.STRING_RULE_MESSAGE = 'Должно быть строкой';
|
6
|
-
/**
|
7
|
-
* @example isString('Не строка')('string')
|
8
|
-
* @description Правило проверки на строку.
|
9
|
-
*/
|
10
|
-
exports.isString = (0, createRule_1.createRule)(function (message) {
|
11
|
-
if (message === void 0) { message = exports.STRING_RULE_MESSAGE; }
|
12
|
-
return function (value) {
|
13
|
-
return typeof value === 'string' ? undefined : message;
|
14
|
-
};
|
15
|
-
});
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,15 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
var isString_1 = require("./isString");
|
4
|
-
describe('isString', function () {
|
5
|
-
it.each(['string', '', '22', 'null', '[Object object]'])('Valid for value: %s', function (value) {
|
6
|
-
expect((0, isString_1.isString)()(value)).toBe(undefined);
|
7
|
-
});
|
8
|
-
it.each([0, 22, null, {}, undefined, []])('Invalid for value: %s', function (value) {
|
9
|
-
expect((0, isString_1.isString)()(value)).toBe(isString_1.STRING_RULE_MESSAGE);
|
10
|
-
});
|
11
|
-
it('Можно прокинуть кастомный текст ошибки', function () {
|
12
|
-
var errorMessage = 'test';
|
13
|
-
expect((0, isString_1.isString)(errorMessage)(22)).toBe(errorMessage);
|
14
|
-
});
|
15
|
-
});
|