]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/helpers/custom-validators/misc.ts
Handle HTML is comments
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / misc.ts
CommitLineData
72c7248b 1import * as validator from 'validator'
fdbda9e3 2
69818c93 3function exists (value: any) {
e4c55619
C
4 return value !== undefined && value !== null
5}
6
69818c93 7function isArray (value: any) {
e4c55619
C
8 return Array.isArray(value)
9}
10
72c7248b
C
11function isDateValid (value: string) {
12 return exists(value) && validator.isISO8601(value)
13}
14
15function isIdValid (value: string) {
16 return exists(value) && validator.isInt('' + value)
17}
18
19function isUUIDValid (value: string) {
20 return exists(value) && validator.isUUID('' + value, 4)
21}
22
23function isIdOrUUIDValid (value: string) {
24 return isIdValid(value) || isUUIDValid(value)
25}
26
47564bbe
C
27function isBooleanValid (value: string) {
28 return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value))
29}
30
e4c55619
C
31// ---------------------------------------------------------------------------
32
65fcc311
C
33export {
34 exists,
72c7248b
C
35 isArray,
36 isIdValid,
37 isUUIDValid,
38 isIdOrUUIDValid,
47564bbe
C
39 isDateValid,
40 isBooleanValid
65fcc311 41}