add isPostalCode (#20042)

This commit is contained in:
iwllyu
2017-09-26 14:03:43 -04:00
committed by Mohamed Hegazy
parent 6d7f3012a1
commit 30a381e2ee
2 changed files with 54 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
// Type definitions for validator.js v6.2
// Type definitions for validator.js v6.3
// Project: https://github.com/chriso/validator.js
// Definitions by: tgfjt <https://github.com/tgfjt>
// Ilya Mochalov <https://github.com/chrootsu>
@@ -12,6 +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 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 {
@@ -154,6 +155,13 @@ declare namespace ValidatorJS {
// check if the string contains only numbers.
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',
// '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;
// check if the string contains any surrogate pairs chars.
isSurrogatePair(str: string): boolean;
@@ -513,6 +521,11 @@ declare module "validator/lib/isMobilePhone" {
export = isMobilePhone;
}
declare module "validator/lib/isPostalCode" {
const isPostalCode: typeof validator.isPostalCode;
export = isPostalCode;
}
declare module "validator/lib/isMongoId" {
const isMongoId: typeof validator.isMongoId;
export = isMongoId;

View File

@@ -47,6 +47,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 isPostalCodeFunc = require('validator/lib/isPostalCode');
import isSurrogatePairFunc = require('validator/lib/isSurrogatePair');
import isURLFunc = require('validator/lib/isURL');
import isUUIDFunc = require('validator/lib/isUUID');
@@ -193,6 +194,9 @@ import whitelistFunc = require('validator/lib/whitelist');
let _isNumeric = validator.isNumeric;
_isNumeric = isNumericFunc;
let _isPostalCode = validator.isPostalCode;
_isPostalCode = isPostalCodeFunc;
let _isSurrogatePair = validator.isSurrogatePair;
_isSurrogatePair = isSurrogatePairFunc;
@@ -472,6 +476,42 @@ let any: any;
result = validator.isNumeric('sample');
result = validator.isPostalCode('sample', 'AT');
result = validator.isPostalCode('sample', 'AU');
result = validator.isPostalCode('sample', 'BE');
result = validator.isPostalCode('sample', 'CA');
result = validator.isPostalCode('sample', 'CH');
result = validator.isPostalCode('sample', 'CZ');
result = validator.isPostalCode('sample', 'DE');
result = validator.isPostalCode('sample', 'DK');
result = validator.isPostalCode('sample', 'DZ');
result = validator.isPostalCode('sample', 'ES');
result = validator.isPostalCode('sample', 'FI');
result = validator.isPostalCode('sample', 'FR');
result = validator.isPostalCode('sample', 'GB');
result = validator.isPostalCode('sample', 'GR');
result = validator.isPostalCode('sample', 'IL');
result = validator.isPostalCode('sample', 'IN');
result = validator.isPostalCode('sample', 'IS');
result = validator.isPostalCode('sample', 'IT');
result = validator.isPostalCode('sample', 'JP');
result = validator.isPostalCode('sample', 'KE');
result = validator.isPostalCode('sample', 'LI');
result = validator.isPostalCode('sample', 'MX');
result = validator.isPostalCode('sample', 'NL');
result = validator.isPostalCode('sample', 'NO');
result = validator.isPostalCode('sample', 'PL');
result = validator.isPostalCode('sample', 'PT');
result = validator.isPostalCode('sample', 'RO');
result = validator.isPostalCode('sample', 'RU');
result = validator.isPostalCode('sample', 'SA');
result = validator.isPostalCode('sample', 'SE');
result = validator.isPostalCode('sample', 'TW');
result = validator.isPostalCode('sample', 'US');
result = validator.isPostalCode('sample', 'ZA');
result = validator.isPostalCode('sample', 'ZM');
result = validator.isPostalCode('sample', 'any');
result = validator.isSurrogatePair('sample');
let isURLOptions: ValidatorJS.IsURLOptions;