import { CustomPropertyDecorator , TypeOverride } from "@plumier/reflect" ; import validatorJs from "validator" ; import * as v from "./validation" ; interface Opt { message ? : string ; } namespace val { function check ( validator , message ) { return v . createValidation ( x => ! validator ( x ) ? message : undefined ) ; } param date export function after ( date ? ) ; param opt export function after ( opt ? ) ; export function after ( op ? ) { const opt = typeof op === "string" ? { date : op , message : undefined } : op ; return check ( x => validatorJs . isAfter ( x , opt && opt . date ) , opt && opt . message || `Date must be greater than ${ opt && opt . date || "today" }` ) ; } param opt export function alpha ( opt ? ) { return check ( x => validatorJs . isAlpha ( x , opt && opt . locale ) , opt && opt . message || "Invalid alpha" ) ; } param opt export function alphanumeric ( opt ? ) { return check ( x => validatorJs . isAlphanumeric ( x , opt && opt . locale ) , opt && opt . message || "Invalid alpha numeric" ) ; } param opt export function ascii ( opt ? ) { return check ( x => validatorJs . isAscii ( x ) , opt && opt . message || "Invalid ascii" ) ; } param opt export function base64 ( opt ? ) { return check ( x => validatorJs . isBase64 ( x ) , opt && opt . message || "Invalid base 64" ) ; } param date export function before ( date ? ) ; param opt export function before ( opt ? ) ; export function before ( op ? ) { const opt = typeof op === "string" ? { date : op , message : undefined } : op ; return check ( x => validatorJs . isBefore ( x , opt && opt . date ) , opt && opt . message || `Date must be less than ${ opt && opt . date || "today" }` ) ; } param opt export function byteLength ( opt ) { return check ( x => validatorJs . isByteLength ( x , opt ) , opt && opt . message || "Invalid byte length" ) ; } param opt export function creditCard ( opt ? ) { return check ( x => validatorJs . isCreditCard ( x ) , opt && opt . message || "Invalid credit card number" ) ; } param opt export function currency ( opt ? ) { return check ( x => validatorJs . isCurrency ( x , opt ) , opt && opt . message || "Invalid currency" ) ; } param opt export function dataURI ( opt ? ) { return check ( x => validatorJs . isDataURI ( x ) , opt && opt . message || "Invalid data URI" ) ; } param opt export function decimal ( opt ? ) { return check ( x => validatorJs . isDecimal ( x , opt ) , opt && opt . message || "Invalid decimal" ) ; } param num export function divisibleBy ( num ) ; param opt export function divisibleBy ( opt ) ; export function divisibleBy ( op ) { const opt = typeof op === "number" ? { num : op , message : undefined } : op ; return check ( x => validatorJs . isDivisibleBy ( x , opt . num ) , opt && opt . message || `Not divisible by ${ opt . num }` ) ; } param opt export function email ( opt ? ) { return check ( x => validatorJs . isEmail ( x , opt ) , opt && opt . message || "Invalid email address" ) ; } param opt export function fqdn ( opt ? ) { return check ( x => validatorJs . isFQDN ( x , opt ) , opt && opt . message || "Invalid FQDN" ) ; } param opt export function float ( opt ? ) { return check ( x => validatorJs . isFloat ( x , opt ) , opt && opt . message || "Invalid float number" ) ; } param opt export function fullWidth ( opt ? ) { return check ( x => validatorJs . isFullWidth ( x ) , opt && opt . message || "Invalid value provided" ) ; } param opt export function halfWidth ( opt ? ) { return check ( x => validatorJs . isHalfWidth ( x ) , opt && opt . message || "Invalid value provided" ) ; } param algorithm export function hash ( algorithm ) ; param opt export function hash ( opt ) ; export function hash ( op ) { const opt = typeof op === "string" ? { algorithm : op , message : undefined } : op ; return check ( x => validatorJs . isHash ( x , opt . algorithm ) , opt && opt . message || "Invalid hash" ) ; } param opt export function hexColor ( opt ? ) { return check ( x => validatorJs . isHexColor ( x ) , opt && opt . message || "Invalid hex color" ) ; } param opt export function hexadecimal ( opt ? ) { return check ( x => validatorJs . isHexadecimal ( x ) , opt && opt . message || "Invalid hexadecimal" ) ; } param version export function ip ( version ? ) ; param opt export function ip ( opt ? ) ; export function ip ( op ? ) { const opt = typeof op === "string" ? { version : op , message : undefined } : op ; return check ( x => validatorJs . isIP ( x , opt && opt . version ) , opt && opt . message || "Invalid IP address" ) ; } param version export function isbn ( version ? ) ; param opt export function isbn ( opt ? ) ; export function isbn ( op ? ) { const opt = typeof op === "string" ? { version : op , message : undefined } : op ; return check ( x => validatorJs . isISBN ( x , opt && opt . version ) , opt && opt . message || "Invalid ISBN" ) ; } param opt export function isin ( opt ? ) { return check ( x => validatorJs . isISIN ( x ) , opt && opt . message || "Invalid ISIN" ) ; } param opt export function iso31661Alpha2 ( opt ? ) { return check ( x => validatorJs . isISO31661Alpha2 ( x ) , opt && opt . message || "Invalid ISO 31661 Alpha 2" ) ; } param opt export function iso8601 ( opt ? ) { return check ( x => validatorJs . isISO8601 ( x ) , opt && opt . message || "Invalid ISO 8601 date" ) ; } param opt export function isrc ( opt ? ) { return check ( x => validatorJs . isISRC ( x ) , opt && opt . message || "Invalid ISRC" ) ; } param opt export function issn ( opt ? ) { return check ( x => validatorJs . isISSN ( x , opt ) , opt && opt . message || "Invalid ISSN" ) ; } param opt export function int ( opt ? ) { return check ( x => validatorJs . isInt ( x , opt ) , opt && opt . message || "Invalid integer" ) ; } param opt export function json ( opt ? ) { return check ( x => validatorJs . isJSON ( x ) , opt && opt . message || "Invalid JSON" ) ; } param opt export function latLong ( opt ? ) { return check ( x => validatorJs . isLatLong ( x ) , opt && opt . message || "Invalid lat long" ) ; } param opt export function length ( opt ) { return check ( x => validatorJs . isLength ( x , opt ) , opt && opt . message || "Invalid length" ) ; } param opt export function lowerCase ( opt ? ) { return check ( x => validatorJs . isLowercase ( x ) , opt && opt . message || "Invalid lower case" ) ; } param opt export function macAddress ( opt ? ) { return check ( x => validatorJs . isMACAddress ( x ) , opt && opt . message || "Invalid MAC address" ) ; } param opt export function md5 ( opt ? ) { return check ( x => validatorJs . isMD5 ( x ) , opt && opt . message || "Invalid MD5 hash" ) ; } param opt export function mimeType ( opt ? ) { return check ( x => validatorJs . isMimeType ( x ) , opt && opt . message || "Invalid mime type" ) ; } param opt export function mobilePhone ( opt ? ) { return check ( x => validatorJs . isMobilePhone ( x , opt && opt . locale , opt && opt . options ) , opt && opt . message || "Invalid mobile phone" ) ; } param opt export function mongoId ( opt ? ) { return check ( x => validatorJs . isMongoId ( x ) , opt && opt . message || "Invalid MongoDb id" ) ; } param opt export function multibyte ( opt ? ) { return check ( x => validatorJs . isMultibyte ( x ) , opt && opt . message || "Invalid multi byte" ) ; } param opt export function numeric ( opt ? ) { return check ( x => validatorJs . isNumeric ( x ) , opt && opt . message || "Invalid numeric" ) ; } param opt export function port ( opt ? ) { return check ( x => validatorJs . isPort ( x ) , opt && opt . message || "Invalid port" ) ; } param opt export function postalCode ( opt ? ) { return check ( x => validatorJs . isPostalCode ( x , opt && opt . locale || "any" ) , opt && opt . message || "Invalid postal code" ) ; } param pattern export function regex ( pattern ) ; param opt export function regex ( opt ) ; export function regex ( op ) { const opt = op instanceof RegExp ? { pattern : op , message : undefined } : op ; return check ( x => validatorJs . matches ( x , opt . pattern ) , opt . message || "Invalid string" ) ; } param opt export function slug ( opt ? ) { return check ( x => validatorJs . isSlug ( x ) , opt && opt . message || "Invalid slug" ) ; } param opt export function surrogatePair ( opt ? ) { return check ( x => validatorJs . isSurrogatePair ( x ) , opt && opt . message || "Invalid surrogate pair" ) ; } param opt export function url ( opt ? ) { return check ( x => validatorJs . isURL ( x , opt ) , opt && opt . message || "Invalid url" ) ; } param opt export function UUID ( opt ? ) { return check ( x => validatorJs . isUUID ( x ) , opt && opt . message || "Invalid UUID" ) ; } param opt export function uppercase ( opt ? ) { return check ( x => validatorJs . isUppercase ( x ) , opt && opt . message || "Invalid uppercase" ) ; } param opt export function variableWidth ( opt ? ) { return check ( x => validatorJs . isVariableWidth ( x ) , opt && opt . message || "Invalid variable width" ) ; } param opt export function whiteListed ( opt ) { return check ( x => validatorJs . isWhitelisted ( x , opt && opt . chars ) , opt && opt . message || "Invalid white listed" ) ; } /**
     * Mark if the property is required
     */ export function required ( ) { return v . required ( ) ; } param typ export function partial ( typ ) { return v . partial ( typ ) ; } } export { val , Opt } ;