@astral/validations 1.55.0 → 1.56.0
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/esm/index.d.ts +1 -0
- package/esm/index.js +1 -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 +1 -0
- package/index.js +1 -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 -1
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
@@ -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
|
+
});
|