@astral/validations 1.55.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 +2 -0
- package/esm/index.js +2 -0
- package/esm/isEmail/index.d.ts +1 -0
- package/esm/isEmail/index.js +1 -0
- package/esm/isEmail/isEmail.d.ts +13 -0
- package/esm/isEmail/isEmail.js +25 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/isEmail/index.d.ts +1 -0
- package/isEmail/index.js +17 -0
- package/isEmail/isEmail.d.ts +13 -0
- package/isEmail/isEmail.js +28 -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
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isEmail';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isEmail';
|
@@ -0,0 +1,13 @@
|
|
1
|
+
export declare const EMAIL_MAX_LENGTH = 256;
|
2
|
+
export declare const DEFAULT_ERROR_MESSAGE = "\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 E-mail";
|
3
|
+
export declare const INVALID_LENGTH_ERROR_MESSAGE = "E-mail \u0441\u043B\u0438\u0448\u043A\u043E\u043C \u0434\u043B\u0438\u043D\u043D\u044B\u0439";
|
4
|
+
/**
|
5
|
+
* @description Проверяет валиден ли email
|
6
|
+
* @example isEmail()('test@example.com');
|
7
|
+
*/
|
8
|
+
export declare const isEmail: (params?: ({
|
9
|
+
message?: string | undefined;
|
10
|
+
invalidLengthMessage?: string | undefined;
|
11
|
+
} & {
|
12
|
+
exclude?: ((value: unknown) => boolean) | undefined;
|
13
|
+
}) | undefined) => import("..").InitializedRule;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { createRule } from '../createRule';
|
2
|
+
import { isEmptyString } from '../utils';
|
3
|
+
const EMAIL_REGEXP = /^[-\w.]+@([A-z0-9][-A-z0-9]+\.)+[A-z]{2,}$/;
|
4
|
+
export const EMAIL_MAX_LENGTH = 256;
|
5
|
+
export const DEFAULT_ERROR_MESSAGE = 'Некорректный E-mail';
|
6
|
+
export const INVALID_LENGTH_ERROR_MESSAGE = 'E-mail слишком длинный';
|
7
|
+
/**
|
8
|
+
* @description Проверяет валиден ли email
|
9
|
+
* @example isEmail()('test@example.com');
|
10
|
+
*/
|
11
|
+
export const isEmail = createRule(({ message = DEFAULT_ERROR_MESSAGE, invalidLengthMessage = INVALID_LENGTH_ERROR_MESSAGE, } = {}) => (value) => {
|
12
|
+
if (typeof value !== 'string') {
|
13
|
+
return message;
|
14
|
+
}
|
15
|
+
if (isEmptyString(value)) {
|
16
|
+
return undefined;
|
17
|
+
}
|
18
|
+
if (!EMAIL_REGEXP.test(value)) {
|
19
|
+
return message;
|
20
|
+
}
|
21
|
+
if (value.length > EMAIL_MAX_LENGTH) {
|
22
|
+
return invalidLengthMessage;
|
23
|
+
}
|
24
|
+
return undefined;
|
25
|
+
});
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
@@ -33,3 +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);
|
37
|
+
__exportStar(require("./isEmail"), exports);
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './isEmail';
|
package/isEmail/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("./isEmail"), exports);
|
@@ -0,0 +1,13 @@
|
|
1
|
+
export declare const EMAIL_MAX_LENGTH = 256;
|
2
|
+
export declare const DEFAULT_ERROR_MESSAGE = "\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 E-mail";
|
3
|
+
export declare const INVALID_LENGTH_ERROR_MESSAGE = "E-mail \u0441\u043B\u0438\u0448\u043A\u043E\u043C \u0434\u043B\u0438\u043D\u043D\u044B\u0439";
|
4
|
+
/**
|
5
|
+
* @description Проверяет валиден ли email
|
6
|
+
* @example isEmail()('test@example.com');
|
7
|
+
*/
|
8
|
+
export declare const isEmail: (params?: ({
|
9
|
+
message?: string | undefined;
|
10
|
+
invalidLengthMessage?: string | undefined;
|
11
|
+
} & {
|
12
|
+
exclude?: ((value: unknown) => boolean) | undefined;
|
13
|
+
}) | undefined) => import("..").InitializedRule;
|
@@ -0,0 +1,28 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.isEmail = exports.INVALID_LENGTH_ERROR_MESSAGE = exports.DEFAULT_ERROR_MESSAGE = exports.EMAIL_MAX_LENGTH = void 0;
|
4
|
+
const createRule_1 = require("../createRule");
|
5
|
+
const utils_1 = require("../utils");
|
6
|
+
const EMAIL_REGEXP = /^[-\w.]+@([A-z0-9][-A-z0-9]+\.)+[A-z]{2,}$/;
|
7
|
+
exports.EMAIL_MAX_LENGTH = 256;
|
8
|
+
exports.DEFAULT_ERROR_MESSAGE = 'Некорректный E-mail';
|
9
|
+
exports.INVALID_LENGTH_ERROR_MESSAGE = 'E-mail слишком длинный';
|
10
|
+
/**
|
11
|
+
* @description Проверяет валиден ли email
|
12
|
+
* @example isEmail()('test@example.com');
|
13
|
+
*/
|
14
|
+
exports.isEmail = (0, createRule_1.createRule)(({ message = exports.DEFAULT_ERROR_MESSAGE, invalidLengthMessage = exports.INVALID_LENGTH_ERROR_MESSAGE, } = {}) => (value) => {
|
15
|
+
if (typeof value !== 'string') {
|
16
|
+
return message;
|
17
|
+
}
|
18
|
+
if ((0, utils_1.isEmptyString)(value)) {
|
19
|
+
return undefined;
|
20
|
+
}
|
21
|
+
if (!EMAIL_REGEXP.test(value)) {
|
22
|
+
return message;
|
23
|
+
}
|
24
|
+
if (value.length > exports.EMAIL_MAX_LENGTH) {
|
25
|
+
return invalidLengthMessage;
|
26
|
+
}
|
27
|
+
return undefined;
|
28
|
+
});
|
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.55.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
|
}
|