Skip to content

Commit

Permalink
validator (v8.2): add isHash(), isCurrency() options, and locales
Browse files Browse the repository at this point in the history
Added isCurrency() options are:
  - allow_decimal
  - require_decimal
  - digits_after_decimal

Added locales are:
  - it-IT (validatorjs/validator.js#700)
  - sv-SE (validatorjs/validator.js#714)
  - ar-AE, ar-EG (validatorjs/validator.js#718)
  - ar-JO (validatorjs/validator.js#701)
  - sk-SK (validatorjs/validator.js#715)
  • Loading branch information
builtinnya committed Feb 20, 2018
1 parent 659358a commit 9318ba8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 11 deletions.
38 changes: 27 additions & 11 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 v8.1
// Type definitions for validator.js v8.2
// Project: https://github.com/chriso/validator.js
// Definitions by: tgfjt <https://github.com/tgfjt>
// Ilya Mochalov <https://github.com/chrootsu>
Expand All @@ -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 {

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

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

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

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

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

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

0 comments on commit 9318ba8

Please sign in to comment.