@astral/validations 1.56.0 → 2.1.3
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/composeSome/composeSome.d.ts +8 -0
- package/composeSome/composeSome.js +29 -0
- package/composeSome/index.d.ts +1 -0
- package/composeSome/index.js +17 -0
- package/esm/composeSome/composeSome.d.ts +8 -0
- package/esm/composeSome/composeSome.js +25 -0
- package/esm/composeSome/index.d.ts +1 -0
- package/esm/composeSome/index.js +1 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -5
@@ -0,0 +1,8 @@
|
|
1
|
+
import { InitializedRule, ValidationResult } from '../types';
|
2
|
+
/**
|
3
|
+
* @description Объединяет переданные правила в цепочку правил, выполняя все переданные правила, независимо от результата выполнения правил.
|
4
|
+
* Выполняет правила слева направо. Возвращает текст первой ошибки, если все правила выполнены с ошибкой
|
5
|
+
* @example composeSome(isIncludeDot(), isIncludeComma());
|
6
|
+
* @example compose(isRequired(), composeSome(isIncludeDot(), isIncludeComma()));
|
7
|
+
*/
|
8
|
+
export declare const composeSome: (...rules: InitializedRule[]) => (value: unknown) => ValidationResult;
|
@@ -0,0 +1,29 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.composeSome = void 0;
|
4
|
+
/**
|
5
|
+
* @description Объединяет переданные правила в цепочку правил, выполняя все переданные правила, независимо от результата выполнения правил.
|
6
|
+
* Выполняет правила слева направо. Возвращает текст первой ошибки, если все правила выполнены с ошибкой
|
7
|
+
* @example composeSome(isIncludeDot(), isIncludeComma());
|
8
|
+
* @example compose(isRequired(), composeSome(isIncludeDot(), isIncludeComma()));
|
9
|
+
*/
|
10
|
+
const composeSome = (...rules) => (value) => {
|
11
|
+
const errors = rules.reduce((errorsAcc, rule) => {
|
12
|
+
const error = rule(value);
|
13
|
+
if (Array.isArray(error) && error.length > 0) {
|
14
|
+
errorsAcc.push(...error);
|
15
|
+
}
|
16
|
+
if (typeof error === 'string') {
|
17
|
+
errorsAcc.push(error);
|
18
|
+
}
|
19
|
+
return errorsAcc;
|
20
|
+
}, []);
|
21
|
+
if (!errors.length) {
|
22
|
+
return undefined;
|
23
|
+
}
|
24
|
+
if (errors.length < rules.length) {
|
25
|
+
return undefined;
|
26
|
+
}
|
27
|
+
return errors[0];
|
28
|
+
};
|
29
|
+
exports.composeSome = composeSome;
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './composeSome';
|
@@ -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("./composeSome"), exports);
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { InitializedRule, ValidationResult } from '../types';
|
2
|
+
/**
|
3
|
+
* @description Объединяет переданные правила в цепочку правил, выполняя все переданные правила, независимо от результата выполнения правил.
|
4
|
+
* Выполняет правила слева направо. Возвращает текст первой ошибки, если все правила выполнены с ошибкой
|
5
|
+
* @example composeSome(isIncludeDot(), isIncludeComma());
|
6
|
+
* @example compose(isRequired(), composeSome(isIncludeDot(), isIncludeComma()));
|
7
|
+
*/
|
8
|
+
export declare const composeSome: (...rules: InitializedRule[]) => (value: unknown) => ValidationResult;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
/**
|
2
|
+
* @description Объединяет переданные правила в цепочку правил, выполняя все переданные правила, независимо от результата выполнения правил.
|
3
|
+
* Выполняет правила слева направо. Возвращает текст первой ошибки, если все правила выполнены с ошибкой
|
4
|
+
* @example composeSome(isIncludeDot(), isIncludeComma());
|
5
|
+
* @example compose(isRequired(), composeSome(isIncludeDot(), isIncludeComma()));
|
6
|
+
*/
|
7
|
+
export const composeSome = (...rules) => (value) => {
|
8
|
+
const errors = rules.reduce((errorsAcc, rule) => {
|
9
|
+
const error = rule(value);
|
10
|
+
if (Array.isArray(error) && error.length > 0) {
|
11
|
+
errorsAcc.push(...error);
|
12
|
+
}
|
13
|
+
if (typeof error === 'string') {
|
14
|
+
errorsAcc.push(error);
|
15
|
+
}
|
16
|
+
return errorsAcc;
|
17
|
+
}, []);
|
18
|
+
if (!errors.length) {
|
19
|
+
return undefined;
|
20
|
+
}
|
21
|
+
if (errors.length < rules.length) {
|
22
|
+
return undefined;
|
23
|
+
}
|
24
|
+
return errors[0];
|
25
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './composeSome';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './composeSome';
|
package/esm/index.d.ts
CHANGED
package/esm/index.js
CHANGED
package/index.d.ts
CHANGED
package/index.js
CHANGED
@@ -33,4 +33,5 @@ __exportStar(require("./isMinValue"), exports);
|
|
33
33
|
__exportStar(require("./isMaybeNumber"), exports);
|
34
34
|
__exportStar(require("./isDate"), exports);
|
35
35
|
__exportStar(require("./isSNILS"), exports);
|
36
|
+
__exportStar(require("./composeSome"), exports);
|
36
37
|
__exportStar(require("./isEmail"), exports);
|
package/package.json
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "@astral/validations",
|
3
|
+
"version": "2.1.3",
|
3
4
|
"browser": "./esm/index.js",
|
4
5
|
"main": "./index.js",
|
5
6
|
"dependencies": {
|
6
7
|
"lodash.isempty": "^4.4.0"
|
7
8
|
},
|
8
|
-
"version": "1.56.0",
|
9
9
|
"author": "Astral.Soft",
|
10
10
|
"license": "MIT",
|
11
11
|
"repository": {
|
@@ -23,10 +23,6 @@
|
|
23
23
|
".": {
|
24
24
|
"import": "./esm/index.js",
|
25
25
|
"require": "./index.js"
|
26
|
-
},
|
27
|
-
"./server": {
|
28
|
-
"import": "./esm/server/index.js",
|
29
|
-
"require": "./server/index.js"
|
30
26
|
}
|
31
27
|
}
|
32
28
|
}
|