diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 4627fe57a..000000000 --- a/.eslintignore +++ /dev/null @@ -1,2 +0,0 @@ -validator.js -validator.min.js \ No newline at end of file diff --git a/.gitignore b/.gitignore index b952b6308..02f031234 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ package-lock.json yarn.lock /es /lib +validator.js +validator.min.js +index.js diff --git a/.travis.yml b/.travis.yml index 0681de748..356e06912 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,3 @@ -sudo: false language: node_js node_js: - stable diff --git a/README.md b/README.md index a78fb3f24..fb1c19b14 100644 --- a/README.md +++ b/README.md @@ -84,8 +84,8 @@ Validator | Description **contains(str, seed [, options ])** | check if the string contains the seed.

`options` is an object that defaults to `{ ignoreCase: false}`.
`ignoreCase` specified whether the case of the substring be same or not. **equals(str, comparison)** | check if the string matches the comparison. **isAfter(str [, date])** | check if the string is a date that's after the specified date (defaults to now). -**isAlpha(str [, locale, options])** | 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', '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', 'fa-IR', 'he', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. Locale list is `validator.isAlphaLocales`. options is an optional object that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. -**isAlphanumeric(str [, locale])** | 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', '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', 'fa-IR', 'he', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. Locale list is `validator.isAlphanumericLocales`. +**isAlpha(str [, locale, options])** | 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', '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', 'fa-IR', 'fr-CA', 'fr-FR', 'he', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. Locale list is `validator.isAlphaLocales`. options is an optional object that can be supplied with the following key(s): ignore which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. +**isAlphanumeric(str [, locale])** | 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', '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', 'fa-IR', 'fr-CA', 'fr-FR', 'he', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. Locale list is `validator.isAlphanumericLocales`. **isAscii(str)** | check if the string contains ASCII chars only. **isBase32(str)** | check if a string is base32 encoded. **isBase58(str)** | check if a string is base58 encoded. @@ -99,13 +99,13 @@ Validator | Description **isCurrency(str [, options])** | check if the string is a valid currency amount.

`options` is an object which defaults to `{symbol: '$', require_symbol: false, allow_space_after_symbol: false, symbol_after_digits: false, allow_negatives: true, parens_for_negatives: false, negative_sign_before_digits: false, negative_sign_after_digits: false, allow_negative_sign_placeholder: false, thousands_separator: ',', decimal_separator: '.', allow_decimal: true, require_decimal: false, digits_after_decimal: [2], allow_space_after_digits: false}`.
**Note:** The array `digits_after_decimal` is filled with the exact number of digits allowed not a range, for example a range 1 to 3 will be given as [1, 2, 3]. **isDataURI(str)** | check if the string is a [data uri format](https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs). **isDate(input [, options])** | Check if the input is a valid date. e.g. [`2002-07-15`, new Date()].

`options` is an object which can contain the keys `format`, `strictMode` and/or `delimiters`

`format` is a string and defaults to `YYYY/MM/DD`.

`strictMode` is a boolean and defaults to `false`. If `strictMode` is set to true, the validator will reject inputs different from `format`.

`delimiters` is an array of allowed date delimiters and defaults to `['/', '-']`. -**isDecimal(str [, options])** | check if the string represents a decimal number, such as 0.1, .3, 1.1, 1.00003, 4.0, etc.

`options` is an object which defaults to `{force_decimal: false, decimal_digits: '1,', locale: 'en-US'}`

`locale` determine the decimal separator and 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', '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', 'fa', 'fa-AF', 'fa-IR', 'fr-FR', 'hu-HU', 'id-ID', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pl-Pl', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN']`.
**Note:** `decimal_digits` is given as a range like '1,3', a specific value like '3' or min like '1,'. +**isDecimal(str [, options])** | check if the string represents a decimal number, such as 0.1, .3, 1.1, 1.00003, 4.0, etc.

`options` is an object which defaults to `{force_decimal: false, decimal_digits: '1,', locale: 'en-US'}`

`locale` determine the decimal separator and 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', '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', 'fa', 'fa-AF', 'fa-IR', 'fr-FR', 'fr-CA', 'hu-HU', 'id-ID', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pl-Pl', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN']`.
**Note:** `decimal_digits` is given as a range like '1,3', a specific value like '3' or min like '1,'. **isDivisibleBy(str, number)** | check if the string is a number that's divisible by another. **isEAN(str)** | check if the string is an EAN (European Article Number). **isEmail(str [, options])** | check if the string is an email.

`options` is an object which defaults to `{ allow_display_name: false, require_display_name: false, allow_utf8_local_part: true, require_tld: true, allow_ip_domain: false, domain_specific_validation: false, blacklisted_chars: '' }`. If `allow_display_name` is set to true, the validator will also match `Display Name `. If `require_display_name` is set to true, the validator will reject strings without the format `Display Name `. If `allow_utf8_local_part` is set to false, the validator will not allow any non-English UTF8 character in email address' local part. If `require_tld` is set to false, e-mail addresses without having TLD in their domain will also be matched. If `ignore_max_length` is set to true, the validator will not check for the standard max length of an email. If `allow_ip_domain` is set to true, the validator will allow IP addresses in the host part. If `domain_specific_validation` is true, some additional validation will be enabled, e.g. disallowing certain syntactically valid email addresses that are rejected by GMail. If `blacklisted_chars` recieves a string,then the validator will reject emails that include any of the characters in the string, in the name part. **isEmpty(str [, options])** | check if the string has a length of zero.

`options` is an object which defaults to `{ ignore_whitespace:false }`. **isEthereumAddress(str)** | check if the string is an [Ethereum](https://ethereum.org/) address using basic regex. Does not validate address checksums. -**isFloat(str [, options])** | check if the string is a float.

`options` is an object which can contain the keys `min`, `max`, `gt`, and/or `lt` to validate the float is within boundaries (e.g. `{ min: 7.22, max: 9.55 }`) it also has `locale` as an option.

`min` and `max` are equivalent to 'greater or equal' and 'less or equal', respectively while `gt` and `lt` are their strict counterparts.

`locale` determine the decimal separator and 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', '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', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`. Locale list is `validator.isFloatLocales`. +**isFloat(str [, options])** | check if the string is a float.

`options` is an object which can contain the keys `min`, `max`, `gt`, and/or `lt` to validate the float is within boundaries (e.g. `{ min: 7.22, max: 9.55 }`) it also has `locale` as an option.

`min` and `max` are equivalent to 'greater or equal' and 'less or equal', respectively while `gt` and `lt` are their strict counterparts.

`locale` determine the decimal separator and 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', '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-CA', 'fr-FR', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`. Locale list is `validator.isFloatLocales`. **isFQDN(str [, options])** | check if the string is a fully qualified domain name (e.g. domain.com).

`options` is an object which defaults to `{ require_tld: true, allow_underscores: false, allow_trailing_dot: false , allow_numeric_tld: false }`. **isFullWidth(str)** | check if the string contains any full-width chars. **isHalfWidth(str)** | check if the string contains any half-width chars. @@ -137,10 +137,10 @@ Validator | Description **isMagnetURI(str)** | check if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). **isMD5(str)** | check if the string is a MD5 hash.

Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA). **isMimeType(str)** | check if the string matches to a valid [MIME type](https://en.wikipedia.org/wiki/Media_type) format -**isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,

(locale is either an array of locales (e.g `['sk-SK', 'sr-RS']`) OR one of `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-MA', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ro-RO', 'ru-RU', 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', 'zh-TW']` OR defaults to 'any'. If 'any' or a falsey value is used, function will check if any of the locales match).

`options` is an optional object that can be supplied with the following keys: `strictMode`, if this is set to `true`, the mobile phone number must be supplied with the country code and therefore must start with `+`. Locale list is `validator.isMobilePhoneLocales`. +**isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,

(locale is either an array of locales (e.g `['sk-SK', 'sr-RS']`) OR one of `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', ar-JO', 'ar-KW', 'ar-MA', 'ar-SA', 'ar-SY', 'ar-TN', 'az-AZ', 'az-LY', 'az-LB', 'bs-BA', 'be-BY', 'bg-BG', 'bn-BD', 'ca-AD', 'cs-CZ', 'da-DK', 'de-DE', 'de-AT', 'de-CH', 'de-LU', 'el-GR', 'en-AU', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-HK', 'en-MO', 'en-IE', 'en-IN', 'en-KE', 'en-MT', 'en-MU', 'en-NG', 'en-NZ', 'en-PK', 'en-PH', 'en-RW', 'en-SG', 'en-SL', 'en-UG', 'en-US', 'en-TZ', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-DO', 'es-HN', 'es-PE', 'es-EC', 'es-ES', 'es-MX', 'es-PA', 'es-PY', 'es-UY', 'et-EE', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-CA', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-RE', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'ne-NP', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ro-RO', 'ru-RU', 'sl-SI', 'sk-SK', 'sq-AL', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', 'zh-TW']` OR defaults to 'any'. If 'any' or a falsey value is used, function will check if any of the locales match).

`options` is an optional object that can be supplied with the following keys: `strictMode`, if this is set to `true`, the mobile phone number must be supplied with the country code and therefore must start with `+`. Locale list is `validator.isMobilePhoneLocales`. **isMongoId(str)** | check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid]. **isMultibyte(str)** | check if the string contains one or more multibyte chars. -**isNumeric(str [, options])** | check if the string contains only numbers.

`options` is an object which defaults to `{no_symbols: false}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`locale` determine the decimal separator and 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', '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', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`. +**isNumeric(str [, options])** | check if the string contains only numbers.

`options` is an object which defaults to `{no_symbols: false}` it also has locale as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`locale` determine the decimal separator and 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', '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', 'fr-CA', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`. **isOctal(str)** | check if the string is a valid octal number. **isPassportNumber(str, countryCode)** | check if the string is a valid passport number.

(countryCode is one of `[ 'AM', 'AR', 'AT', 'AU', 'BE', 'BG', 'BY', 'CA', 'CH', 'CN', 'CY', 'CZ', 'DE', 'DK', 'DZ', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE' 'IN', 'IS', 'IT', 'JP', 'KR', 'LT', 'LU', 'LV', 'MT', 'NL', 'PO', 'PT', 'RO', 'RU', 'SE', 'SL', 'SK', 'TR', 'UA', 'US' ]`. **isPort(str)** | check if the string is a valid port number. diff --git a/index.js b/index.js deleted file mode 100644 index 19417991b..000000000 --- a/index.js +++ /dev/null @@ -1,296 +0,0 @@ -"use strict"; - -function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _toDate = _interopRequireDefault(require("./lib/toDate")); - -var _toFloat = _interopRequireDefault(require("./lib/toFloat")); - -var _toInt = _interopRequireDefault(require("./lib/toInt")); - -var _toBoolean = _interopRequireDefault(require("./lib/toBoolean")); - -var _equals = _interopRequireDefault(require("./lib/equals")); - -var _contains = _interopRequireDefault(require("./lib/contains")); - -var _matches = _interopRequireDefault(require("./lib/matches")); - -var _isEmail = _interopRequireDefault(require("./lib/isEmail")); - -var _isURL = _interopRequireDefault(require("./lib/isURL")); - -var _isMACAddress = _interopRequireDefault(require("./lib/isMACAddress")); - -var _isIP = _interopRequireDefault(require("./lib/isIP")); - -var _isIPRange = _interopRequireDefault(require("./lib/isIPRange")); - -var _isFQDN = _interopRequireDefault(require("./lib/isFQDN")); - -var _isDate = _interopRequireDefault(require("./lib/isDate")); - -var _isBoolean = _interopRequireDefault(require("./lib/isBoolean")); - -var _isLocale = _interopRequireDefault(require("./lib/isLocale")); - -var _isAlpha = _interopRequireWildcard(require("./lib/isAlpha")); - -var _isAlphanumeric = _interopRequireWildcard(require("./lib/isAlphanumeric")); - -var _isNumeric = _interopRequireDefault(require("./lib/isNumeric")); - -var _isPassportNumber = _interopRequireDefault(require("./lib/isPassportNumber")); - -var _isPort = _interopRequireDefault(require("./lib/isPort")); - -var _isLowercase = _interopRequireDefault(require("./lib/isLowercase")); - -var _isUppercase = _interopRequireDefault(require("./lib/isUppercase")); - -var _isIMEI = _interopRequireDefault(require("./lib/isIMEI")); - -var _isAscii = _interopRequireDefault(require("./lib/isAscii")); - -var _isFullWidth = _interopRequireDefault(require("./lib/isFullWidth")); - -var _isHalfWidth = _interopRequireDefault(require("./lib/isHalfWidth")); - -var _isVariableWidth = _interopRequireDefault(require("./lib/isVariableWidth")); - -var _isMultibyte = _interopRequireDefault(require("./lib/isMultibyte")); - -var _isSemVer = _interopRequireDefault(require("./lib/isSemVer")); - -var _isSurrogatePair = _interopRequireDefault(require("./lib/isSurrogatePair")); - -var _isInt = _interopRequireDefault(require("./lib/isInt")); - -var _isFloat = _interopRequireWildcard(require("./lib/isFloat")); - -var _isDecimal = _interopRequireDefault(require("./lib/isDecimal")); - -var _isHexadecimal = _interopRequireDefault(require("./lib/isHexadecimal")); - -var _isOctal = _interopRequireDefault(require("./lib/isOctal")); - -var _isDivisibleBy = _interopRequireDefault(require("./lib/isDivisibleBy")); - -var _isHexColor = _interopRequireDefault(require("./lib/isHexColor")); - -var _isRgbColor = _interopRequireDefault(require("./lib/isRgbColor")); - -var _isHSL = _interopRequireDefault(require("./lib/isHSL")); - -var _isISRC = _interopRequireDefault(require("./lib/isISRC")); - -var _isIBAN = _interopRequireDefault(require("./lib/isIBAN")); - -var _isBIC = _interopRequireDefault(require("./lib/isBIC")); - -var _isMD = _interopRequireDefault(require("./lib/isMD5")); - -var _isHash = _interopRequireDefault(require("./lib/isHash")); - -var _isJWT = _interopRequireDefault(require("./lib/isJWT")); - -var _isJSON = _interopRequireDefault(require("./lib/isJSON")); - -var _isEmpty = _interopRequireDefault(require("./lib/isEmpty")); - -var _isLength = _interopRequireDefault(require("./lib/isLength")); - -var _isByteLength = _interopRequireDefault(require("./lib/isByteLength")); - -var _isUUID = _interopRequireDefault(require("./lib/isUUID")); - -var _isMongoId = _interopRequireDefault(require("./lib/isMongoId")); - -var _isAfter = _interopRequireDefault(require("./lib/isAfter")); - -var _isBefore = _interopRequireDefault(require("./lib/isBefore")); - -var _isIn = _interopRequireDefault(require("./lib/isIn")); - -var _isCreditCard = _interopRequireDefault(require("./lib/isCreditCard")); - -var _isIdentityCard = _interopRequireDefault(require("./lib/isIdentityCard")); - -var _isEAN = _interopRequireDefault(require("./lib/isEAN")); - -var _isISIN = _interopRequireDefault(require("./lib/isISIN")); - -var _isISBN = _interopRequireDefault(require("./lib/isISBN")); - -var _isISSN = _interopRequireDefault(require("./lib/isISSN")); - -var _isTaxID = _interopRequireDefault(require("./lib/isTaxID")); - -var _isMobilePhone = _interopRequireWildcard(require("./lib/isMobilePhone")); - -var _isEthereumAddress = _interopRequireDefault(require("./lib/isEthereumAddress")); - -var _isCurrency = _interopRequireDefault(require("./lib/isCurrency")); - -var _isBtcAddress = _interopRequireDefault(require("./lib/isBtcAddress")); - -var _isISO = _interopRequireDefault(require("./lib/isISO8601")); - -var _isRFC = _interopRequireDefault(require("./lib/isRFC3339")); - -var _isISO31661Alpha = _interopRequireDefault(require("./lib/isISO31661Alpha2")); - -var _isISO31661Alpha2 = _interopRequireDefault(require("./lib/isISO31661Alpha3")); - -var _isBase = _interopRequireDefault(require("./lib/isBase32")); - -var _isBase2 = _interopRequireDefault(require("./lib/isBase58")); - -var _isBase3 = _interopRequireDefault(require("./lib/isBase64")); - -var _isDataURI = _interopRequireDefault(require("./lib/isDataURI")); - -var _isMagnetURI = _interopRequireDefault(require("./lib/isMagnetURI")); - -var _isMimeType = _interopRequireDefault(require("./lib/isMimeType")); - -var _isLatLong = _interopRequireDefault(require("./lib/isLatLong")); - -var _isPostalCode = _interopRequireWildcard(require("./lib/isPostalCode")); - -var _ltrim = _interopRequireDefault(require("./lib/ltrim")); - -var _rtrim = _interopRequireDefault(require("./lib/rtrim")); - -var _trim = _interopRequireDefault(require("./lib/trim")); - -var _escape = _interopRequireDefault(require("./lib/escape")); - -var _unescape = _interopRequireDefault(require("./lib/unescape")); - -var _stripLow = _interopRequireDefault(require("./lib/stripLow")); - -var _whitelist = _interopRequireDefault(require("./lib/whitelist")); - -var _blacklist = _interopRequireDefault(require("./lib/blacklist")); - -var _isWhitelisted = _interopRequireDefault(require("./lib/isWhitelisted")); - -var _normalizeEmail = _interopRequireDefault(require("./lib/normalizeEmail")); - -var _isSlug = _interopRequireDefault(require("./lib/isSlug")); - -function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } - -function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -var version = '13.1.17'; -var validator = { - version: version, - toDate: _toDate.default, - toFloat: _toFloat.default, - toInt: _toInt.default, - toBoolean: _toBoolean.default, - equals: _equals.default, - contains: _contains.default, - matches: _matches.default, - isEmail: _isEmail.default, - isURL: _isURL.default, - isMACAddress: _isMACAddress.default, - isIP: _isIP.default, - isIPRange: _isIPRange.default, - isFQDN: _isFQDN.default, - isBoolean: _isBoolean.default, - isIBAN: _isIBAN.default, - isBIC: _isBIC.default, - isAlpha: _isAlpha.default, - isAlphaLocales: _isAlpha.locales, - isAlphanumeric: _isAlphanumeric.default, - isAlphanumericLocales: _isAlphanumeric.locales, - isNumeric: _isNumeric.default, - isPassportNumber: _isPassportNumber.default, - isPort: _isPort.default, - isLowercase: _isLowercase.default, - isUppercase: _isUppercase.default, - isAscii: _isAscii.default, - isFullWidth: _isFullWidth.default, - isHalfWidth: _isHalfWidth.default, - isVariableWidth: _isVariableWidth.default, - isMultibyte: _isMultibyte.default, - isSemVer: _isSemVer.default, - isSurrogatePair: _isSurrogatePair.default, - isInt: _isInt.default, - isIMEI: _isIMEI.default, - isFloat: _isFloat.default, - isFloatLocales: _isFloat.locales, - isDecimal: _isDecimal.default, - isHexadecimal: _isHexadecimal.default, - isOctal: _isOctal.default, - isDivisibleBy: _isDivisibleBy.default, - isHexColor: _isHexColor.default, - isRgbColor: _isRgbColor.default, - isHSL: _isHSL.default, - isISRC: _isISRC.default, - isMD5: _isMD.default, - isHash: _isHash.default, - isJWT: _isJWT.default, - isJSON: _isJSON.default, - isEmpty: _isEmpty.default, - isLength: _isLength.default, - isLocale: _isLocale.default, - isByteLength: _isByteLength.default, - isUUID: _isUUID.default, - isMongoId: _isMongoId.default, - isAfter: _isAfter.default, - isBefore: _isBefore.default, - isIn: _isIn.default, - isCreditCard: _isCreditCard.default, - isIdentityCard: _isIdentityCard.default, - isEAN: _isEAN.default, - isISIN: _isISIN.default, - isISBN: _isISBN.default, - isISSN: _isISSN.default, - isMobilePhone: _isMobilePhone.default, - isMobilePhoneLocales: _isMobilePhone.locales, - isPostalCode: _isPostalCode.default, - isPostalCodeLocales: _isPostalCode.locales, - isEthereumAddress: _isEthereumAddress.default, - isCurrency: _isCurrency.default, - isBtcAddress: _isBtcAddress.default, - isISO8601: _isISO.default, - isRFC3339: _isRFC.default, - isISO31661Alpha2: _isISO31661Alpha.default, - isISO31661Alpha3: _isISO31661Alpha2.default, - isBase32: _isBase.default, - isBase58: _isBase2.default, - isBase64: _isBase3.default, - isDataURI: _isDataURI.default, - isMagnetURI: _isMagnetURI.default, - isMimeType: _isMimeType.default, - isLatLong: _isLatLong.default, - ltrim: _ltrim.default, - rtrim: _rtrim.default, - trim: _trim.default, - escape: _escape.default, - unescape: _unescape.default, - stripLow: _stripLow.default, - whitelist: _whitelist.default, - blacklist: _blacklist.default, - isWhitelisted: _isWhitelisted.default, - normalizeEmail: _normalizeEmail.default, - toString: toString, - isSlug: _isSlug.default, - isTaxID: _isTaxID.default, - isDate: _isDate.default -}; -var _default = validator; -exports.default = _default; -module.exports = exports.default; -module.exports.default = exports.default; \ No newline at end of file diff --git a/package.json b/package.json index ae38132fb..d822d5344 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "build:es": "babel src -d es --env-name=es", "build:node": "babel src -d .", "build": "npm run build:browser && npm run build:node && npm run build:es", - "pretest": "npm run lint && npm run build", + "pretest": "npm run build && npm run lint", "test": "nyc mocha --require @babel/register --reporter dot", "test:ci": "nyc report --reporter=text-lcov" }, diff --git a/src/lib/alpha.js b/src/lib/alpha.js index a4c00c654..c898cacfe 100644 --- a/src/lib/alpha.js +++ b/src/lib/alpha.js @@ -68,7 +68,6 @@ export const alphanumeric = { export const decimal = { 'en-US': '.', ar: '٫', - fa: '٫', }; @@ -100,17 +99,16 @@ export const farsiLocales = [ for (let locale, i = 0; i < farsiLocales.length; i++) { locale = `fa-${farsiLocales[i]}`; - alpha[locale] = alpha.fa; alphanumeric[locale] = alphanumeric.fa; - decimal[locale] = decimal.fa; + decimal[locale] = decimal.ar; } // Source: https://en.wikipedia.org/wiki/Decimal_mark export const dotDecimal = ['ar-EG', 'ar-LB', 'ar-LY']; export const commaDecimal = [ - 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-ZM', 'es-ES', 'fr-FR', 'id-ID', 'it-IT', 'ku-IQ', 'hu-HU', 'nb-NO', - 'nn-NO', 'nl-NL', 'pl-PL', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS@latin', - 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN', + 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-ZM', 'es-ES', 'fr-CA', 'fr-FR', + 'id-ID', 'it-IT', 'ku-IQ', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-PL', 'pt-PT', + 'ru-RU', 'sl-SI', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN', ]; for (let i = 0; i < dotDecimal.length; i++) { @@ -121,8 +119,8 @@ for (let i = 0; i < commaDecimal.length; i++) { decimal[commaDecimal[i]] = ','; } -// see #1455 -alpha['fa-IR'] = alpha['fa-IR']; +alpha['fr-CA'] = alpha['fr-FR']; +alphanumeric['fr-CA'] = alphanumeric['fr-FR']; alpha['pt-BR'] = alpha['pt-PT']; alphanumeric['pt-BR'] = alphanumeric['pt-PT']; @@ -132,3 +130,6 @@ decimal['pt-BR'] = decimal['pt-PT']; alpha['pl-Pl'] = alpha['pl-PL']; alphanumeric['pl-Pl'] = alphanumeric['pl-PL']; decimal['pl-Pl'] = decimal['pl-PL']; + +// see #1455 +alpha['fa-AF'] = alpha.fa; diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index 107eb3457..119a4c14c 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -116,6 +116,7 @@ const phones = { // aliases phones['en-CA'] = phones['en-US']; +phones['fr-CA'] = phones['en-CA']; phones['fr-BE'] = phones['nl-BE']; phones['zh-HK'] = phones['en-HK']; phones['zh-MO'] = phones['en-MO']; diff --git a/test/sanitizers.js b/test/sanitizers.js index 505e11f95..00ec35ab9 100644 --- a/test/sanitizers.js +++ b/test/sanitizers.js @@ -268,6 +268,20 @@ describe('Sanitizers', () => { }); }); + it('should score passwords with default options', () => { + test({ + sanitizer: 'isStrongPassword', + expect: { + abc: false, + abcc: false, + aBc: false, + 'Abc123!': false, + '!@#$%^&*()': false, + 'abc123!@f#rA': true, + }, + }); + }); + it('should normalize an email based on domain', () => { test({ sanitizer: 'normalizeEmail', diff --git a/test/validators.js b/test/validators.js index 3dfee3c8d..383b2712d 100644 --- a/test/validators.js +++ b/test/validators.js @@ -2130,6 +2130,30 @@ describe('Validators', () => { }); }); + it('should validate numeric strings with locale', () => { + test({ + validator: 'isNumeric', + args: [{ + locale: 'fr-CA', + }], + valid: [ + '123', + '00123', + '-00123', + '0', + '-0', + '+123', + '123,123', + '+000000', + ], + invalid: [ + ' ', + '', + '.', + ], + }); + }); + it('should validate ports', () => { test({ validator: 'isPort', @@ -5944,6 +5968,17 @@ describe('Validators', () => { '+3361245789', ], }, + { + locale: 'fr-CA', + valid: ['19876543210', '8005552222', '+15673628910'], + invalid: [ + '564785', + '0123456789', + '1437439210', + '+10345672645', + '11435213543', + ], + }, { locale: 'fr-GF', valid: [