]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/custom-validators/misc.ts
Refractor validators
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / misc.ts
index 8d215a416bc899c6cbf122b7fad5f603f2dbc512..160ec91f3912211c4ea9b787d489ea9aa981a4d7 100644 (file)
@@ -1,4 +1,4 @@
-import 'express-validator'
+import * as validator from 'validator'
 
 function exists (value: any) {
   return value !== undefined && value !== null
@@ -8,16 +8,29 @@ function isArray (value: any) {
   return Array.isArray(value)
 }
 
+function isDateValid (value: string) {
+  return exists(value) && validator.isISO8601(value)
+}
+
+function isIdValid (value: string) {
+  return exists(value) && validator.isInt('' + value)
+}
+
+function isUUIDValid (value: string) {
+  return exists(value) && validator.isUUID('' + value, 4)
+}
+
+function isIdOrUUIDValid (value: string) {
+  return isIdValid(value) || isUUIDValid(value)
+}
+
 // ---------------------------------------------------------------------------
 
 export {
   exists,
-  isArray
-}
-
-declare module 'express-validator' {
-  export interface Validator {
-    exists,
-    isArray
-  }
+  isArray,
+  isIdValid,
+  isUUIDValid,
+  isIdOrUUIDValid,
+  isDateValid
 }