From 989543a2b87e37a4ca25f3c6189bd51d7e1cdac0 Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Thu, 26 Sep 2019 15:27:13 +0545 Subject: [PATCH 01/10] added islatlong --- src/decorator/decorators.ts | 16 +++++++++++++ src/validation/ValidationTypes.ts | 1 + src/validation/Validator.ts | 13 ++++++++++ ...alidation-functions-and-decorators.spec.ts | 24 +++++++++++++++++++ 4 files changed, 54 insertions(+) diff --git a/src/decorator/decorators.ts b/src/decorator/decorators.ts index 33b627fe41..8619b71c94 100644 --- a/src/decorator/decorators.ts +++ b/src/decorator/decorators.ts @@ -260,6 +260,22 @@ export function IsBoolean(validationOptions?: ValidationOptions) { }; } + +/** + * Checks if a value is a boolean. + */ +export function IsLatLong(validationOptions?: ValidationOptions) { + return function (object: Object, propertyName: string) { + const args: ValidationMetadataArgs = { + type: ValidationTypes.IS_LATLONG, + target: object.constructor, + propertyName: propertyName, + validationOptions: validationOptions + }; + getFromContainer(MetadataStorage).addValidationMetadata(new ValidationMetadata(args)); + }; +} + /** * Checks if a value is a date. */ diff --git a/src/validation/ValidationTypes.ts b/src/validation/ValidationTypes.ts index dc2fa1ab34..0f5e877b9c 100644 --- a/src/validation/ValidationTypes.ts +++ b/src/validation/ValidationTypes.ts @@ -25,6 +25,7 @@ export class ValidationTypes { static IS_BOOLEAN = "isBoolean"; static IS_DATE = "isDate"; static IS_NUMBER = "isNumber"; + static IS_LATLONG = "isLatLong"; static IS_STRING = "isString"; static IS_DATE_STRING = "isDateString"; static IS_ARRAY = "isArray"; diff --git a/src/validation/Validator.ts b/src/validation/Validator.ts index 7126c52163..3703367edb 100644 --- a/src/validation/Validator.ts +++ b/src/validation/Validator.ts @@ -127,6 +127,8 @@ export class Validator { return this.isNotIn(value, metadata.constraints[0]); /* type checkers */ + case ValidationTypes.IS_LATLONG: + return this.isLatLong(value); case ValidationTypes.IS_BOOLEAN: return this.isBoolean(value); case ValidationTypes.IS_DATE: @@ -332,6 +334,17 @@ export class Validator { return value instanceof Boolean || typeof value === "boolean"; } + isLatLong(value: any): boolean { + + const lat = /^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/; + const long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/; + if (!value.includes(",")) return false; + const pair = value.split(","); + if ((pair[0].startsWith("(") && !pair[1].endsWith(")")) + || (pair[1].endsWith(")") && !pair[0].startsWith("("))) return false; + return lat.test(pair[0]) && long.test(pair[1]); + } + /** * Checks if a given value is a real date. */ diff --git a/test/functional/validation-functions-and-decorators.spec.ts b/test/functional/validation-functions-and-decorators.spec.ts index e7f6dd2ec2..b515905faf 100644 --- a/test/functional/validation-functions-and-decorators.spec.ts +++ b/test/functional/validation-functions-and-decorators.spec.ts @@ -3,6 +3,7 @@ import {expect} from "chai"; import { IsBooleanString, IsPositive, + IsLatLong, IsNegative, Contains, Equals, @@ -441,6 +442,29 @@ describe("IsBoolean", function() { checkReturnedError(new MyClass(), invalidValues, validationType, message, done); }); +}); +// ------------------------------------------------------------------------- +// Specifications: type check +// ------------------------------------------------------------------------- + +describe("IsLatLong", function () { + + const validValues = ["27.6945311,85.3446311", "27.675509,85.2100893"]; + const invalidValues = [ "276945311,853446311" , "asas,as.as12" ]; + + class MyClass { + @IsLatLong() + someProperty: any; + } + + it("should not fail if validator.validate said that its valid", function (done) { + checkValidValues(new MyClass(), validValues, done); + }); + + it("should fail if validator.validate said that its invalid", function (done) { + checkInvalidValues(new MyClass(), invalidValues, done); + }); + }); describe("IsDate", function() { From b74ab854cf4b9e69a17cd88d1034f22bebe3f9d1 Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Tue, 1 Oct 2019 23:58:14 +0545 Subject: [PATCH 02/10] updated readme and islatlong code --- README.md | 2 ++ src/validation/Validator.ts | 8 +------- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index de7d9f469b..189fd8876d 100644 --- a/README.md +++ b/README.md @@ -848,6 +848,7 @@ validator.isURL(str, options); // Checks if the string is an url. validator.isUUID(str, version); // Checks if the string is a UUID (version 3, 4 or 5). validator.isUppercase(str); // Checks if the string is uppercase. validator.length(str, min, max); // Checks if the string's length falls in a range. +validator.isLatLong(str); // check if the string is a valid latitude-longitude coordinate in the format lat,long or lat, long validator.minLength(str, min); // Checks if the string's length is not less than given number. validator.maxLength(str, max); // Checks if the string's length is not more than given number. validator.matches(str, pattern, modifiers); // Checks if string matches the pattern. Either matches('foo', /foo/i) or matches('foo', 'foo', 'i'). @@ -923,6 +924,7 @@ validator.isInstance(value, target); // Checks value is an instance of the targe | `@IsISO8601()` | Checks if the string is a valid ISO 8601 date. | | `@IsJSON()` | Checks if the string is valid JSON. | | `@IsLowercase()` | Checks if the string is lowercase. | +| `@IsLatLong()` | Checks if the string is lat,long or lat, long. | | `@IsMobilePhone(locale: string)` | Checks if the string is a mobile phone number. | | `@IsISO31661Alpha2()` | Check if the string is a valid [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) officially assigned country code. | | `@IsISO31661Alpha3()` | Check if the string is a valid [ISO 3166-1 alpha-3](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3) officially assigned country code. | diff --git a/src/validation/Validator.ts b/src/validation/Validator.ts index 3703367edb..117cd57c7b 100644 --- a/src/validation/Validator.ts +++ b/src/validation/Validator.ts @@ -336,13 +336,7 @@ export class Validator { isLatLong(value: any): boolean { - const lat = /^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/; - const long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/; - if (!value.includes(",")) return false; - const pair = value.split(","); - if ((pair[0].startsWith("(") && !pair[1].endsWith(")")) - || (pair[1].endsWith(")") && !pair[0].startsWith("("))) return false; - return lat.test(pair[0]) && long.test(pair[1]); + return validator.isLatLong(value); } /** From 3b4411dc22243f3156c8f7348c58b8cd948fb1ef Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Wed, 2 Oct 2019 00:54:24 +0545 Subject: [PATCH 03/10] added default message for latlong --- src/validation/ValidationTypes.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/validation/ValidationTypes.ts b/src/validation/ValidationTypes.ts index 0f5e877b9c..bfe6849632 100644 --- a/src/validation/ValidationTypes.ts +++ b/src/validation/ValidationTypes.ts @@ -233,6 +233,8 @@ export class ValidationTypes { return eachPrefix + "$property must be a valid ISO31661 Alpha2 code"; case this.IS_ISO31661_ALPHA_3: return eachPrefix + "$property must be a valid ISO31661 Alpha3 code"; + case this.IS_LATLONG: + return eachPrefix + "$property must be a latitude,longitude string"; case this.IS_MONGO_ID: return eachPrefix + "$property must be a mongodb id"; case this.IS_MULTIBYTE: From 3c1c331634fc9120ada63baf9e31bd2174db6d58 Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Wed, 2 Oct 2019 17:01:11 +0545 Subject: [PATCH 04/10] added IsLatitude and IsLongitude --- src/decorator/decorators.ts | 35 +++++++++++- src/validation/ValidationTypes.ts | 2 + src/validation/Validator.ts | 26 +++++++++ ...alidation-functions-and-decorators.spec.ts | 57 +++++++++++++++++++ 4 files changed, 119 insertions(+), 1 deletion(-) diff --git a/src/decorator/decorators.ts b/src/decorator/decorators.ts index 8619b71c94..ca7cfa419f 100644 --- a/src/decorator/decorators.ts +++ b/src/decorator/decorators.ts @@ -262,7 +262,7 @@ export function IsBoolean(validationOptions?: ValidationOptions) { /** - * Checks if a value is a boolean. + * Checks if a value is a latitude,longitude. */ export function IsLatLong(validationOptions?: ValidationOptions) { return function (object: Object, propertyName: string) { @@ -276,6 +276,39 @@ export function IsLatLong(validationOptions?: ValidationOptions) { }; } +/** + * Checks if a value is a latitude,longitude. + */ +export function IsLatitude(validationOptions?: ValidationOptions) { + return function (object: Object, propertyName: string) { + const args: ValidationMetadataArgs = { + type: ValidationTypes.IS_LONGITUDE, + target: object.constructor, + propertyName: propertyName, + validationOptions: validationOptions + }; + getFromContainer(MetadataStorage).addValidationMetadata(new ValidationMetadata(args)); + }; +} + + +/** + * Checks if a value is a latitude,longitude. + */ +export function IsLongitude(validationOptions?: ValidationOptions) { + return function (object: Object, propertyName: string) { + const args: ValidationMetadataArgs = { + type: ValidationTypes.IS_LATITUDE, + target: object.constructor, + propertyName: propertyName, + validationOptions: validationOptions + }; + getFromContainer(MetadataStorage).addValidationMetadata(new ValidationMetadata(args)); + }; +} + + + /** * Checks if a value is a date. */ diff --git a/src/validation/ValidationTypes.ts b/src/validation/ValidationTypes.ts index bfe6849632..7ab40e90e5 100644 --- a/src/validation/ValidationTypes.ts +++ b/src/validation/ValidationTypes.ts @@ -26,6 +26,8 @@ export class ValidationTypes { static IS_DATE = "isDate"; static IS_NUMBER = "isNumber"; static IS_LATLONG = "isLatLong"; + static IS_LATITUDE = "isLatitude"; + static IS_LONGITUDE = "isLongitude"; static IS_STRING = "isString"; static IS_DATE_STRING = "isDateString"; static IS_ARRAY = "isArray"; diff --git a/src/validation/Validator.ts b/src/validation/Validator.ts index 117cd57c7b..fd92f05d9c 100644 --- a/src/validation/Validator.ts +++ b/src/validation/Validator.ts @@ -129,6 +129,13 @@ export class Validator { /* type checkers */ case ValidationTypes.IS_LATLONG: return this.isLatLong(value); + + case ValidationTypes.IS_LATITUDE: + return this.isLatitude(value); + + case ValidationTypes.IS_LONGITUDE: + return this.isLongitude(value); + case ValidationTypes.IS_BOOLEAN: return this.isBoolean(value); case ValidationTypes.IS_DATE: @@ -334,11 +341,30 @@ export class Validator { return value instanceof Boolean || typeof value === "boolean"; } + +/** +* Checks if a given value is a latitude. +*/ isLatLong(value: any): boolean { return validator.isLatLong(value); } + isLatitude(value: any): boolean { + const lat = /^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/; + + return lat.test(value); + } + +/** +* Checks if a given value is a longitude. +*/ + + isLongitude(value: any): boolean { + const long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/; + return long.test(value); + } + /** * Checks if a given value is a real date. */ diff --git a/test/functional/validation-functions-and-decorators.spec.ts b/test/functional/validation-functions-and-decorators.spec.ts index b515905faf..db77350cdb 100644 --- a/test/functional/validation-functions-and-decorators.spec.ts +++ b/test/functional/validation-functions-and-decorators.spec.ts @@ -4,6 +4,8 @@ import { IsBooleanString, IsPositive, IsLatLong, + IsLongitude, + IsLatitude, IsNegative, Contains, Equals, @@ -466,6 +468,61 @@ describe("IsLatLong", function () { }); }); +describe("IsLatitude", function () { + + const validValues = ["27.6945311", "27.675509"]; + const invalidValues = ["276945311", "asas"]; + + class MyClass { + @IsLatitude() + someProperty: any; + } + + it("should not fail if validator.validate said that its valid", function (done) { + checkValidValues(new MyClass(), validValues, done); + }); + + it("should fail if validator.validate said that its invalid", function (done) { + checkInvalidValues(new MyClass(), invalidValues, done); + }); + +}); + +describe("IsLongitude", function () { + + const validValues = ["85.3446311", "85.2100893"]; + const invalidValues = ["853446311", "as.as12"]; + + class MyClass { + @IsLongitude() + someProperty: any; + } + + it("should not fail if validator.validate said that its valid", function (done) { + checkValidValues(new MyClass(), validValues, done); + }); + + it("should fail if validator.validate said that its invalid", function (done) { + checkInvalidValues(new MyClass(), invalidValues, done); + }); + +}); + + + + + + + + + + + + + + + + describe("IsDate", function() { From e3f4ce46254edeb77ab0082d523022afd108fb7c Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Wed, 2 Oct 2019 18:51:25 +0545 Subject: [PATCH 05/10] added IsLatitude and IsLongitude --- README.md | 9 +++++---- src/validation/ValidationTypes.ts | 5 +++++ src/validation/Validator.ts | 10 ++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 189fd8876d..84fa4bf99c 100644 --- a/README.md +++ b/README.md @@ -470,7 +470,7 @@ import { validate } from 'class-validator'; class MyClass { @MinLength(32, { - message: "EIC code must be at least 32 charatcers", + message: "EIC code must be at least 32 characters", context: { errorCode: 1003, developerNote: "The validated string must contain 32 or more characters." @@ -848,7 +848,6 @@ validator.isURL(str, options); // Checks if the string is an url. validator.isUUID(str, version); // Checks if the string is a UUID (version 3, 4 or 5). validator.isUppercase(str); // Checks if the string is uppercase. validator.length(str, min, max); // Checks if the string's length falls in a range. -validator.isLatLong(str); // check if the string is a valid latitude-longitude coordinate in the format lat,long or lat, long validator.minLength(str, min); // Checks if the string's length is not less than given number. validator.maxLength(str, max); // Checks if the string's length is not more than given number. validator.matches(str, pattern, modifiers); // Checks if string matches the pattern. Either matches('foo', /foo/i) or matches('foo', 'foo', 'i'). @@ -923,8 +922,10 @@ validator.isInstance(value, target); // Checks value is an instance of the targe | `@IsISIN()` | Checks if the string is an ISIN (stock/security identifier). | | `@IsISO8601()` | Checks if the string is a valid ISO 8601 date. | | `@IsJSON()` | Checks if the string is valid JSON. | -| `@IsLowercase()` | Checks if the string is lowercase. | -| `@IsLatLong()` | Checks if the string is lat,long or lat, long. | +| `@IsLowercase()` | Checks if the string is lowercase. +| `@IsLatLong()` | check if the string is a valid latitude-longitude coordinate in the format lat,long +| `@IsLatitude()` | check if the string is a valid latitude coordinate +| `@IsLongitude()` | check if the string is a valid longitude coordinate | `@IsMobilePhone(locale: string)` | Checks if the string is a mobile phone number. | | `@IsISO31661Alpha2()` | Check if the string is a valid [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) officially assigned country code. | | `@IsISO31661Alpha3()` | Check if the string is a valid [ISO 3166-1 alpha-3](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3) officially assigned country code. | diff --git a/src/validation/ValidationTypes.ts b/src/validation/ValidationTypes.ts index 7ab40e90e5..504fa75408 100644 --- a/src/validation/ValidationTypes.ts +++ b/src/validation/ValidationTypes.ts @@ -237,6 +237,11 @@ export class ValidationTypes { return eachPrefix + "$property must be a valid ISO31661 Alpha3 code"; case this.IS_LATLONG: return eachPrefix + "$property must be a latitude,longitude string"; + + case this.IS_LATITUDE: + return eachPrefix + "$property must be a latitude string"; + case this.IS_LONGITUDE: + return eachPrefix + "$property must be a longitude string"; case this.IS_MONGO_ID: return eachPrefix + "$property must be a mongodb id"; case this.IS_MULTIBYTE: diff --git a/src/validation/Validator.ts b/src/validation/Validator.ts index fd92f05d9c..7dd62b7c73 100644 --- a/src/validation/Validator.ts +++ b/src/validation/Validator.ts @@ -347,13 +347,11 @@ export class Validator { */ isLatLong(value: any): boolean { - return validator.isLatLong(value); + return this.validatorJs.isLatLong(value); } isLatitude(value: any): boolean { - const lat = /^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/; - - return lat.test(value); + return (typeof value === "number" || this.isString(value)) && this.isLatLong(`0,${value}`); } /** @@ -361,8 +359,8 @@ export class Validator { */ isLongitude(value: any): boolean { - const long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/; - return long.test(value); + return (typeof value === "number" || this.isString(value)) && this.isLatLong(`${value},0`); + } /** From 64b3cca805031f336ebfb01757e157679dbaf71d Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Wed, 2 Oct 2019 20:35:51 +0545 Subject: [PATCH 06/10] indented --- src/validation/Validator.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/validation/Validator.ts b/src/validation/Validator.ts index 7dd62b7c73..1c3709b0a6 100644 --- a/src/validation/Validator.ts +++ b/src/validation/Validator.ts @@ -342,21 +342,27 @@ export class Validator { } -/** -* Checks if a given value is a latitude. -*/ + /** + * Checks if a given value is a latitude. + */ + isLatLong(value: any): boolean { return this.validatorJs.isLatLong(value); } + /** + * Checks if a given value is a latitude. + */ + + isLatitude(value: any): boolean { return (typeof value === "number" || this.isString(value)) && this.isLatLong(`0,${value}`); } -/** -* Checks if a given value is a longitude. -*/ + /** + * Checks if a given value is a longitude. + */ isLongitude(value: any): boolean { return (typeof value === "number" || this.isString(value)) && this.isLatLong(`${value},0`); From ea97c755ba56c4ce436d3a1bed4d06d997daef12 Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Wed, 2 Oct 2019 20:45:31 +0545 Subject: [PATCH 07/10] indented and changed testcases values --- README.md | 4 ++-- src/validation/ValidationTypes.ts | 5 ++-- ...alidation-functions-and-decorators.spec.ts | 24 ++++--------------- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 84fa4bf99c..eaa9ee26c7 100644 --- a/README.md +++ b/README.md @@ -925,8 +925,8 @@ validator.isInstance(value, target); // Checks value is an instance of the targe | `@IsLowercase()` | Checks if the string is lowercase. | `@IsLatLong()` | check if the string is a valid latitude-longitude coordinate in the format lat,long | `@IsLatitude()` | check if the string is a valid latitude coordinate -| `@IsLongitude()` | check if the string is a valid longitude coordinate -| `@IsMobilePhone(locale: string)` | Checks if the string is a mobile phone number. | +| `@IsLongitude()` | check if the string or number is a valid longitude coordinate +| `@IsMobilePhone(locale: string)` | Checks if the string or number is a mobile phone number. | | `@IsISO31661Alpha2()` | Check if the string is a valid [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) officially assigned country code. | | `@IsISO31661Alpha3()` | Check if the string is a valid [ISO 3166-1 alpha-3](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3) officially assigned country code. | | `@IsPhoneNumber(region: string)` | Checks if the string is a valid phone number. "region" accepts 2 characters uppercase country code (e.g. DE, US, CH).If users must enter the intl. prefix (e.g. +41), then you may pass "ZZ" or null as region. See [google-libphonenumber, metadata.js:countryCodeToRegionCodeMap on github](https://github.com/ruimarinho/google-libphonenumber/blob/1e46138878cff479aafe2ce62175c6c49cb58720/src/metadata.js#L33) | diff --git a/src/validation/ValidationTypes.ts b/src/validation/ValidationTypes.ts index 504fa75408..5ac6b3a750 100644 --- a/src/validation/ValidationTypes.ts +++ b/src/validation/ValidationTypes.ts @@ -237,11 +237,10 @@ export class ValidationTypes { return eachPrefix + "$property must be a valid ISO31661 Alpha3 code"; case this.IS_LATLONG: return eachPrefix + "$property must be a latitude,longitude string"; - case this.IS_LATITUDE: - return eachPrefix + "$property must be a latitude string"; + return eachPrefix + "$property must be a latitude string or number"; case this.IS_LONGITUDE: - return eachPrefix + "$property must be a longitude string"; + return eachPrefix + "$property must be a longitude string or number"; case this.IS_MONGO_ID: return eachPrefix + "$property must be a mongodb id"; case this.IS_MULTIBYTE: diff --git a/test/functional/validation-functions-and-decorators.spec.ts b/test/functional/validation-functions-and-decorators.spec.ts index db77350cdb..915b0def58 100644 --- a/test/functional/validation-functions-and-decorators.spec.ts +++ b/test/functional/validation-functions-and-decorators.spec.ts @@ -470,8 +470,8 @@ describe("IsLatLong", function () { }); describe("IsLatitude", function () { - const validValues = ["27.6945311", "27.675509"]; - const invalidValues = ["276945311", "asas"]; + const validValues = ["27.6945311", "27.675509", 27.675509]; + const invalidValues = ["276945311", "asas", 1234222, 5678921]; class MyClass { @IsLatitude() @@ -490,8 +490,8 @@ describe("IsLatitude", function () { describe("IsLongitude", function () { - const validValues = ["85.3446311", "85.2100893"]; - const invalidValues = ["853446311", "as.as12"]; + const validValues = ["85.3446311", "85.2100893", 85.2100893]; + const invalidValues = ["853446311", "as.as12", 12345 , 737399]; class MyClass { @IsLongitude() @@ -508,22 +508,6 @@ describe("IsLongitude", function () { }); - - - - - - - - - - - - - - - - describe("IsDate", function() { const validValues = [new Date()]; From 8fb6ecc0a1380df8894286c5ca9a89fc7b8c7ff2 Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Wed, 2 Oct 2019 21:35:27 +0545 Subject: [PATCH 08/10] removed empty lines --- src/validation/Validator.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/validation/Validator.ts b/src/validation/Validator.ts index 1c3709b0a6..fe7f5ee423 100644 --- a/src/validation/Validator.ts +++ b/src/validation/Validator.ts @@ -129,13 +129,10 @@ export class Validator { /* type checkers */ case ValidationTypes.IS_LATLONG: return this.isLatLong(value); - case ValidationTypes.IS_LATITUDE: return this.isLatitude(value); - case ValidationTypes.IS_LONGITUDE: return this.isLongitude(value); - case ValidationTypes.IS_BOOLEAN: return this.isBoolean(value); case ValidationTypes.IS_DATE: @@ -345,7 +342,6 @@ export class Validator { /** * Checks if a given value is a latitude. */ - isLatLong(value: any): boolean { return this.validatorJs.isLatLong(value); @@ -354,8 +350,6 @@ export class Validator { /** * Checks if a given value is a latitude. */ - - isLatitude(value: any): boolean { return (typeof value === "number" || this.isString(value)) && this.isLatLong(`0,${value}`); } @@ -363,10 +357,8 @@ export class Validator { /** * Checks if a given value is a longitude. */ - isLongitude(value: any): boolean { return (typeof value === "number" || this.isString(value)) && this.isLatLong(`${value},0`); - } /** From 7829053e0226a33c519bd610f5aa7cb9abd6bd07 Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Wed, 2 Oct 2019 21:42:25 +0545 Subject: [PATCH 09/10] fixed typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eaa9ee26c7..dfb4c8d1ab 100644 --- a/README.md +++ b/README.md @@ -924,9 +924,9 @@ validator.isInstance(value, target); // Checks value is an instance of the targe | `@IsJSON()` | Checks if the string is valid JSON. | | `@IsLowercase()` | Checks if the string is lowercase. | `@IsLatLong()` | check if the string is a valid latitude-longitude coordinate in the format lat,long -| `@IsLatitude()` | check if the string is a valid latitude coordinate +| `@IsLatitude()` | check if the string or number is a valid latitude coordinate | `@IsLongitude()` | check if the string or number is a valid longitude coordinate -| `@IsMobilePhone(locale: string)` | Checks if the string or number is a mobile phone number. | +| `@IsMobilePhone(locale: string)` | Checks if the string is a mobile phone number. | | `@IsISO31661Alpha2()` | Check if the string is a valid [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) officially assigned country code. | | `@IsISO31661Alpha3()` | Check if the string is a valid [ISO 3166-1 alpha-3](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3) officially assigned country code. | | `@IsPhoneNumber(region: string)` | Checks if the string is a valid phone number. "region" accepts 2 characters uppercase country code (e.g. DE, US, CH).If users must enter the intl. prefix (e.g. +41), then you may pass "ZZ" or null as region. See [google-libphonenumber, metadata.js:countryCodeToRegionCodeMap on github](https://github.com/ruimarinho/google-libphonenumber/blob/1e46138878cff479aafe2ce62175c6c49cb58720/src/metadata.js#L33) | From 5b54072852a5c980e321b374afd8bf7861f0c334 Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Wed, 2 Oct 2019 21:44:14 +0545 Subject: [PATCH 10/10] fixed indenting --- src/decorator/decorators.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/decorator/decorators.ts b/src/decorator/decorators.ts index ca7cfa419f..f2463ad0c7 100644 --- a/src/decorator/decorators.ts +++ b/src/decorator/decorators.ts @@ -260,7 +260,6 @@ export function IsBoolean(validationOptions?: ValidationOptions) { }; } - /** * Checks if a value is a latitude,longitude. */ @@ -291,7 +290,6 @@ export function IsLatitude(validationOptions?: ValidationOptions) { }; } - /** * Checks if a value is a latitude,longitude. */ @@ -307,8 +305,6 @@ export function IsLongitude(validationOptions?: ValidationOptions) { }; } - - /** * Checks if a value is a date. */