Skip to content

Commit

Permalink
validator (v9.1): add isISO31661Alpha2() and some locales
Browse files Browse the repository at this point in the history
Added locales are:
  - fo-FO, kl-GL (validatorjs/validator.js#735)
  • Loading branch information
builtinnya committed Feb 20, 2018
1 parent 0b926af commit 54ee800
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
21 changes: 15 additions & 6 deletions types/validator/index.d.ts
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/tgfjt>
// Ilya Mochalov <https://github.com/chrootsu>
Expand All @@ -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";

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions types/validator/validator-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -450,6 +454,8 @@ let any: any;

result = validator.isISO8601('sample');

result = validator.isISO31661Alpha2('sample');

result = validator.isISRC('sample');

result = validator.isIn('sample', []);
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 54ee800

Please sign in to comment.