Skip to content

Commit

Permalink
validator (v7.1): add isISRC() and mobile phone locales
Browse files Browse the repository at this point in the history
Added locales are:
  - id-ID (validatorjs/validator.js#647)
  - lt-LT (validatorjs/validator.js#667)
  - fa-IR (validatorjs/validator.js#671)

ko-KR (validatorjs/validator.js#668) has already
been added.
  • Loading branch information
builtinnya committed Feb 20, 2018
1 parent af0fdee commit caf5db5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
18 changes: 13 additions & 5 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 v7.0
// Type definitions for validator.js v7.1
// Project: https://github.com/chriso/validator.js
// Definitions by: tgfjt <https://github.com/tgfjt>
// Ilya Mochalov <https://github.com/chrootsu>
Expand All @@ -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 {
Expand Down Expand Up @@ -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;

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

Expand Down Expand Up @@ -408,6 +412,8 @@ let any: any;

result = validator.isISO8601('sample');

result = validator.isISRC('sample');

result = validator.isIn('sample', []);

let isIntOptions: ValidatorJS.IsIntOptions;
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit caf5db5

Please sign in to comment.