This commit is contained in:
proddy
2021-05-14 12:45:57 +02:00
parent 15df0c0552
commit fec5ff3132
108 changed files with 3508 additions and 2455 deletions

View File

@@ -1,5 +1,5 @@
export { default as isHostname } from './isHostname'
export { default as isIP } from './isIP'
export { default as optional } from './optional'
export { default as or } from './or'
export { default as isPath } from './isPath'
export { default as isHostname } from './isHostname';
export { default as isIP } from './isIP';
export { default as optional } from './optional';
export { default as or } from './or';
export { default as isPath } from './isPath';

View File

@@ -1,8 +1,8 @@
const hostnameLengthRegex = /^.{0,48}$/
const hostnamePatternRegex = /^(([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 hostnameLengthRegex = /^.{0,48}$/;
const hostnamePatternRegex = /^(([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])$/;
export default function isHostname(hostname: string) {
return (
hostnameLengthRegex.test(hostname) && hostnamePatternRegex.test(hostname)
)
);
}

View File

@@ -1,5 +1,5 @@
const ipAddressRegexp = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
const ipAddressRegexp = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
export default function isIp(ipAddress: string) {
return ipAddressRegexp.test(ipAddress)
return ipAddressRegexp.test(ipAddress);
}

View File

@@ -1,6 +1,6 @@
const pathLengthRegex = /^[^.]{0,108}$/
const pathPatternRegex = /^([a-zA-Z0-9_][a-zA-Z0-9/_-]*[a-zA-Z0-9_])$/
const pathLengthRegex = /^[^.]{0,108}$/;
const pathPatternRegex = /^([a-zA-Z0-9_][a-zA-Z0-9/_-]*[a-zA-Z0-9_])$/;
export default function isPath(path: string) {
return pathLengthRegex.test(path) && pathPatternRegex.test(path)
return pathLengthRegex.test(path) && pathPatternRegex.test(path);
}

View File

@@ -1,4 +1,4 @@
const OPTIONAL = (validator: (value: any) => boolean) => (value: any) =>
!value || validator(value)
!value || validator(value);
export default OPTIONAL
export default OPTIONAL;

View File

@@ -1,8 +1,8 @@
const OR = (
validator1: (value: any) => boolean,
validator2: (value: any) => boolean,
validator2: (value: any) => boolean
) => {
return (value: any) => validator1(value) || validator2(value)
}
return (value: any) => validator1(value) || validator2(value);
};
export default OR
export default OR;