/
web.ts
74 lines (64 loc) · 1.58 KB
/
web.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import * as util from 'util';
import { default as validator } from 'validator';
/**
*
* @param value
* @returns
* @category Internet Validator
*/
export const isHexadecimal = validator.isHexadecimal;
/**
*
* @param value
* @returns
* @category Internet Validator
*/
export const isHexColor = validator.isHexColor;
/**
*
* @param value
* @returns
* @category Internet Validator
*/
export const isHSL = validator.isHSL;
/**
* Check if the string is valid JWT token.
*
* @param value The string to validate
* @returns
* @category Internet Validator
*/
export const isJWT = validator.isJWT;
/**
* check if the string is a rgb or rgba color.
*
* @param value The string to validate
* @param includePercentValues
* @returns
* @category Internet Validator
*/
export const isRgbColor = (value: string, includePercentValues?: boolean) => {
return validator.isRgbColor(value, includePercentValues);
}
/**
* Check if the string is of type slug. Options allow a single hyphen between string. e.g. [cn-cn, cn-c-c]
*
* @param value The string to validate
* @returns
* @category Internet Validator
*/
export const isSlug = validator.isSlug;
/**
* check if the string is a UUID (version 1, 2, 3, 4 or 5).
*
* @param value The string to validate
* @param version
* @returns
* @category Internet Validator
*/
export const isUUID = (value: string, version?: number | string) => {
if (typeof version === 'string' && version !== 'any') {
throw new Error(`isUUID invalid version ${version}`);
}
return validator.isUUID(value, version ?? 'any');
}