mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
formatting
This commit is contained in:
@@ -7,13 +7,17 @@ export const validate = <T extends object>(
|
||||
options?: ValidateOption
|
||||
): Promise<T> =>
|
||||
new Promise((resolve, reject) => {
|
||||
void validator.validate(source, options ? options : {}, (errors, fieldErrors) => {
|
||||
if (errors) {
|
||||
reject(fieldErrors);
|
||||
} else {
|
||||
resolve(source as T);
|
||||
void validator.validate(
|
||||
source,
|
||||
options ? options : {},
|
||||
(errors, fieldErrors) => {
|
||||
if (errors) {
|
||||
reject(fieldErrors);
|
||||
} else {
|
||||
resolve(source as T);
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
});
|
||||
|
||||
// updated to support both IPv4 and IPv6
|
||||
@@ -23,7 +27,11 @@ const IP_ADDRESS_REGEXP =
|
||||
const isValidIpAddress = (value: string) => IP_ADDRESS_REGEXP.test(value);
|
||||
|
||||
export const IP_ADDRESS_VALIDATOR = {
|
||||
validator(rule: InternalRuleItem, value: string, callback: (error?: string) => void) {
|
||||
validator(
|
||||
rule: InternalRuleItem,
|
||||
value: string,
|
||||
callback: (error?: string) => void
|
||||
) {
|
||||
if (value && !isValidIpAddress(value)) {
|
||||
callback('Must be an IP address');
|
||||
} else {
|
||||
@@ -36,10 +44,15 @@ const HOSTNAME_LENGTH_REGEXP = /^.{0,200}$/;
|
||||
const HOSTNAME_PATTERN_REGEXP =
|
||||
/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/;
|
||||
|
||||
const isValidHostname = (value: string) => HOSTNAME_LENGTH_REGEXP.test(value) && HOSTNAME_PATTERN_REGEXP.test(value);
|
||||
const isValidHostname = (value: string) =>
|
||||
HOSTNAME_LENGTH_REGEXP.test(value) && HOSTNAME_PATTERN_REGEXP.test(value);
|
||||
|
||||
export const HOSTNAME_VALIDATOR = {
|
||||
validator(rule: InternalRuleItem, value: string, callback: (error?: string) => void) {
|
||||
validator(
|
||||
rule: InternalRuleItem,
|
||||
value: string,
|
||||
callback: (error?: string) => void
|
||||
) {
|
||||
if (value && !isValidHostname(value)) {
|
||||
callback('Must be a valid hostname');
|
||||
} else {
|
||||
@@ -49,7 +62,11 @@ export const HOSTNAME_VALIDATOR = {
|
||||
};
|
||||
|
||||
export const IP_OR_HOSTNAME_VALIDATOR = {
|
||||
validator(rule: InternalRuleItem, value: string, callback: (error?: string) => void) {
|
||||
validator(
|
||||
rule: InternalRuleItem,
|
||||
value: string,
|
||||
callback: (error?: string) => void
|
||||
) {
|
||||
if (value && !(isValidIpAddress(value) || isValidHostname(value))) {
|
||||
callback('Must be a valid IP address or hostname');
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user