From af0fdeeab0fb2d0bc8089897dcd003a8aa5a370a Mon Sep 17 00:00:00 2001 From: Naoto Yokoyama Date: Tue, 20 Feb 2018 19:45:47 +0900 Subject: [PATCH 01/17] validator (v7.0): remove isDate() --- types/validator/index.d.ts | 11 ++--------- types/validator/validator-tests.ts | 6 ------ 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/types/validator/index.d.ts b/types/validator/index.d.ts index e27b1e70c0..34de2ee9f9 100644 --- a/types/validator/index.d.ts +++ b/types/validator/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for validator.js v6.3 +// Type definitions for validator.js v7.0 // Project: https://github.com/chriso/validator.js // Definitions by: tgfjt // Ilya Mochalov @@ -6,6 +6,7 @@ // Louy Alakkad // Kacper Polak // Bonggyun Lee +// Naoto Yokoyama // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace ValidatorJS { @@ -66,9 +67,6 @@ declare namespace ValidatorJS { // check if the string is a data uri format (https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs) isDataURI(str: string): boolean; - // check if the string is a date. - isDate(str: string): boolean; - // check if the string represents a decimal number, such as 0.1, .3, 1.1, 1.00003, 4.0, etc. isDecimal(str: string): boolean; @@ -406,11 +404,6 @@ declare module "validator/lib/isDataURI" { export = isDataURI; } -declare module "validator/lib/isDate" { - const isDate: typeof validator.isDate; - export = isDate; -} - declare module "validator/lib/isDecimal" { const isDecimal: typeof validator.isDecimal; export = isDecimal; diff --git a/types/validator/validator-tests.ts b/types/validator/validator-tests.ts index 2bda229ea6..92acf504c4 100644 --- a/types/validator/validator-tests.ts +++ b/types/validator/validator-tests.ts @@ -20,7 +20,6 @@ import isByteLengthFunc = require('validator/lib/isByteLength'); import isCreditCardFunc = require('validator/lib/isCreditCard'); import isCurrencyFunc = require('validator/lib/isCurrency'); import isDataURIFunc = require('validator/lib/isDataURI'); -import isDateFunc = require('validator/lib/isDate'); import isDecimalFunc = require('validator/lib/isDecimal'); import isDivisibleByFunc = require('validator/lib/isDivisibleBy'); import isEmailFunc = require('validator/lib/isEmail'); @@ -113,9 +112,6 @@ import whitelistFunc = require('validator/lib/whitelist'); let _isDataURI = validator.isDataURI; _isDataURI = isDataURIFunc; - let _isDate = validator.isDate; - _isDate = isDateFunc; - let _isDecimal = validator.isDecimal; _isDecimal = isDecimalFunc; @@ -378,8 +374,6 @@ let any: any; result = validator.isDataURI('sample'); - result = validator.isDate('sample'); - result = validator.isDecimal('sample'); result = validator.isDivisibleBy('sample', 2); From caf5db5ccf11fa02e016f175a2f40e0c096e6267 Mon Sep 17 00:00:00 2001 From: Naoto Yokoyama Date: Tue, 20 Feb 2018 20:05:26 +0900 Subject: [PATCH 02/17] validator (v7.1): add isISRC() and mobile phone locales Added locales are: - id-ID (https://github.com/chriso/validator.js/pull/647) - lt-LT (https://github.com/chriso/validator.js/pull/667) - fa-IR (https://github.com/chriso/validator.js/pull/671) ko-KR (https://github.com/chriso/validator.js/pull/668) has already been added. --- types/validator/index.d.ts | 18 +++++++++++++----- types/validator/validator-tests.ts | 9 +++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/types/validator/index.d.ts b/types/validator/index.d.ts index 34de2ee9f9..22fe951788 100644 --- a/types/validator/index.d.ts +++ b/types/validator/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for validator.js v7.0 +// Type definitions for validator.js v7.1 // Project: https://github.com/chriso/validator.js // Definitions by: tgfjt // Ilya Mochalov @@ -12,7 +12,7 @@ declare namespace ValidatorJS { type AlphaLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "nl-NL" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "tr-TR"; type AlphanumericLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "fr-BE" | "hu-HU" | "nl-BE" | "nl-NL" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "tr-TR"; - type MobilePhoneLocale = "ar-DZ" | "ar-SA" | "ar-SY" | "cs-CZ" | "de-DE" | "da-DK" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-CA" | "en-ZA" | "en-ZM" | "es-ES" | "fi-FI" | "fr-FR" | "hu-HU" | "it-IT" | "ja-JP" | "ko-KR" | "ms-MY" | "nb-NO" | "nn-NO" | "pl-PL" | "pt-PT" | "ru-RU" | "sr-RS" | "tr-TR" | "vi-VN" | "zh-CN" | "zh-TW" | "any"; + type MobilePhoneLocale = "ar-DZ" | "ar-SA" | "ar-SY" | "cs-CZ" | "de-DE" | "da-DK" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-CA" | "en-ZA" | "en-ZM" | "es-ES" | "fa-IR" | "fi-FI" | "fr-FR" | "hu-HU" | "id-ID" | "it-IT" | "ja-JP" | "ko-KR" | "lt-LT" | "ms-MY" | "nb-NO" | "nn-NO" | "pl-PL" | "pt-PT" | "ru-RU" | "sr-RS" | "tr-TR" | "vi-VN" | "zh-CN" | "zh-TW" | "any"; type PostalCodeLocale = "AT" | "AU" | "BE" | "CA" | "CH" | "CZ" | "DE" | "DK" | "DZ" | "ES" | "FI" | "FR" | "GB" | "GR" | "IL" | "IN" | "IS" | "IT" | "JP" | "KE" | "LI" | "MX" | "NL" | "NO" | "PL" | "PT" | "RO" | "RU" | "SA" | "SE" | "TW" | "US" | "ZA" | "ZM" | "any" interface ValidatorStatic { @@ -110,6 +110,9 @@ declare namespace ValidatorJS { // check if the string is a valid ISO 8601 (https://en.wikipedia.org/wiki/ISO_8601) date. isISO8601(str: string): boolean; + // check if the string is a ISRC (https://en.wikipedia.org/wiki/International_Standard_Recording_Code). + isISRC(str: string): boolean; + // check if the string is in a array of allowed values. isIn(str: string, values: any[]): boolean; @@ -135,9 +138,9 @@ declare namespace ValidatorJS { // check if the string is a mobile phone number, (locale is one of // ['ar-DZ', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-GB', 'en-HK', - // 'en-IN', 'en-NZ', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fi-FI', 'fr-FR', 'hu-HU', - // 'it-IT', 'ja-JP', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ru-RU', 'sr-RS', 'tr-TR', - // 'vi-VN', 'zh-CN', 'zh-TW']). + // 'en-IN', 'en-NZ', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fr-FR', + // 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'ko-KR', lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', + // 'pt-PT', 'ru-RU', 'sr-RS', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-TW']). isMobilePhone(str: string, locale: MobilePhoneLocale): boolean; // check if the string is a valid hex-encoded representation of a MongoDB ObjectId @@ -474,6 +477,11 @@ declare module "validator/lib/isISO8601" { export = isISO8601; } +declare module "validator/lib/isISRC" { + const isISRC: typeof validator.isISRC; + export = isISRC; +} + declare module "validator/lib/isIn" { const isIn: typeof validator.isIn; export = isIn; diff --git a/types/validator/validator-tests.ts b/types/validator/validator-tests.ts index 92acf504c4..76d08c1c6c 100644 --- a/types/validator/validator-tests.ts +++ b/types/validator/validator-tests.ts @@ -34,6 +34,7 @@ import isIPFunc = require('validator/lib/isIP'); import isISBNFunc = require('validator/lib/isISBN'); import isISINFunc = require('validator/lib/isISIN'); import isISO8601Func = require('validator/lib/isISO8601'); +import isISRCFunc = require('validator/lib/isISRC'); import isInFunc = require('validator/lib/isIn'); import isIntFunc = require('validator/lib/isInt'); import isJSONFunc = require('validator/lib/isJSON'); @@ -154,6 +155,9 @@ import whitelistFunc = require('validator/lib/whitelist'); let _isISO8601 = validator.isISO8601; _isISO8601 = isISO8601Func; + let _isISRC = validator.isISRC; + _isISRC = isISRCFunc; + let _isIn = validator.isIn; _isIn = isInFunc; @@ -408,6 +412,8 @@ let any: any; result = validator.isISO8601('sample'); + result = validator.isISRC('sample'); + result = validator.isIn('sample', []); let isIntOptions: ValidatorJS.IsIntOptions; @@ -444,12 +450,15 @@ let any: any; result = validator.isMobilePhone('sample', 'en-ZA'); result = validator.isMobilePhone('sample', 'en-ZM'); result = validator.isMobilePhone('sample', 'es-ES'); + result = validator.isMobilePhone('sample', 'fa-IR'); result = validator.isMobilePhone('sample', 'fi-FI'); result = validator.isMobilePhone('sample', 'fr-FR'); result = validator.isMobilePhone('sample', 'hu-HU'); + result = validator.isMobilePhone('sample', 'id-ID'); result = validator.isMobilePhone('sample', 'it-IT'); result = validator.isMobilePhone('sample', 'ja-JP'); result = validator.isMobilePhone('sample', 'ko-KR'); + result = validator.isMobilePhone('sample', 'lt-LT'); result = validator.isMobilePhone('sample', 'ms-MY'); result = validator.isMobilePhone('sample', 'nb-NO'); result = validator.isMobilePhone('sample', 'nn-NO'); From a948fb3eb7bc6b3605efd87e9d31c3c078989fe3 Mon Sep 17 00:00:00 2001 From: Naoto Yokoyama Date: Tue, 20 Feb 2018 20:57:38 +0900 Subject: [PATCH 03/17] validator (v7.2): update a bunch of locales Locales added in v7.2: - any (https://github.com/chriso/validator.js/pull/663) - en-KE (https://github.com/chriso/validator.js/pull/673) - en-UG, en-RW, en-TZ (https://github.com/chriso/validator.js/pull/676) Missing locales (but added in this commit): - da-DK (https://github.com/chriso/validator.js/pull/601) - uk-UA (https://github.com/chriso/validator.js/pull/585) - en-NG (https://github.com/chriso/validator.js/pull/616) - en-PK (https://github.com/chriso/validator.js/pull/630) - he-IL (https://github.com/chriso/validator.js/pull/610) - ro-RO (https://github.com/chriso/validator.js/pull/627) - zh-HK (https://github.com/chriso/validator.js/pull/622) Non-existent locales: - fr-BE, nl-BE (https://github.com/chriso/validator.js/pull/700) --- types/validator/index.d.ts | 27 ++++++++++++++------------- types/validator/validator-tests.ts | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/types/validator/index.d.ts b/types/validator/index.d.ts index 22fe951788..bfb1e5d4ad 100644 --- a/types/validator/index.d.ts +++ b/types/validator/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for validator.js v7.1 +// Type definitions for validator.js v7.2 // Project: https://github.com/chriso/validator.js // Definitions by: tgfjt // Ilya Mochalov @@ -10,9 +10,9 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace ValidatorJS { - type AlphaLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "nl-NL" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "tr-TR"; - type AlphanumericLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "fr-BE" | "hu-HU" | "nl-BE" | "nl-NL" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "tr-TR"; - type MobilePhoneLocale = "ar-DZ" | "ar-SA" | "ar-SY" | "cs-CZ" | "de-DE" | "da-DK" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-CA" | "en-ZA" | "en-ZM" | "es-ES" | "fa-IR" | "fi-FI" | "fr-FR" | "hu-HU" | "id-ID" | "it-IT" | "ja-JP" | "ko-KR" | "lt-LT" | "ms-MY" | "nb-NO" | "nn-NO" | "pl-PL" | "pt-PT" | "ru-RU" | "sr-RS" | "tr-TR" | "vi-VN" | "zh-CN" | "zh-TW" | "any"; + type AlphaLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "nl-NL" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "tr-TR" | "uk-UA"; + type AlphanumericLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "nl-NL" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "tr-TR" | "uk-UA"; + type MobilePhoneLocale = "ar-DZ" | "ar-SA" | "ar-SY" | "cs-CZ" | "de-DE" | "da-DK" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-KE" | "en-NG" | "en-NZ" | "en-UG" | "en-RW" | "en-TZ" | "en-PK" | "en-US" | "en-CA" | "en-ZA" | "en-ZM" | "es-ES" | "fa-IR" | "fi-FI" | "fr-FR" | "he-IL" | "hu-HU" | "id-ID" | "it-IT" | "ja-JP" | "ko-KR" | "lt-LT" | "ms-MY" | "nb-NO" | "nn-NO" | "pl-PL" | "pt-PT" | "ro-RO" | "ru-RU" | "sr-RS" | "tr-TR" | "vi-VN" | "zh-CN" | "zh-HK" | "zh-TW" | "any"; type PostalCodeLocale = "AT" | "AU" | "BE" | "CA" | "CH" | "CZ" | "DE" | "DK" | "DZ" | "ES" | "FI" | "FR" | "GB" | "GR" | "IL" | "IN" | "IS" | "IT" | "JP" | "KE" | "LI" | "MX" | "NL" | "NO" | "PL" | "PT" | "RO" | "RU" | "SA" | "SE" | "TW" | "US" | "ZA" | "ZM" | "any" interface ValidatorStatic { @@ -32,14 +32,14 @@ declare namespace ValidatorJS { // check if the string contains only letters (a-zA-Z). Locale is one of ['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', // 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', - // 'cs-CZ', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', - // 'nl-NL', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'tr-TR']) and defaults to en-US + // 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', + // 'hu-HU', 'nl-NL', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'tr-TR' 'uk-UA']) and defaults to en-US isAlpha(str: string, locale?: AlphaLocale): boolean; // check if the string contains only letters and numbers. Locale is one of ['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', // 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', - // 'cs-CZ', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', 'hu-HU', - // 'nl-NL', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'tr-TR']) and defaults to en-US + // 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', + // 'hu-HU', 'nl-NL', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'tr-TR', 'uk-UA']) and defaults to en-US isAlphanumeric(str: string, locale?: AlphanumericLocale): boolean; // check if the string contains ASCII chars only. @@ -138,9 +138,10 @@ declare namespace ValidatorJS { // check if the string is a mobile phone number, (locale is one of // ['ar-DZ', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-GB', 'en-HK', - // 'en-IN', 'en-NZ', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fr-FR', - // 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'ko-KR', lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', - // 'pt-PT', 'ru-RU', 'sr-RS', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-TW']). + // 'en-IN', 'en-KE', 'en-NG', 'en-NZ', 'en-UG', 'en-RW', 'en-TZ', 'en-PK', 'en-US', 'en-CA', + // 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', + // 'ja-JP', 'ko-KR', lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', + // 'sr-RS', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']). isMobilePhone(str: string, locale: MobilePhoneLocale): boolean; // check if the string is a valid hex-encoded representation of a MongoDB ObjectId @@ -157,8 +158,8 @@ declare namespace ValidatorJS { isNumeric(str: string): boolean; // check if the string is a postal code, (locale is one of - // [ 'AT', 'AU', 'BE', 'CA', 'CH', 'CZ', 'DE', 'DK', 'DZ', 'ES', 'FI', 'FR', 'GB', 'GR', 'IL', - // 'IN', 'IS', 'IT', 'JP', 'KE', 'LI', 'MX', 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'SA', 'SE', + // [ 'AT', 'AU', 'BE', 'CA', 'CH', 'CZ', 'DE', 'DK', 'DZ', 'ES', 'FI', 'FR', 'GB', 'GR', 'IL', + // 'IN', 'IS', 'IT', 'JP', 'KE', 'LI', 'MX', 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'SA', 'SE', // 'TW', 'US', 'ZA', 'ZM' ]) OR 'any'. If 'any' is used, function will check if any of the // locales match). isPostalCode(str: string, locale: PostalCodeLocale): boolean; diff --git a/types/validator/validator-tests.ts b/types/validator/validator-tests.ts index 76d08c1c6c..b6d44b04bf 100644 --- a/types/validator/validator-tests.ts +++ b/types/validator/validator-tests.ts @@ -293,6 +293,7 @@ let any: any; result = validator.isAlpha('sample', 'ar-TN'); result = validator.isAlpha('sample', 'ar-YE'); result = validator.isAlpha('sample', 'cs-CZ'); + result = validator.isAlpha('sample', 'da-DK'); result = validator.isAlpha('sample', 'de-DE'); result = validator.isAlpha('sample', 'en-AU'); result = validator.isAlpha('sample', 'en-GB'); @@ -313,6 +314,7 @@ let any: any; result = validator.isAlpha('sample', 'sr-RS'); result = validator.isAlpha('sample', 'sr-RS@latin'); result = validator.isAlpha('sample', 'tr-TR'); + result = validator.isAlpha('sample', 'uk-UA'); result = validator.isAlphanumeric('sample', 'ar'); result = validator.isAlphanumeric('sample', 'ar-AE'); @@ -333,6 +335,7 @@ let any: any; result = validator.isAlphanumeric('sample', 'ar-TN'); result = validator.isAlphanumeric('sample', 'ar-YE'); result = validator.isAlphanumeric('sample', 'cs-CZ'); + result = validator.isAlphanumeric('sample', 'da-DK'); result = validator.isAlphanumeric('sample', 'de-DE'); result = validator.isAlphanumeric('sample', 'en-AU'); result = validator.isAlphanumeric('sample', 'en-GB'); @@ -344,9 +347,7 @@ let any: any; result = validator.isAlphanumeric('sample', 'en-ZM'); result = validator.isAlphanumeric('sample', 'es-ES'); result = validator.isAlphanumeric('sample', 'fr-FR'); - result = validator.isAlphanumeric('sample', 'fr-BE'); result = validator.isAlphanumeric('sample', 'hu-HU'); - result = validator.isAlphanumeric('sample', 'nl-BE'); result = validator.isAlphanumeric('sample', 'nl-NL'); result = validator.isAlphanumeric('sample', 'pl-PL'); result = validator.isAlphanumeric('sample', 'pt-BR'); @@ -355,6 +356,7 @@ let any: any; result = validator.isAlphanumeric('sample', 'sr-RS'); result = validator.isAlphanumeric('sample', 'sr-RS@latin'); result = validator.isAlphanumeric('sample', 'tr-TR'); + result = validator.isAlphanumeric('sample', 'uk-UA'); result = validator.isAscii('sample'); @@ -444,7 +446,13 @@ let any: any; result = validator.isMobilePhone('sample', 'en-GB'); result = validator.isMobilePhone('sample', 'en-HK'); result = validator.isMobilePhone('sample', 'en-IN'); + result = validator.isMobilePhone('sample', 'en-KE'); + result = validator.isMobilePhone('sample', 'en-NG'); result = validator.isMobilePhone('sample', 'en-NZ'); + result = validator.isMobilePhone('sample', 'en-UG'); + result = validator.isMobilePhone('sample', 'en-RW'); + result = validator.isMobilePhone('sample', 'en-TZ'); + result = validator.isMobilePhone('sample', 'en-PK'); result = validator.isMobilePhone('sample', 'en-US'); result = validator.isMobilePhone('sample', 'en-CA'); result = validator.isMobilePhone('sample', 'en-ZA'); @@ -453,6 +461,7 @@ let any: any; result = validator.isMobilePhone('sample', 'fa-IR'); result = validator.isMobilePhone('sample', 'fi-FI'); result = validator.isMobilePhone('sample', 'fr-FR'); + result = validator.isMobilePhone('sample', 'he-IL'); result = validator.isMobilePhone('sample', 'hu-HU'); result = validator.isMobilePhone('sample', 'id-ID'); result = validator.isMobilePhone('sample', 'it-IT'); @@ -464,12 +473,15 @@ let any: any; result = validator.isMobilePhone('sample', 'nn-NO'); result = validator.isMobilePhone('sample', 'pl-PL'); result = validator.isMobilePhone('sample', 'pt-PT'); + result = validator.isMobilePhone('sample', 'ro-RO'); result = validator.isMobilePhone('sample', 'ru-RU'); result = validator.isMobilePhone('sample', 'sr-RS'); result = validator.isMobilePhone('sample', 'tr-TR'); result = validator.isMobilePhone('sample', 'vi-VN'); result = validator.isMobilePhone('sample', 'zh-CN'); + result = validator.isMobilePhone('sample', 'zh-HK'); result = validator.isMobilePhone('sample', 'zh-TW'); + result = validator.isMobilePhone('sample', 'any'); result = validator.isMongoId('sample'); From 659358ae4b2a2ac30d58db64bd5b955d1c241804 Mon Sep 17 00:00:00 2001 From: Naoto Yokoyama Date: Tue, 20 Feb 2018 21:23:46 +0900 Subject: [PATCH 04/17] validator (v8.1): add isLatLong() and locales (nb-NO and nn-NO) isPostalCode() has already been added. --- types/validator/index.d.ts | 18 +++++++++++++----- types/validator/validator-tests.ts | 10 ++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/types/validator/index.d.ts b/types/validator/index.d.ts index bfb1e5d4ad..a4b19606b9 100644 --- a/types/validator/index.d.ts +++ b/types/validator/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for validator.js v7.2 +// Type definitions for validator.js v8.1 // Project: https://github.com/chriso/validator.js // Definitions by: tgfjt // Ilya Mochalov @@ -10,8 +10,8 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace ValidatorJS { - type AlphaLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "nl-NL" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "tr-TR" | "uk-UA"; - type AlphanumericLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "nl-NL" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "tr-TR" | "uk-UA"; + type AlphaLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "tr-TR" | "uk-UA"; + type AlphanumericLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "tr-TR" | "uk-UA"; type MobilePhoneLocale = "ar-DZ" | "ar-SA" | "ar-SY" | "cs-CZ" | "de-DE" | "da-DK" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-KE" | "en-NG" | "en-NZ" | "en-UG" | "en-RW" | "en-TZ" | "en-PK" | "en-US" | "en-CA" | "en-ZA" | "en-ZM" | "es-ES" | "fa-IR" | "fi-FI" | "fr-FR" | "he-IL" | "hu-HU" | "id-ID" | "it-IT" | "ja-JP" | "ko-KR" | "lt-LT" | "ms-MY" | "nb-NO" | "nn-NO" | "pl-PL" | "pt-PT" | "ro-RO" | "ru-RU" | "sr-RS" | "tr-TR" | "vi-VN" | "zh-CN" | "zh-HK" | "zh-TW" | "any"; type PostalCodeLocale = "AT" | "AU" | "BE" | "CA" | "CH" | "CZ" | "DE" | "DK" | "DZ" | "ES" | "FI" | "FR" | "GB" | "GR" | "IL" | "IN" | "IS" | "IT" | "JP" | "KE" | "LI" | "MX" | "NL" | "NO" | "PL" | "PT" | "RO" | "RU" | "SA" | "SE" | "TW" | "US" | "ZA" | "ZM" | "any" @@ -33,13 +33,13 @@ declare namespace ValidatorJS { // check if the string contains only letters (a-zA-Z). Locale is one of ['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', // 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', // 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', - // 'hu-HU', 'nl-NL', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'tr-TR' 'uk-UA']) and defaults to en-US + // 'hu-HU', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'tr-TR' 'uk-UA']) and defaults to en-US isAlpha(str: string, locale?: AlphaLocale): boolean; // check if the string contains only letters and numbers. Locale is one of ['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', // 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', // 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', - // 'hu-HU', 'nl-NL', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'tr-TR', 'uk-UA']) and defaults to en-US + // 'hu-HU', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'tr-TR', 'uk-UA']) and defaults to en-US isAlphanumeric(str: string, locale?: AlphanumericLocale): boolean; // check if the string contains ASCII chars only. @@ -122,6 +122,9 @@ declare namespace ValidatorJS { // check if the string is valid JSON (note: uses JSON.parse). isJSON(str: string): boolean; + // check if the string is a valid latitude-longitude coordinate in the format lat,long or lat, long. + isLatLong(str: string): boolean; + // check if the string's length falls in a range. // Note: this function takes into account surrogate pairs. isLength(str: string, options: IsLengthOptions): boolean; @@ -498,6 +501,11 @@ declare module "validator/lib/isJSON" { export = isJSON; } +declare module "validator/lib/isLatLong" { + const isLatLong: typeof validator.isLatLong; + export = isLatLong; +} + declare module "validator/lib/isLength" { const isLength: typeof validator.isLength; export = isLength; diff --git a/types/validator/validator-tests.ts b/types/validator/validator-tests.ts index b6d44b04bf..2be484cf0a 100644 --- a/types/validator/validator-tests.ts +++ b/types/validator/validator-tests.ts @@ -38,6 +38,7 @@ import isISRCFunc = require('validator/lib/isISRC'); import isInFunc = require('validator/lib/isIn'); import isIntFunc = require('validator/lib/isInt'); import isJSONFunc = require('validator/lib/isJSON'); +import isLatLongFunc = require('validator/lib/isLatLong'); import isLengthFunc = require('validator/lib/isLength'); import isLowercaseFunc = require('validator/lib/isLowercase'); import isMACAddressFunc = require('validator/lib/isMACAddress'); @@ -167,6 +168,9 @@ import whitelistFunc = require('validator/lib/whitelist'); let _isJSON = validator.isJSON; _isJSON = isJSONFunc; + let _isLatLong = validator.isLatLong; + _isLatLong = isLatLongFunc; + let _isLength = validator.isLength; _isLength = isLengthFunc; @@ -306,7 +310,9 @@ let any: any; result = validator.isAlpha('sample', 'es-ES'); result = validator.isAlpha('sample', 'fr-FR'); result = validator.isAlpha('sample', 'hu-HU'); + result = validator.isAlpha('sample', 'nb-NO'); result = validator.isAlpha('sample', 'nl-NL'); + result = validator.isAlpha('sample', 'nn-NO'); result = validator.isAlpha('sample', 'pl-PL'); result = validator.isAlpha('sample', 'pt-BR'); result = validator.isAlpha('sample', 'pt-PT'); @@ -348,7 +354,9 @@ let any: any; result = validator.isAlphanumeric('sample', 'es-ES'); result = validator.isAlphanumeric('sample', 'fr-FR'); result = validator.isAlphanumeric('sample', 'hu-HU'); + result = validator.isAlphanumeric('sample', 'nb-NO'); result = validator.isAlphanumeric('sample', 'nl-NL'); + result = validator.isAlphanumeric('sample', 'nn-NO'); result = validator.isAlphanumeric('sample', 'pl-PL'); result = validator.isAlphanumeric('sample', 'pt-BR'); result = validator.isAlphanumeric('sample', 'pt-PT'); @@ -424,6 +432,8 @@ let any: any; result = validator.isJSON('sample'); + result = validator.isLatLong('sample'); + let isLengthOptions: ValidatorJS.IsLengthOptions; result = validator.isLength('sample', isLengthOptions); result = validator.isLength('sample', 3); From 9318ba8c9bd8a2a4e285c966a05b02a75184f4c9 Mon Sep 17 00:00:00 2001 From: Naoto Yokoyama Date: Tue, 20 Feb 2018 21:51:40 +0900 Subject: [PATCH 05/17] validator (v8.2): add isHash(), isCurrency() options, and locales Added isCurrency() options are: - allow_decimal - require_decimal - digits_after_decimal Added locales are: - it-IT (https://github.com/chriso/validator.js/pull/700) - sv-SE (https://github.com/chriso/validator.js/pull/714) - ar-AE, ar-EG (https://github.com/chriso/validator.js/pull/718) - ar-JO (https://github.com/chriso/validator.js/pull/701) - sk-SK (https://github.com/chriso/validator.js/pull/715) --- types/validator/index.d.ts | 38 +++++++++++++++++++++--------- types/validator/validator-tests.ts | 26 ++++++++++++++++++++ 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/types/validator/index.d.ts b/types/validator/index.d.ts index a4b19606b9..6588570a1a 100644 --- a/types/validator/index.d.ts +++ b/types/validator/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for validator.js v8.1 +// Type definitions for validator.js v8.2 // Project: https://github.com/chriso/validator.js // Definitions by: tgfjt // Ilya Mochalov @@ -10,10 +10,11 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace ValidatorJS { - type AlphaLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "tr-TR" | "uk-UA"; - type AlphanumericLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "tr-TR" | "uk-UA"; - type MobilePhoneLocale = "ar-DZ" | "ar-SA" | "ar-SY" | "cs-CZ" | "de-DE" | "da-DK" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-KE" | "en-NG" | "en-NZ" | "en-UG" | "en-RW" | "en-TZ" | "en-PK" | "en-US" | "en-CA" | "en-ZA" | "en-ZM" | "es-ES" | "fa-IR" | "fi-FI" | "fr-FR" | "he-IL" | "hu-HU" | "id-ID" | "it-IT" | "ja-JP" | "ko-KR" | "lt-LT" | "ms-MY" | "nb-NO" | "nn-NO" | "pl-PL" | "pt-PT" | "ro-RO" | "ru-RU" | "sr-RS" | "tr-TR" | "vi-VN" | "zh-CN" | "zh-HK" | "zh-TW" | "any"; + type AlphaLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; + type AlphanumericLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; + type MobilePhoneLocale = "ar-AE" | "ar-DZ" | "ar-EG" | "ar-JO" | "ar-SA" | "ar-SY" | "cs-CZ" | "de-DE" | "da-DK" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-KE" | "en-NG" | "en-NZ" | "en-UG" | "en-RW" | "en-TZ" | "en-PK" | "en-US" | "en-CA" | "en-ZA" | "en-ZM" | "es-ES" | "fa-IR" | "fi-FI" | "fr-FR" | "he-IL" | "hu-HU" | "id-ID" | "it-IT" | "ja-JP" | "ko-KR" | "lt-LT" | "ms-MY" | "nb-NO" | "nn-NO" | "pl-PL" | "pt-PT" | "ro-RO" | "ru-RU" | "sk-SK" | "sr-RS" | "tr-TR" | "vi-VN" | "zh-CN" | "zh-HK" | "zh-TW" | "any"; type PostalCodeLocale = "AT" | "AU" | "BE" | "CA" | "CH" | "CZ" | "DE" | "DK" | "DZ" | "ES" | "FI" | "FR" | "GB" | "GR" | "IL" | "IN" | "IS" | "IT" | "JP" | "KE" | "LI" | "MX" | "NL" | "NO" | "PL" | "PT" | "RO" | "RU" | "SA" | "SE" | "TW" | "US" | "ZA" | "ZM" | "any" + type HashAlgorithm = "md4" | "md5" | "sha1" | "sha256" | "sha384" | "sha512" | "ripemd128" | "ripemd160" | "tiger128" | "tiger160" | "tiger192" | "crc32" | "crc32b"; interface ValidatorStatic { @@ -33,13 +34,15 @@ declare namespace ValidatorJS { // check if the string contains only letters (a-zA-Z). Locale is one of ['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', // 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', // 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', - // 'hu-HU', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'tr-TR' 'uk-UA']) and defaults to en-US + // 'hu-HU', 'it-IT' 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'sv-SE', + // 'tr-TR', 'uk-UA']) and defaults to en-US isAlpha(str: string, locale?: AlphaLocale): boolean; // check if the string contains only letters and numbers. Locale is one of ['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', // 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', // 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', - // 'hu-HU', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'tr-TR', 'uk-UA']) and defaults to en-US + // 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'sv-SE', + // 'tr-TR', 'uk-UA']) and defaults to en-US isAlphanumeric(str: string, locale?: AlphanumericLocale): boolean; // check if the string contains ASCII chars only. @@ -91,6 +94,11 @@ declare namespace ValidatorJS { // check if the string contains any half-width chars. isHalfWidth(str: string): boolean; + // check if the string is a hash of type algorithm. + // Algorithm is one of ['md4', 'md5', 'sha1', 'sha256', 'sha384', 'sha512', 'ripemd128', 'ripemd160', 'tiger128', + // 'tiger160', 'tiger192', 'crc32', 'crc32b'] + isHash(str: string, algorithm: HashAlgorithm): boolean; + // check if the string is a hexadecimal color. isHexColor(str: string): boolean; @@ -140,11 +148,11 @@ declare namespace ValidatorJS { isMD5(str: string): boolean; // check if the string is a mobile phone number, (locale is one of - // ['ar-DZ', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-GB', 'en-HK', - // 'en-IN', 'en-KE', 'en-NG', 'en-NZ', 'en-UG', 'en-RW', 'en-TZ', 'en-PK', 'en-US', 'en-CA', - // 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', - // 'ja-JP', 'ko-KR', lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', - // 'sr-RS', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']). + // ['ar-AE', ar-DZ', 'ar-EG', 'ar-JO', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', + // 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-KE', 'en-NG', 'en-NZ', 'en-UG', 'en-RW', 'en-TZ', + // 'en-PK', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', + // 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'ko-KR', lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', + // 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', 'sr-RS', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']). isMobilePhone(str: string, locale: MobilePhoneLocale): boolean; // check if the string is a valid hex-encoded representation of a MongoDB ObjectId @@ -267,6 +275,9 @@ declare namespace ValidatorJS { allow_negative_sign_placeholder?: boolean; thousands_separator?: string; decimal_separator?: string; + allow_decimal?: boolean; + require_decimal?: boolean; + digits_after_decimal?: number[]; allow_space_after_digits?: boolean; } @@ -451,6 +462,11 @@ declare module "validator/lib/isHalfWidth" { export = isHalfWidth; } +declare module "validator/lib/isHash" { + const isHash: typeof validator.isHash; + export = isHash; +} + declare module "validator/lib/isHexColor" { const isHexColor: typeof validator.isHexColor; export = isHexColor; diff --git a/types/validator/validator-tests.ts b/types/validator/validator-tests.ts index 2be484cf0a..bf3d74cb78 100644 --- a/types/validator/validator-tests.ts +++ b/types/validator/validator-tests.ts @@ -28,6 +28,7 @@ import isFQDNFunc = require('validator/lib/isFQDN'); import isFloatFunc = require('validator/lib/isFloat'); import isFullWidthFunc = require('validator/lib/isFullWidth'); import isHalfWidthFunc = require('validator/lib/isHalfWidth'); +import isHashFunc = require('validator/lib/isHash'); import isHexColorFunc = require('validator/lib/isHexColor'); import isHexadecimalFunc = require('validator/lib/isHexadecimal'); import isIPFunc = require('validator/lib/isIP'); @@ -138,6 +139,9 @@ import whitelistFunc = require('validator/lib/whitelist'); let _isHalfWidth = validator.isHalfWidth; _isHalfWidth = isHalfWidthFunc; + let _isHash = validator.isHash; + _isHash = isHashFunc; + let _isHexColor = validator.isHexColor; _isHexColor = isHexColorFunc; @@ -310,6 +314,7 @@ let any: any; result = validator.isAlpha('sample', 'es-ES'); result = validator.isAlpha('sample', 'fr-FR'); result = validator.isAlpha('sample', 'hu-HU'); + result = validator.isAlpha('sample', 'it-IT'); result = validator.isAlpha('sample', 'nb-NO'); result = validator.isAlpha('sample', 'nl-NL'); result = validator.isAlpha('sample', 'nn-NO'); @@ -319,6 +324,7 @@ let any: any; result = validator.isAlpha('sample', 'ru-RU'); result = validator.isAlpha('sample', 'sr-RS'); result = validator.isAlpha('sample', 'sr-RS@latin'); + result = validator.isAlpha('sample', 'sv-SE'); result = validator.isAlpha('sample', 'tr-TR'); result = validator.isAlpha('sample', 'uk-UA'); @@ -354,6 +360,7 @@ let any: any; result = validator.isAlphanumeric('sample', 'es-ES'); result = validator.isAlphanumeric('sample', 'fr-FR'); result = validator.isAlphanumeric('sample', 'hu-HU'); + result = validator.isAlphanumeric('sample', 'it-IT'); result = validator.isAlphanumeric('sample', 'nb-NO'); result = validator.isAlphanumeric('sample', 'nl-NL'); result = validator.isAlphanumeric('sample', 'nn-NO'); @@ -363,6 +370,7 @@ let any: any; result = validator.isAlphanumeric('sample', 'ru-RU'); result = validator.isAlphanumeric('sample', 'sr-RS'); result = validator.isAlphanumeric('sample', 'sr-RS@latin'); + result = validator.isAlphanumeric('sample', 'sv-SE'); result = validator.isAlphanumeric('sample', 'tr-TR'); result = validator.isAlphanumeric('sample', 'uk-UA'); @@ -408,6 +416,20 @@ let any: any; result = validator.isHalfWidth('sample'); + result = validator.isHash('sample', 'md4'); + result = validator.isHash('sample', 'md5'); + result = validator.isHash('sample', 'sha1'); + result = validator.isHash('sample', 'sha256'); + result = validator.isHash('sample', 'sha384'); + result = validator.isHash('sample', 'sha512'); + result = validator.isHash('sample', 'ripemd128'); + result = validator.isHash('sample', 'ripemd160'); + result = validator.isHash('sample', 'tiger128'); + result = validator.isHash('sample', 'tiger160'); + result = validator.isHash('sample', 'tiger192'); + result = validator.isHash('sample', 'crc32'); + result = validator.isHash('sample', 'crc32b'); + result = validator.isHexColor('sample'); result = validator.isHexadecimal('sample'); @@ -445,7 +467,10 @@ let any: any; result = validator.isMD5('sample'); + result = validator.isMobilePhone('sample', 'ar-AE'); result = validator.isMobilePhone('sample', 'ar-DZ'); + result = validator.isMobilePhone('sample', 'ar-EG'); + result = validator.isMobilePhone('sample', 'ar-JO'); result = validator.isMobilePhone('sample', 'ar-SA'); result = validator.isMobilePhone('sample', 'ar-SY'); result = validator.isMobilePhone('sample', 'cs-CZ'); @@ -486,6 +511,7 @@ let any: any; result = validator.isMobilePhone('sample', 'ro-RO'); result = validator.isMobilePhone('sample', 'ru-RU'); result = validator.isMobilePhone('sample', 'sr-RS'); + result = validator.isMobilePhone('sample', 'sk-SK'); result = validator.isMobilePhone('sample', 'tr-TR'); result = validator.isMobilePhone('sample', 'vi-VN'); result = validator.isMobilePhone('sample', 'zh-CN'); From 0b926af02dc124f610d5ff592ad47aaec1320eaa Mon Sep 17 00:00:00 2001 From: Naoto Yokoyama Date: Tue, 20 Feb 2018 22:11:22 +0900 Subject: [PATCH 06/17] validator (v9.0): add isPort(), some options, and locales Added option for isFloat(): - locale Added options for isDecimal(): - locale - force_decimal - decimal_digits Added locales: - uk-UA (https://github.com/chriso/validator.js/pull/731) --- types/validator/index.d.ts | 27 +++++++++++++++++++++++---- types/validator/validator-tests.ts | 9 +++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/types/validator/index.d.ts b/types/validator/index.d.ts index 6588570a1a..c4dd7a59c3 100644 --- a/types/validator/index.d.ts +++ b/types/validator/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for validator.js v8.2 +// Type definitions for validator.js v9.0 // Project: https://github.com/chriso/validator.js // Definitions by: tgfjt // Ilya Mochalov @@ -12,7 +12,9 @@ declare namespace ValidatorJS { type AlphaLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; type AlphanumericLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; - type MobilePhoneLocale = "ar-AE" | "ar-DZ" | "ar-EG" | "ar-JO" | "ar-SA" | "ar-SY" | "cs-CZ" | "de-DE" | "da-DK" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-KE" | "en-NG" | "en-NZ" | "en-UG" | "en-RW" | "en-TZ" | "en-PK" | "en-US" | "en-CA" | "en-ZA" | "en-ZM" | "es-ES" | "fa-IR" | "fi-FI" | "fr-FR" | "he-IL" | "hu-HU" | "id-ID" | "it-IT" | "ja-JP" | "ko-KR" | "lt-LT" | "ms-MY" | "nb-NO" | "nn-NO" | "pl-PL" | "pt-PT" | "ro-RO" | "ru-RU" | "sk-SK" | "sr-RS" | "tr-TR" | "vi-VN" | "zh-CN" | "zh-HK" | "zh-TW" | "any"; + type DecimalLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; + type FloatLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; + type MobilePhoneLocale = "ar-AE" | "ar-DZ" | "ar-EG" | "ar-JO" | "ar-SA" | "ar-SY" | "cs-CZ" | "de-DE" | "da-DK" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-KE" | "en-NG" | "en-NZ" | "en-UG" | "en-RW" | "en-TZ" | "en-PK" | "en-US" | "en-CA" | "en-ZA" | "en-ZM" | "es-ES" | "fa-IR" | "fi-FI" | "fr-FR" | "he-IL" | "hu-HU" | "id-ID" | "it-IT" | "ja-JP" | "ko-KR" | "lt-LT" | "ms-MY" | "nb-NO" | "nn-NO" | "pl-PL" | "pt-PT" | "ro-RO" | "ru-RU" | "sk-SK" | "sr-RS" | "tr-TR" | "uk-UA" | "vi-VN" | "zh-CN" | "zh-HK" | "zh-TW" | "any"; type PostalCodeLocale = "AT" | "AU" | "BE" | "CA" | "CH" | "CZ" | "DE" | "DK" | "DZ" | "ES" | "FI" | "FR" | "GB" | "GR" | "IL" | "IN" | "IS" | "IT" | "JP" | "KE" | "LI" | "MX" | "NL" | "NO" | "PL" | "PT" | "RO" | "RU" | "SA" | "SE" | "TW" | "US" | "ZA" | "ZM" | "any" type HashAlgorithm = "md4" | "md5" | "sha1" | "sha256" | "sha384" | "sha512" | "ripemd128" | "ripemd160" | "tiger128" | "tiger160" | "tiger192" | "crc32" | "crc32b"; @@ -71,7 +73,7 @@ declare namespace ValidatorJS { isDataURI(str: string): boolean; // check if the string represents a decimal number, such as 0.1, .3, 1.1, 1.00003, 4.0, etc. - isDecimal(str: string): boolean; + isDecimal(str: string, options?: IsDecimalOptions): boolean; // check if the string is a number that's divisible by another. isDivisibleBy(str: string, number: number): boolean; @@ -152,7 +154,8 @@ declare namespace ValidatorJS { // 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-KE', 'en-NG', 'en-NZ', 'en-UG', 'en-RW', 'en-TZ', // 'en-PK', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', // 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'ko-KR', lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', - // 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', 'sr-RS', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']). + // 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', 'sr-RS', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-HK', + // 'zh-TW']). isMobilePhone(str: string, locale: MobilePhoneLocale): boolean; // check if the string is a valid hex-encoded representation of a MongoDB ObjectId @@ -168,6 +171,9 @@ declare namespace ValidatorJS { // check if the string contains only numbers. isNumeric(str: string): boolean; + // check if the string is a valid port number. + isPort(str: string): boolean; + // check if the string is a postal code, (locale is one of // [ 'AT', 'AU', 'BE', 'CA', 'CH', 'CZ', 'DE', 'DK', 'DZ', 'ES', 'FI', 'FR', 'GB', 'GR', 'IL', // 'IN', 'IS', 'IT', 'JP', 'KE', 'LI', 'MX', 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'SA', 'SE', @@ -281,6 +287,13 @@ declare namespace ValidatorJS { allow_space_after_digits?: boolean; } + // options for isDecimal + interface IsDecimalOptions { + force_decimal?: boolean; + decimal_digits?: string; + locale?: DecimalLocale; + } + // options for isEmail interface IsEmailOptions { allow_display_name?: boolean; @@ -299,6 +312,7 @@ declare namespace ValidatorJS { interface IsFloatOptions { min?: number; max?: number; + locale?: FloatLocale; } // options for IsInt @@ -572,6 +586,11 @@ declare module "validator/lib/isNumeric" { export = isNumeric; } +declare module "validator/lib/isPort" { + const isPort: typeof validator.isPort; + export = isPort; +} + declare module "validator/lib/isSurrogatePair" { const isSurrogatePair: typeof validator.isSurrogatePair; export = isSurrogatePair; diff --git a/types/validator/validator-tests.ts b/types/validator/validator-tests.ts index bf3d74cb78..02d0510be2 100644 --- a/types/validator/validator-tests.ts +++ b/types/validator/validator-tests.ts @@ -49,6 +49,7 @@ import isMongoIdFunc = require('validator/lib/isMongoId'); import isMultibyteFunc = require('validator/lib/isMultibyte'); import isNullFunc = require('validator/lib/isNull'); import isNumericFunc = require('validator/lib/isNumeric'); +import isPortFunc = require('validator/lib/isPort'); import isPostalCodeFunc = require('validator/lib/isPostalCode'); import isSurrogatePairFunc = require('validator/lib/isSurrogatePair'); import isURLFunc = require('validator/lib/isURL'); @@ -202,6 +203,9 @@ import whitelistFunc = require('validator/lib/whitelist'); let _isNumeric = validator.isNumeric; _isNumeric = isNumericFunc; + let _isPort = validator.isPort; + _isPort = isPortFunc; + let _isPostalCode = validator.isPostalCode; _isPostalCode = isPostalCodeFunc; @@ -396,7 +400,9 @@ let any: any; result = validator.isDataURI('sample'); + let isDecimalOptions: ValidatorJS.IsDecimalOptions; result = validator.isDecimal('sample'); + result = validator.isDecimal('sample', isDecimalOptions); result = validator.isDivisibleBy('sample', 2); @@ -513,6 +519,7 @@ let any: any; result = validator.isMobilePhone('sample', 'sr-RS'); result = validator.isMobilePhone('sample', 'sk-SK'); result = validator.isMobilePhone('sample', 'tr-TR'); + result = validator.isMobilePhone('sample', 'uk-UA'); result = validator.isMobilePhone('sample', 'vi-VN'); result = validator.isMobilePhone('sample', 'zh-CN'); result = validator.isMobilePhone('sample', 'zh-HK'); @@ -527,6 +534,8 @@ let any: any; result = validator.isNumeric('sample'); + result = validator.isPort('sample'); + result = validator.isPostalCode('sample', 'AT'); result = validator.isPostalCode('sample', 'AU'); result = validator.isPostalCode('sample', 'BE'); From 54ee80024f2a04cd56c82601c25e88f77c7f4823 Mon Sep 17 00:00:00 2001 From: Naoto Yokoyama Date: Tue, 20 Feb 2018 22:21:59 +0900 Subject: [PATCH 07/17] validator (v9.1): add isISO31661Alpha2() and some locales Added locales are: - fo-FO, kl-GL (https://github.com/chriso/validator.js/pull/735) --- types/validator/index.d.ts | 21 +++++++++++++++------ types/validator/validator-tests.ts | 8 ++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/types/validator/index.d.ts b/types/validator/index.d.ts index c4dd7a59c3..4b06aa9bf8 100644 --- a/types/validator/index.d.ts +++ b/types/validator/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for validator.js v9.0 +// Type definitions for validator.js v9.1 // Project: https://github.com/chriso/validator.js // Definitions by: tgfjt // Ilya Mochalov @@ -14,7 +14,7 @@ declare namespace ValidatorJS { type AlphanumericLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; type DecimalLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; type FloatLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; - type MobilePhoneLocale = "ar-AE" | "ar-DZ" | "ar-EG" | "ar-JO" | "ar-SA" | "ar-SY" | "cs-CZ" | "de-DE" | "da-DK" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-KE" | "en-NG" | "en-NZ" | "en-UG" | "en-RW" | "en-TZ" | "en-PK" | "en-US" | "en-CA" | "en-ZA" | "en-ZM" | "es-ES" | "fa-IR" | "fi-FI" | "fr-FR" | "he-IL" | "hu-HU" | "id-ID" | "it-IT" | "ja-JP" | "ko-KR" | "lt-LT" | "ms-MY" | "nb-NO" | "nn-NO" | "pl-PL" | "pt-PT" | "ro-RO" | "ru-RU" | "sk-SK" | "sr-RS" | "tr-TR" | "uk-UA" | "vi-VN" | "zh-CN" | "zh-HK" | "zh-TW" | "any"; + type MobilePhoneLocale = "ar-AE" | "ar-DZ" | "ar-EG" | "ar-JO" | "ar-SA" | "ar-SY" | "cs-CZ" | "de-DE" | "da-DK" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-KE" | "en-NG" | "en-NZ" | "en-UG" | "en-RW" | "en-TZ" | "en-PK" | "en-US" | "en-CA" | "en-ZA" | "en-ZM" | "es-ES" | "fa-IR" | "fi-FI" | "fo-FO" | "fr-FR" | "he-IL" | "hu-HU" | "id-ID" | "it-IT" | "ja-JP" | "kl-GL" | "ko-KR" | "lt-LT" | "ms-MY" | "nb-NO" | "nn-NO" | "pl-PL" | "pt-PT" | "ro-RO" | "ru-RU" | "sk-SK" | "sr-RS" | "tr-TR" | "uk-UA" | "vi-VN" | "zh-CN" | "zh-HK" | "zh-TW" | "any"; type PostalCodeLocale = "AT" | "AU" | "BE" | "CA" | "CH" | "CZ" | "DE" | "DK" | "DZ" | "ES" | "FI" | "FR" | "GB" | "GR" | "IL" | "IN" | "IS" | "IT" | "JP" | "KE" | "LI" | "MX" | "NL" | "NO" | "PL" | "PT" | "RO" | "RU" | "SA" | "SE" | "TW" | "US" | "ZA" | "ZM" | "any" type HashAlgorithm = "md4" | "md5" | "sha1" | "sha256" | "sha384" | "sha512" | "ripemd128" | "ripemd160" | "tiger128" | "tiger160" | "tiger192" | "crc32" | "crc32b"; @@ -120,6 +120,10 @@ declare namespace ValidatorJS { // check if the string is a valid ISO 8601 (https://en.wikipedia.org/wiki/ISO_8601) date. isISO8601(str: string): boolean; + // 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. + isISO31661Alpha2(str: string): boolean; + // check if the string is a ISRC (https://en.wikipedia.org/wiki/International_Standard_Recording_Code). isISRC(str: string): boolean; @@ -152,10 +156,10 @@ declare namespace ValidatorJS { // check if the string is a mobile phone number, (locale is one of // ['ar-AE', ar-DZ', 'ar-EG', 'ar-JO', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', // 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-KE', 'en-NG', 'en-NZ', 'en-UG', 'en-RW', 'en-TZ', - // 'en-PK', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', - // 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'ko-KR', lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', - // 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', 'sr-RS', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-HK', - // 'zh-TW']). + // 'en-PK', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fo-FO', 'fr-FR', + // 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'kl-GL', 'ko-KR', lt-LT', 'ms-MY', 'nb-NO', + // 'nn-NO', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', 'sr-RS', 'tr-TR', 'uk-UA', 'vi-VN', + // 'zh-CN', 'zh-HK', 'zh-TW']). isMobilePhone(str: string, locale: MobilePhoneLocale): boolean; // check if the string is a valid hex-encoded representation of a MongoDB ObjectId @@ -511,6 +515,11 @@ declare module "validator/lib/isISO8601" { export = isISO8601; } +declare module "validator/lib/isISO31661Alpha2" { + const isISO31661Alpha2: typeof validator.isISO31661Alpha2; + export = isISO31661Alpha2; +} + declare module "validator/lib/isISRC" { const isISRC: typeof validator.isISRC; export = isISRC; diff --git a/types/validator/validator-tests.ts b/types/validator/validator-tests.ts index 02d0510be2..bcc7418b6f 100644 --- a/types/validator/validator-tests.ts +++ b/types/validator/validator-tests.ts @@ -35,6 +35,7 @@ import isIPFunc = require('validator/lib/isIP'); import isISBNFunc = require('validator/lib/isISBN'); import isISINFunc = require('validator/lib/isISIN'); import isISO8601Func = require('validator/lib/isISO8601'); +import isISO31661Alpha2Func = require('validator/lib/isISO31661Alpha2'); import isISRCFunc = require('validator/lib/isISRC'); import isInFunc = require('validator/lib/isIn'); import isIntFunc = require('validator/lib/isInt'); @@ -161,6 +162,9 @@ import whitelistFunc = require('validator/lib/whitelist'); let _isISO8601 = validator.isISO8601; _isISO8601 = isISO8601Func; + let _isISO31661Alpha2 = validator.isISO31661Alpha2; + _isISO31661Alpha2 = isISO31661Alpha2Func; + let _isISRC = validator.isISRC; _isISRC = isISRCFunc; @@ -450,6 +454,8 @@ let any: any; result = validator.isISO8601('sample'); + result = validator.isISO31661Alpha2('sample'); + result = validator.isISRC('sample'); result = validator.isIn('sample', []); @@ -501,12 +507,14 @@ let any: any; result = validator.isMobilePhone('sample', 'es-ES'); result = validator.isMobilePhone('sample', 'fa-IR'); result = validator.isMobilePhone('sample', 'fi-FI'); + result = validator.isMobilePhone('sample', 'fo-FO'); result = validator.isMobilePhone('sample', 'fr-FR'); result = validator.isMobilePhone('sample', 'he-IL'); result = validator.isMobilePhone('sample', 'hu-HU'); result = validator.isMobilePhone('sample', 'id-ID'); result = validator.isMobilePhone('sample', 'it-IT'); result = validator.isMobilePhone('sample', 'ja-JP'); + result = validator.isMobilePhone('sample', 'kl-GL'); result = validator.isMobilePhone('sample', 'ko-KR'); result = validator.isMobilePhone('sample', 'lt-LT'); result = validator.isMobilePhone('sample', 'ms-MY'); From 282306be55de77880feb515f56185b5ed88affb9 Mon Sep 17 00:00:00 2001 From: Naoto Yokoyama Date: Tue, 20 Feb 2018 22:33:42 +0900 Subject: [PATCH 08/17] validator (v9.2): add isMimeType() and locales (el-GR and en-SG) --- types/validator/index.d.ts | 38 ++++++++++++++++++------------ types/validator/validator-tests.ts | 9 +++++++ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/types/validator/index.d.ts b/types/validator/index.d.ts index 4b06aa9bf8..5976ce7982 100644 --- a/types/validator/index.d.ts +++ b/types/validator/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for validator.js v9.1 +// Type definitions for validator.js v9.2 // Project: https://github.com/chriso/validator.js // Definitions by: tgfjt // Ilya Mochalov @@ -10,11 +10,11 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace ValidatorJS { - type AlphaLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; - type AlphanumericLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; + type AlphaLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; + type AlphanumericLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; type DecimalLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; type FloatLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; - type MobilePhoneLocale = "ar-AE" | "ar-DZ" | "ar-EG" | "ar-JO" | "ar-SA" | "ar-SY" | "cs-CZ" | "de-DE" | "da-DK" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-KE" | "en-NG" | "en-NZ" | "en-UG" | "en-RW" | "en-TZ" | "en-PK" | "en-US" | "en-CA" | "en-ZA" | "en-ZM" | "es-ES" | "fa-IR" | "fi-FI" | "fo-FO" | "fr-FR" | "he-IL" | "hu-HU" | "id-ID" | "it-IT" | "ja-JP" | "kl-GL" | "ko-KR" | "lt-LT" | "ms-MY" | "nb-NO" | "nn-NO" | "pl-PL" | "pt-PT" | "ro-RO" | "ru-RU" | "sk-SK" | "sr-RS" | "tr-TR" | "uk-UA" | "vi-VN" | "zh-CN" | "zh-HK" | "zh-TW" | "any"; + type MobilePhoneLocale = "ar-AE" | "ar-DZ" | "ar-EG" | "ar-JO" | "ar-SA" | "ar-SY" | "cs-CZ" | "de-DE" | "da-DK" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-KE" | "en-NG" | "en-NZ" | "en-UG" | "en-RW" | "en-SG" | "en-TZ" | "en-PK" | "en-US" | "en-CA" | "en-ZA" | "en-ZM" | "es-ES" | "fa-IR" | "fi-FI" | "fo-FO" | "fr-FR" | "he-IL" | "hu-HU" | "id-ID" | "it-IT" | "ja-JP" | "kl-GL" | "ko-KR" | "lt-LT" | "ms-MY" | "nb-NO" | "nn-NO" | "pl-PL" | "pt-PT" | "ro-RO" | "ru-RU" | "sk-SK" | "sr-RS" | "tr-TR" | "uk-UA" | "vi-VN" | "zh-CN" | "zh-HK" | "zh-TW" | "any"; type PostalCodeLocale = "AT" | "AU" | "BE" | "CA" | "CH" | "CZ" | "DE" | "DK" | "DZ" | "ES" | "FI" | "FR" | "GB" | "GR" | "IL" | "IN" | "IS" | "IT" | "JP" | "KE" | "LI" | "MX" | "NL" | "NO" | "PL" | "PT" | "RO" | "RU" | "SA" | "SE" | "TW" | "US" | "ZA" | "ZM" | "any" type HashAlgorithm = "md4" | "md5" | "sha1" | "sha256" | "sha384" | "sha512" | "ripemd128" | "ripemd160" | "tiger128" | "tiger160" | "tiger192" | "crc32" | "crc32b"; @@ -35,16 +35,16 @@ declare namespace ValidatorJS { // check if the string contains only letters (a-zA-Z). Locale is one of ['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', // 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', - // 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', - // 'hu-HU', 'it-IT' 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'sv-SE', - // 'tr-TR', 'uk-UA']) and defaults to en-US + // 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', + // 'fr-FR', 'hu-HU', 'it-IT' 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', + // 'sv-SE', 'tr-TR', 'uk-UA']) and defaults to en-US isAlpha(str: string, locale?: AlphaLocale): boolean; // check if the string contains only letters and numbers. Locale is one of ['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', // 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', - // 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fr-FR', - // 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', 'sv-SE', - // 'tr-TR', 'uk-UA']) and defaults to en-US + // 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', + // 'fr-FR', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', + // 'sv-SE', 'tr-TR', 'uk-UA']) and defaults to en-US isAlphanumeric(str: string, locale?: AlphanumericLocale): boolean; // check if the string contains ASCII chars only. @@ -153,13 +153,16 @@ declare namespace ValidatorJS { // check if the string is a MD5 hash. isMD5(str: string): boolean; + // check if the string matches to a valid MIME type (https://en.wikipedia.org/wiki/Media_type) format + isMimeType(str: string): boolean; + // check if the string is a mobile phone number, (locale is one of // ['ar-AE', ar-DZ', 'ar-EG', 'ar-JO', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', - // 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-KE', 'en-NG', 'en-NZ', 'en-UG', 'en-RW', 'en-TZ', - // 'en-PK', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fo-FO', 'fr-FR', - // 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'kl-GL', 'ko-KR', lt-LT', 'ms-MY', 'nb-NO', - // 'nn-NO', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', 'sr-RS', 'tr-TR', 'uk-UA', 'vi-VN', - // 'zh-CN', 'zh-HK', 'zh-TW']). + // 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-KE', 'en-NG', 'en-NZ', 'en-UG', 'en-RW', 'en-SG', + // 'en-TZ', 'en-PK', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fo-FO', + // 'fr-FR', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'kl-GL', 'ko-KR', lt-LT', 'ms-MY', + // 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', 'sr-RS', 'tr-TR', 'uk-UA', + // 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']). isMobilePhone(str: string, locale: MobilePhoneLocale): boolean; // check if the string is a valid hex-encoded representation of a MongoDB ObjectId @@ -565,6 +568,11 @@ declare module "validator/lib/isMD5" { export = isMD5; } +declare module "validator/lib/isMimeType" { + const isMimeType: typeof validator.isMimeType; + export = isMimeType; +} + declare module "validator/lib/isMobilePhone" { const isMobilePhone: typeof validator.isMobilePhone; export = isMobilePhone; diff --git a/types/validator/validator-tests.ts b/types/validator/validator-tests.ts index bcc7418b6f..4709453e14 100644 --- a/types/validator/validator-tests.ts +++ b/types/validator/validator-tests.ts @@ -45,6 +45,7 @@ import isLengthFunc = require('validator/lib/isLength'); import isLowercaseFunc = require('validator/lib/isLowercase'); import isMACAddressFunc = require('validator/lib/isMACAddress'); import isMD5Func = require('validator/lib/isMD5'); +import isMimeTypeFunc = require('validator/lib/isMimeType'); import isMobilePhoneFunc = require('validator/lib/isMobilePhone'); import isMongoIdFunc = require('validator/lib/isMongoId'); import isMultibyteFunc = require('validator/lib/isMultibyte'); @@ -192,6 +193,9 @@ import whitelistFunc = require('validator/lib/whitelist'); let _isMD5 = validator.isMD5; _isMD5 = isMD5Func; + let _isMimeType = validator.isMimeType; + _isMimeType = isMimeTypeFunc; + let _isMobilePhone = validator.isMobilePhone; _isMobilePhone = isMobilePhoneFunc; @@ -311,6 +315,7 @@ let any: any; result = validator.isAlpha('sample', 'cs-CZ'); result = validator.isAlpha('sample', 'da-DK'); result = validator.isAlpha('sample', 'de-DE'); + result = validator.isAlpha('sample', 'el-GR'); result = validator.isAlpha('sample', 'en-AU'); result = validator.isAlpha('sample', 'en-GB'); result = validator.isAlpha('sample', 'en-HK'); @@ -357,6 +362,7 @@ let any: any; result = validator.isAlphanumeric('sample', 'cs-CZ'); result = validator.isAlphanumeric('sample', 'da-DK'); result = validator.isAlphanumeric('sample', 'de-DE'); + result = validator.isAlphanumeric('sample', 'el-GR'); result = validator.isAlphanumeric('sample', 'en-AU'); result = validator.isAlphanumeric('sample', 'en-GB'); result = validator.isAlphanumeric('sample', 'en-HK'); @@ -479,6 +485,8 @@ let any: any; result = validator.isMD5('sample'); + result = validator.isMimeType('sample'); + result = validator.isMobilePhone('sample', 'ar-AE'); result = validator.isMobilePhone('sample', 'ar-DZ'); result = validator.isMobilePhone('sample', 'ar-EG'); @@ -498,6 +506,7 @@ let any: any; result = validator.isMobilePhone('sample', 'en-NZ'); result = validator.isMobilePhone('sample', 'en-UG'); result = validator.isMobilePhone('sample', 'en-RW'); + result = validator.isMobilePhone('sample', 'en-SG'); result = validator.isMobilePhone('sample', 'en-TZ'); result = validator.isMobilePhone('sample', 'en-PK'); result = validator.isMobilePhone('sample', 'en-US'); From d29b1a2fe175a2f778c80ed4f5f9025bd650aa2c Mon Sep 17 00:00:00 2001 From: Naoto Yokoyama Date: Tue, 20 Feb 2018 22:49:38 +0900 Subject: [PATCH 09/17] validator (v9.3): add a bunch of locales Added locales are: - bg-BG (https://github.com/chriso/validator.js/pull/779) - sk-SK (https://github.com/chriso/validator.js/pull/763) - be-BY, kk-KZ (https://github.com/chriso/validator.js/pull/774) - th-TH (https://github.com/chriso/validator.js/pull/777) --- types/validator/index.d.ts | 44 +++++++++++++++--------------- types/validator/validator-tests.ts | 9 ++++++ 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/types/validator/index.d.ts b/types/validator/index.d.ts index 5976ce7982..1df66cf1d5 100644 --- a/types/validator/index.d.ts +++ b/types/validator/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for validator.js v9.2 +// Type definitions for validator.js v9.3 // Project: https://github.com/chriso/validator.js // Definitions by: tgfjt // Ilya Mochalov @@ -10,12 +10,12 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace ValidatorJS { - type AlphaLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; - type AlphanumericLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; - type DecimalLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; - type FloatLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; - type MobilePhoneLocale = "ar-AE" | "ar-DZ" | "ar-EG" | "ar-JO" | "ar-SA" | "ar-SY" | "cs-CZ" | "de-DE" | "da-DK" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-KE" | "en-NG" | "en-NZ" | "en-UG" | "en-RW" | "en-SG" | "en-TZ" | "en-PK" | "en-US" | "en-CA" | "en-ZA" | "en-ZM" | "es-ES" | "fa-IR" | "fi-FI" | "fo-FO" | "fr-FR" | "he-IL" | "hu-HU" | "id-ID" | "it-IT" | "ja-JP" | "kl-GL" | "ko-KR" | "lt-LT" | "ms-MY" | "nb-NO" | "nn-NO" | "pl-PL" | "pt-PT" | "ro-RO" | "ru-RU" | "sk-SK" | "sr-RS" | "tr-TR" | "uk-UA" | "vi-VN" | "zh-CN" | "zh-HK" | "zh-TW" | "any"; - type PostalCodeLocale = "AT" | "AU" | "BE" | "CA" | "CH" | "CZ" | "DE" | "DK" | "DZ" | "ES" | "FI" | "FR" | "GB" | "GR" | "IL" | "IN" | "IS" | "IT" | "JP" | "KE" | "LI" | "MX" | "NL" | "NO" | "PL" | "PT" | "RO" | "RU" | "SA" | "SE" | "TW" | "US" | "ZA" | "ZM" | "any" + type AlphaLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "bg-BG" | "cs-CZ" | "da-DK" | "de-DE" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sk-SK" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; + type AlphanumericLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "bg-BG"| "cs-CZ" | "da-DK" | "de-DE" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sk-SK" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; + type DecimalLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "bg-BG" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; + type FloatLocale = "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-QA" | "ar-QM" | "ar-SA" | "ar-SD" | "ar-SY" | "ar-TN" | "ar-YE" | "bg-BG" | "cs-CZ" | "da-DK" | "de-DE" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-NZ" | "en-US" | "en-ZA" | "en-ZM" | "es-ES" | "fr-FR" | "hu-HU" | "it-IT" | "nb-NO" | "nl-NL" | "nn-NO" | "pl-PL" | "pt-BR" | "pt-PT" | "ru-RU" | "sr-RS" | "sr-RS@latin" | "sv-SE" | "tr-TR" | "uk-UA"; + type MobilePhoneLocale = "ar-AE" | "ar-DZ" | "ar-EG" | "ar-JO" | "ar-SA" | "ar-SY" | "be-BY" | "bg-BG" | "cs-CZ" | "de-DE" | "da-DK" | "el-GR" | "en-AU" | "en-GB" | "en-HK" | "en-IN" | "en-KE" | "en-NG" | "en-NZ" | "en-UG" | "en-RW" | "en-SG" | "en-TZ" | "en-PK" | "en-US" | "en-CA" | "en-ZA" | "en-ZM" | "es-ES" | "fa-IR" | "fi-FI" | "fo-FO" | "fr-FR" | "he-IL" | "hu-HU" | "id-ID" | "it-IT" | "ja-JP" | "kk-KZ" | "kl-GL" | "ko-KR" | "lt-LT" | "ms-MY" | "nb-NO" | "nn-NO" | "pl-PL" | "pt-PT" | "ro-RO" | "ru-RU" | "sk-SK" | "sr-RS" | "th-TH" | "tr-TR" | "uk-UA" | "vi-VN" | "zh-CN" | "zh-HK" | "zh-TW" | "any"; + type PostalCodeLocale = "AT" | "AU" | "BE" | "BG" | "CA" | "CH" | "CZ" | "DE" | "DK" | "DZ" | "ES" | "FI" | "FR" | "GB" | "GR" | "IL" | "IN" | "IS" | "IT" | "JP" | "KE" | "LI" | "MX" | "NL" | "NO" | "PL" | "PT" | "RO" | "RU" | "SA" | "SE" | "TW" | "US" | "ZA" | "ZM" | "any" type HashAlgorithm = "md4" | "md5" | "sha1" | "sha256" | "sha384" | "sha512" | "ripemd128" | "ripemd160" | "tiger128" | "tiger160" | "tiger192" | "crc32" | "crc32b"; interface ValidatorStatic { @@ -35,16 +35,16 @@ declare namespace ValidatorJS { // check if the string contains only letters (a-zA-Z). Locale is one of ['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', // 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', - // 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', - // 'fr-FR', 'hu-HU', 'it-IT' 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', - // 'sv-SE', 'tr-TR', 'uk-UA']) and defaults to en-US + // 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', + // 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sk-SK', 'sr-RS', + // 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']) and defaults to en-US isAlpha(str: string, locale?: AlphaLocale): boolean; // check if the string contains only letters and numbers. Locale is one of ['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', // 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', - // 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', - // 'fr-FR', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sr-RS', 'sr-RS@latin', - // 'sv-SE', 'tr-TR', 'uk-UA']) and defaults to en-US + // 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', + // 'es-ES', 'fr-FR', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sk-SK', 'sr-RS', + // 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']) and defaults to en-US isAlphanumeric(str: string, locale?: AlphanumericLocale): boolean; // check if the string contains ASCII chars only. @@ -157,12 +157,12 @@ declare namespace ValidatorJS { isMimeType(str: string): boolean; // check if the string is a mobile phone number, (locale is one of - // ['ar-AE', ar-DZ', 'ar-EG', 'ar-JO', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', - // 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-KE', 'en-NG', 'en-NZ', 'en-UG', 'en-RW', 'en-SG', - // 'en-TZ', 'en-PK', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fo-FO', - // 'fr-FR', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'kl-GL', 'ko-KR', lt-LT', 'ms-MY', - // 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', 'sr-RS', 'tr-TR', 'uk-UA', - // 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']). + // ['ar-AE', ar-DZ', 'ar-EG', 'ar-JO', 'ar-SA', 'ar-SY', 'be-BY', 'bg-BG', 'cs-CZ', 'de-DE', + // 'da-DK', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-KE', 'en-NG', 'en-NZ', 'en-UG', + // 'en-RW', 'en-SG', 'en-TZ', 'en-PK', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', + // 'fi-FI', 'fo-FO', 'fr-FR', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'kk-KZ', 'kl-GL', + // 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', + // 'sr-RS', 'th-TH', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']). isMobilePhone(str: string, locale: MobilePhoneLocale): boolean; // check if the string is a valid hex-encoded representation of a MongoDB ObjectId @@ -182,9 +182,9 @@ declare namespace ValidatorJS { isPort(str: string): boolean; // check if the string is a postal code, (locale is one of - // [ 'AT', 'AU', 'BE', 'CA', 'CH', 'CZ', 'DE', 'DK', 'DZ', 'ES', 'FI', 'FR', 'GB', 'GR', 'IL', - // 'IN', 'IS', 'IT', 'JP', 'KE', 'LI', 'MX', 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'SA', 'SE', - // 'TW', 'US', 'ZA', 'ZM' ]) OR 'any'. If 'any' is used, function will check if any of the + // [ 'AT', 'AU', 'BE', 'BG', 'CA', 'CH', 'CZ', 'DE', 'DK', 'DZ', 'ES', 'FI', 'FR', 'GB', 'GR', + // 'IL', 'IN', 'IS', 'IT', 'JP', 'KE', 'LI', 'MX', 'NL', 'NO', 'PL', 'PT', 'RO', 'RU', 'SA', + // 'SE', 'TW', 'US', 'ZA', 'ZM' ]) OR 'any'. If 'any' is used, function will check if any of the // locales match). isPostalCode(str: string, locale: PostalCodeLocale): boolean; diff --git a/types/validator/validator-tests.ts b/types/validator/validator-tests.ts index 4709453e14..49d864cb43 100644 --- a/types/validator/validator-tests.ts +++ b/types/validator/validator-tests.ts @@ -312,6 +312,7 @@ let any: any; result = validator.isAlpha('sample', 'ar-SY'); result = validator.isAlpha('sample', 'ar-TN'); result = validator.isAlpha('sample', 'ar-YE'); + result = validator.isAlpha('sample', 'bg-BG'); result = validator.isAlpha('sample', 'cs-CZ'); result = validator.isAlpha('sample', 'da-DK'); result = validator.isAlpha('sample', 'de-DE'); @@ -335,6 +336,7 @@ let any: any; result = validator.isAlpha('sample', 'pt-BR'); result = validator.isAlpha('sample', 'pt-PT'); result = validator.isAlpha('sample', 'ru-RU'); + result = validator.isAlpha('sample', 'sk-SK'); result = validator.isAlpha('sample', 'sr-RS'); result = validator.isAlpha('sample', 'sr-RS@latin'); result = validator.isAlpha('sample', 'sv-SE'); @@ -359,6 +361,7 @@ let any: any; result = validator.isAlphanumeric('sample', 'ar-SY'); result = validator.isAlphanumeric('sample', 'ar-TN'); result = validator.isAlphanumeric('sample', 'ar-YE'); + result = validator.isAlphanumeric('sample', 'bg-BG'); result = validator.isAlphanumeric('sample', 'cs-CZ'); result = validator.isAlphanumeric('sample', 'da-DK'); result = validator.isAlphanumeric('sample', 'de-DE'); @@ -382,6 +385,7 @@ let any: any; result = validator.isAlphanumeric('sample', 'pt-BR'); result = validator.isAlphanumeric('sample', 'pt-PT'); result = validator.isAlphanumeric('sample', 'ru-RU'); + result = validator.isAlphanumeric('sample', 'sk-SK'); result = validator.isAlphanumeric('sample', 'sr-RS'); result = validator.isAlphanumeric('sample', 'sr-RS@latin'); result = validator.isAlphanumeric('sample', 'sv-SE'); @@ -493,6 +497,8 @@ let any: any; result = validator.isMobilePhone('sample', 'ar-JO'); result = validator.isMobilePhone('sample', 'ar-SA'); result = validator.isMobilePhone('sample', 'ar-SY'); + result = validator.isMobilePhone('sample', 'be-BY'); + result = validator.isMobilePhone('sample', 'bg-BG'); result = validator.isMobilePhone('sample', 'cs-CZ'); result = validator.isMobilePhone('sample', 'de-DE'); result = validator.isMobilePhone('sample', 'da-DK'); @@ -523,6 +529,7 @@ let any: any; result = validator.isMobilePhone('sample', 'id-ID'); result = validator.isMobilePhone('sample', 'it-IT'); result = validator.isMobilePhone('sample', 'ja-JP'); + result = validator.isMobilePhone('sample', 'kk-KZ'); result = validator.isMobilePhone('sample', 'kl-GL'); result = validator.isMobilePhone('sample', 'ko-KR'); result = validator.isMobilePhone('sample', 'lt-LT'); @@ -535,6 +542,7 @@ let any: any; result = validator.isMobilePhone('sample', 'ru-RU'); result = validator.isMobilePhone('sample', 'sr-RS'); result = validator.isMobilePhone('sample', 'sk-SK'); + result = validator.isMobilePhone('sample', 'th-TH'); result = validator.isMobilePhone('sample', 'tr-TR'); result = validator.isMobilePhone('sample', 'uk-UA'); result = validator.isMobilePhone('sample', 'vi-VN'); @@ -556,6 +564,7 @@ let any: any; result = validator.isPostalCode('sample', 'AT'); result = validator.isPostalCode('sample', 'AU'); result = validator.isPostalCode('sample', 'BE'); + result = validator.isPostalCode('sample', 'BG'); result = validator.isPostalCode('sample', 'CA'); result = validator.isPostalCode('sample', 'CH'); result = validator.isPostalCode('sample', 'CZ'); From f8af9626d7cab665dbc7a7693adee2fe58851719 Mon Sep 17 00:00:00 2001 From: Naoto Yokoyama Date: Tue, 20 Feb 2018 22:56:58 +0900 Subject: [PATCH 10/17] validator (v9.4): add options for isMobilePhone() --- types/validator/index.d.ts | 9 +++++++-- types/validator/validator-tests.ts | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/types/validator/index.d.ts b/types/validator/index.d.ts index 1df66cf1d5..ee3cf460de 100644 --- a/types/validator/index.d.ts +++ b/types/validator/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for validator.js v9.3 +// Type definitions for validator.js v9.4 // Project: https://github.com/chriso/validator.js // Definitions by: tgfjt // Ilya Mochalov @@ -163,7 +163,7 @@ declare namespace ValidatorJS { // 'fi-FI', 'fo-FO', 'fr-FR', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'ja-JP', 'kk-KZ', 'kl-GL', // 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 'sk-SK', // 'sr-RS', 'th-TH', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']). - isMobilePhone(str: string, locale: MobilePhoneLocale): boolean; + isMobilePhone(str: string, locale: MobilePhoneLocale, options?: IsMobilePhoneOptions): boolean; // check if the string is a valid hex-encoded representation of a MongoDB ObjectId // (http://docs.mongodb.org/manual/reference/object-id/). @@ -337,6 +337,11 @@ declare namespace ValidatorJS { max?: number; } + // options for isMobilePhone + interface IsMobilePhoneOptions { + strictMode?: boolean; + } + // options for isURL interface IsURLOptions { protocols?: string[]; diff --git a/types/validator/validator-tests.ts b/types/validator/validator-tests.ts index 49d864cb43..4172d80751 100644 --- a/types/validator/validator-tests.ts +++ b/types/validator/validator-tests.ts @@ -491,6 +491,8 @@ let any: any; result = validator.isMimeType('sample'); + let isMobilePhoneOptions: ValidatorJS.IsMobilePhoneOptions; + result = validator.isMobilePhone('sample', 'any', isMobilePhoneOptions); result = validator.isMobilePhone('sample', 'ar-AE'); result = validator.isMobilePhone('sample', 'ar-DZ'); result = validator.isMobilePhone('sample', 'ar-EG'); From c7e42dc2301f79de2a97ab5c69f32735476c3a9d Mon Sep 17 00:00:00 2001 From: Naoto Yokoyama Date: Tue, 20 Feb 2018 23:02:49 +0900 Subject: [PATCH 11/17] validator: add a test for isAlphanumeric() --- types/validator/validator-tests.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/validator/validator-tests.ts b/types/validator/validator-tests.ts index 4172d80751..8ee42c6572 100644 --- a/types/validator/validator-tests.ts +++ b/types/validator/validator-tests.ts @@ -343,6 +343,7 @@ let any: any; result = validator.isAlpha('sample', 'tr-TR'); result = validator.isAlpha('sample', 'uk-UA'); + result = validator.isAlphanumeric('sample'); result = validator.isAlphanumeric('sample', 'ar'); result = validator.isAlphanumeric('sample', 'ar-AE'); result = validator.isAlphanumeric('sample', 'ar-BH'); From ed2827423c2bdaec1ab5625b273a8020410a9bdb Mon Sep 17 00:00:00 2001 From: Naoto Yokoyama Date: Tue, 20 Feb 2018 23:07:03 +0900 Subject: [PATCH 12/17] validator: add require_display_name option for isEmail() --- types/validator/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/validator/index.d.ts b/types/validator/index.d.ts index ee3cf460de..e22386e343 100644 --- a/types/validator/index.d.ts +++ b/types/validator/index.d.ts @@ -304,6 +304,7 @@ declare namespace ValidatorJS { // options for isEmail interface IsEmailOptions { allow_display_name?: boolean; + require_display_name?: boolean; allow_utf8_local_part?: boolean; require_tld?: boolean; } From dac0f9d0d15f58862fd374fada7ca0a12cccda72 Mon Sep 17 00:00:00 2001 From: Naoto Yokoyama Date: Tue, 20 Feb 2018 23:09:10 +0900 Subject: [PATCH 13/17] validator: add a test for isEmpty() --- types/validator/validator-tests.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types/validator/validator-tests.ts b/types/validator/validator-tests.ts index 8ee42c6572..626f51671e 100644 --- a/types/validator/validator-tests.ts +++ b/types/validator/validator-tests.ts @@ -425,6 +425,8 @@ let any: any; result = validator.isEmail('sample'); result = validator.isEmail('sample', isEmailOptions); + result = validator.isEmpty('sample'); + let isFQDNOptions: ValidatorJS.IsFQDNOptions; result = validator.isFQDN('sample'); result = validator.isFQDN('sample', isFQDNOptions); From 4553192408b0e12f1ef59b5a8ec4ff359c99c0e4 Mon Sep 17 00:00:00 2001 From: Naoto Yokoyama Date: Tue, 20 Feb 2018 23:12:41 +0900 Subject: [PATCH 14/17] validator: add gt and lt option to isFloat() --- types/validator/index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types/validator/index.d.ts b/types/validator/index.d.ts index e22386e343..228090f62c 100644 --- a/types/validator/index.d.ts +++ b/types/validator/index.d.ts @@ -320,6 +320,8 @@ declare namespace ValidatorJS { interface IsFloatOptions { min?: number; max?: number; + gt?: number; + lt?: number; locale?: FloatLocale; } From 7e9f8baca4e307555ade863df0369e5c89cf6465 Mon Sep 17 00:00:00 2001 From: Naoto Yokoyama Date: Tue, 20 Feb 2018 23:18:37 +0900 Subject: [PATCH 15/17] validator: add isISSN() --- types/validator/index.d.ts | 14 ++++++++++++++ types/validator/validator-tests.ts | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/types/validator/index.d.ts b/types/validator/index.d.ts index 228090f62c..0806d34f2a 100644 --- a/types/validator/index.d.ts +++ b/types/validator/index.d.ts @@ -113,6 +113,9 @@ declare namespace ValidatorJS { // check if the string is an ISBN (version 10 or 13). isISBN(str: string, version?: number): boolean; + // check if the string is an ISSN (https://en.wikipedia.org/wiki/International_Standard_Serial_Number). + isISSN(str: string, options?: IsISSNOptions): boolean; + // check if the string is an ISIN (https://en.wikipedia.org/wiki/International_Securities_Identification_Number) // (stock/security identifier). isISIN(str: string): boolean; @@ -325,6 +328,12 @@ declare namespace ValidatorJS { locale?: FloatLocale; } + // options for isISSN + interface IsISSNOptions { + case_sensitive?: boolean; + require_hyphen?: boolean; + } + // options for IsInt interface IsIntOptions { min?: number; @@ -516,6 +525,11 @@ declare module "validator/lib/isISBN" { export = isISBN; } +declare module "validator/lib/isISSN" { + const isISSN: typeof validator.isISSN; + export = isISSN; +} + declare module "validator/lib/isISIN" { const isISIN: typeof validator.isISIN; export = isISIN; diff --git a/types/validator/validator-tests.ts b/types/validator/validator-tests.ts index 626f51671e..0aaf7f1f10 100644 --- a/types/validator/validator-tests.ts +++ b/types/validator/validator-tests.ts @@ -33,6 +33,7 @@ import isHexColorFunc = require('validator/lib/isHexColor'); import isHexadecimalFunc = require('validator/lib/isHexadecimal'); import isIPFunc = require('validator/lib/isIP'); import isISBNFunc = require('validator/lib/isISBN'); +import isISSNFunc = require('validator/lib/isISSN'); import isISINFunc = require('validator/lib/isISIN'); import isISO8601Func = require('validator/lib/isISO8601'); import isISO31661Alpha2Func = require('validator/lib/isISO31661Alpha2'); @@ -157,6 +158,9 @@ import whitelistFunc = require('validator/lib/whitelist'); let _isISBN = validator.isISBN; _isISBN = isISBNFunc; + let _isISSN = validator.isISSN; + _isISSN = isISSNFunc; + let _isISIN = validator.isISIN; _isISIN = isISINFunc; @@ -463,6 +467,10 @@ let any: any; result = validator.isISBN('sample'); result = validator.isISBN('sample', 13); + let isISSNOptions: ValidatorJS.IsISSNOptions; + result = validator.isISSN('sample'); + result = validator.isISSN('sample', isISSNOptions); + result = validator.isISIN('sample'); result = validator.isISO8601('sample'); From 4958f3ea59e6e09286d02ff62bd2abb0ab1900a0 Mon Sep 17 00:00:00 2001 From: Naoto Yokoyama Date: Tue, 20 Feb 2018 23:21:44 +0900 Subject: [PATCH 16/17] validator: remove isNull(), which was renamed to isEmpty() --- types/validator/index.d.ts | 8 -------- types/validator/validator-tests.ts | 6 ------ 2 files changed, 14 deletions(-) diff --git a/types/validator/index.d.ts b/types/validator/index.d.ts index 0806d34f2a..204b032ba5 100644 --- a/types/validator/index.d.ts +++ b/types/validator/index.d.ts @@ -175,9 +175,6 @@ declare namespace ValidatorJS { // check if the string contains one or more multibyte chars. isMultibyte(str: string): boolean; - // check if the string is null. - isNull(str: string): boolean; - // check if the string contains only numbers. isNumeric(str: string): boolean; @@ -615,11 +612,6 @@ declare module "validator/lib/isMultibyte" { export = isMultibyte; } -declare module "validator/lib/isNull" { - const isNull: typeof validator.isNull; - export = isNull; -} - declare module "validator/lib/isNumeric" { const isNumeric: typeof validator.isNumeric; export = isNumeric; diff --git a/types/validator/validator-tests.ts b/types/validator/validator-tests.ts index 0aaf7f1f10..c3d4327d84 100644 --- a/types/validator/validator-tests.ts +++ b/types/validator/validator-tests.ts @@ -50,7 +50,6 @@ import isMimeTypeFunc = require('validator/lib/isMimeType'); import isMobilePhoneFunc = require('validator/lib/isMobilePhone'); import isMongoIdFunc = require('validator/lib/isMongoId'); import isMultibyteFunc = require('validator/lib/isMultibyte'); -import isNullFunc = require('validator/lib/isNull'); import isNumericFunc = require('validator/lib/isNumeric'); import isPortFunc = require('validator/lib/isPort'); import isPostalCodeFunc = require('validator/lib/isPostalCode'); @@ -209,9 +208,6 @@ import whitelistFunc = require('validator/lib/whitelist'); let _isMultibyte = validator.isMultibyte; _isMultibyte = isMultibyteFunc; - let _isNull = validator.isNull; - _isNull = isNullFunc; - let _isNumeric = validator.isNumeric; _isNumeric = isNumericFunc; @@ -568,8 +564,6 @@ let any: any; result = validator.isMultibyte('sample'); - result = validator.isNull('sample'); - result = validator.isNumeric('sample'); result = validator.isPort('sample'); From f27bed9d456267a323061645c81d34b7f49bb41c Mon Sep 17 00:00:00 2001 From: Naoto Yokoyama Date: Tue, 20 Feb 2018 23:34:48 +0900 Subject: [PATCH 17/17] validator: update options for normalizeEmail() See: https://github.com/chriso/validator.js/pull/583 --- types/validator/index.d.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/types/validator/index.d.ts b/types/validator/index.d.ts index 204b032ba5..e91bd36ce2 100644 --- a/types/validator/index.d.ts +++ b/types/validator/index.d.ts @@ -367,9 +367,17 @@ declare namespace ValidatorJS { // options for normalizeEmail interface NormalizeEmailOptions { - lowercase?: boolean; - remove_dots?: boolean; - remove_extension?: boolean; + all_lowercase?: boolean; + gmail_lowercase?: boolean; + gmail_remove_dots?: boolean; + gmail_remove_subaddress?: boolean; + gmail_convert_googlemaildotcom?: boolean; + outlookdotcom_lowercase?: boolean; + outlookdotcom_remove_subaddress?: boolean; + yahoo_lowercase?: boolean; + yahoo_remove_subaddress?: boolean; + icloud_lowercase?: boolean; + icloud_remove_subaddress?: boolean; } }