@@ -5,6 +5,7 @@ import {IsNumberOptions} from "./ValidationTypeOptions";
55import { ValidatorOptions } from "./ValidatorOptions" ;
66import { ValidationExecutor } from "./ValidationExecutor" ;
77import { ValidationOptions } from "../decorator/ValidationOptions" ;
8+ import * as validator from "validator" ;
89
910/**
1011 * Validator performs validation of the given object based on its metadata.
@@ -15,7 +16,7 @@ export class Validator {
1516 // Private Properties
1617 // -------------------------------------------------------------------------
1718
18- private validatorJs = require ( " validator" ) ;
19+ private validatorJs = validator ;
1920 private libPhoneNumber = {
2021 phoneUtil : require ( "google-libphonenumber" ) . PhoneNumberUtil . getInstance ( ) ,
2122 } ;
@@ -204,6 +205,8 @@ export class Validator {
204205 return this . isHexadecimal ( value ) ;
205206 case ValidationTypes . IS_IP :
206207 return this . isIP ( value , metadata . constraints [ 0 ] ) ;
208+ case ValidationTypes . IS_PORT :
209+ return this . isPort ( value ) ;
207210 case ValidationTypes . IS_ISBN :
208211 return this . isISBN ( value , metadata . constraints [ 0 ] ) ;
209212 case ValidationTypes . IS_ISIN :
@@ -613,15 +616,22 @@ export class Validator {
613616 * Checks if the string is an IP (version 4 or 6).
614617 * If given value is not a string, then it returns false.
615618 */
616- isIP ( value : string , version ?: "4" | "6" ) : boolean {
619+ isIP ( value : string , version ?: number ) : boolean {
617620 return typeof value === "string" && this . validatorJs . isIP ( value , version ) ;
618621 }
619622
623+ /**
624+ * Check if the string is a valid port number.
625+ */
626+ isPort ( value : string ) : boolean {
627+ return this . validatorJs . isPort ( value ) ;
628+ }
629+
620630 /**
621631 * Checks if the string is an ISBN (version 10 or 13).
622632 * If given value is not a string, then it returns false.
623633 */
624- isISBN ( value : string , version ?: "10" | "13" ) : boolean {
634+ isISBN ( value : string , version ?: number ) : boolean {
625635 return typeof value === "string" && this . validatorJs . isISBN ( value , version ) ;
626636 }
627637
0 commit comments