Skip to content

Commit

Permalink
feat: export isFloat locales
Browse files Browse the repository at this point in the history
This commit exports the list of supported locales for `isFloat`
as `isFloatLocales`

Ref: validatorjs#815, validatorjs#891, follow up for validatorjs#890
  • Loading branch information
profnandaa committed Sep 2, 2018
1 parent e11005c commit 2a333d9
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Validator | Description
**isEmail(str [, options])** | check if the string is an email.<br/><br/>`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 }`. If `allow_display_name` is set to true, the validator will also match `Display Name <email-address>`. If `require_display_name` is set to true, the validator will reject strings without the format `Display Name <email-address>`. 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 `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.
**isEmpty(str [, options])** | check if the string has a length of zero.<br/><br/>`options` is an object which defaults to `{ ignore_whitespace:false }`.
**isFQDN(str [, options])** | check if the string is a fully qualified domain name (e.g. domain.com).<br/><br/>`options` is an object which defaults to `{ require_tld: true, allow_underscores: false, allow_trailing_dot: false }`.
**isFloat(str [, options])** | check if the string is a float.<br/><br/>`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.<br/><br/>`min` and `max` are equivalent to 'greater or equal' and 'less or equal', respectively while `gt` and `lt` are their strict counterparts.<br/><br/>`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', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`.
**isFloat(str [, options])** | check if the string is a float.<br/><br/>`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.<br/><br/>`min` and `max` are equivalent to 'greater or equal' and 'less or equal', respectively while `gt` and `lt` are their strict counterparts.<br/><br/>`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', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`. Locale list is `validator.isFloatLocales`.
**isFullWidth(str)** | check if the string contains any full-width chars.
**isHalfWidth(str)** | check if the string contains any half-width chars.
**isHash(str, algorithm)** | check if the string is a hash of type algorithm.<br/><br/>Algorithm is one of `['md4', 'md5', 'sha1', 'sha256', 'sha384', 'sha512', 'ripemd128', 'ripemd160', 'tiger128', 'tiger160', 'tiger192', 'crc32', 'crc32b']`
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ var validator = {
isSurrogatePair: _isSurrogatePair2.default,
isInt: _isInt2.default,
isFloat: _isFloat2.default,
isFloatLocales: _isFloat.locales,
isDecimal: _isDecimal2.default,
isHexadecimal: _isHexadecimal2.default,
isDivisibleBy: _isDivisibleBy2.default,
Expand Down
4 changes: 3 additions & 1 deletion lib/isFloat.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.locales = undefined;
exports.default = isFloat;

var _assertString = require('./util/assertString');
Expand All @@ -23,4 +24,5 @@ function isFloat(str, options) {
var value = parseFloat(str.replace(',', '.'));
return float.test(str) && (!options.hasOwnProperty('min') || value >= options.min) && (!options.hasOwnProperty('max') || value <= options.max) && (!options.hasOwnProperty('lt') || value < options.lt) && (!options.hasOwnProperty('gt') || value > options.gt);
}
module.exports = exports['default'];

var locales = exports.locales = Object.keys(_alpha.decimal);
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import isMultibyte from './lib/isMultibyte';
import isSurrogatePair from './lib/isSurrogatePair';

import isInt from './lib/isInt';
import isFloat from './lib/isFloat';
import isFloat, { locales as isFloatLocales } from './lib/isFloat';
import isDecimal from './lib/isDecimal';
import isHexadecimal from './lib/isHexadecimal';
import isDivisibleBy from './lib/isDivisibleBy';
Expand Down Expand Up @@ -129,6 +129,7 @@ const validator = {
isSurrogatePair,
isInt,
isFloat,
isFloatLocales,
isDecimal,
isHexadecimal,
isDivisibleBy,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/isFloat.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ export default function isFloat(str, options) {
(!options.hasOwnProperty('lt') || value < options.lt) &&
(!options.hasOwnProperty('gt') || value > options.gt);
}

export const locales = Object.keys(decimal);
6 changes: 6 additions & 0 deletions test/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let isPostalCodeLocales = require('../lib/isPostalCode').locales;
const isAlphaLocales = require('../lib/isAlpha').locales;
const isAlphanumericLocales = require('../lib/isAlphanumeric').locales;
const isMobilePhoneLocales = require('../lib/isMobilePhone').locales;
const isFloatLocales = require('../lib/isFloat').locales;

describe('Exports', () => {
it('should export validators', () => {
Expand Down Expand Up @@ -44,4 +45,9 @@ describe('Exports', () => {
assert.ok(isMobilePhoneLocales instanceof Array);
assert.ok(validator.isMobilePhoneLocales instanceof Array);
});

it('should export isFloat\'s supported locales', () => {
assert.ok(isFloatLocales instanceof Array);
assert.ok(validator.isFloatLocales instanceof Array);
});
});
11 changes: 7 additions & 4 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,8 @@ function isFloat(str, options) {
return float.test(str) && (!options.hasOwnProperty('min') || value >= options.min) && (!options.hasOwnProperty('max') || value <= options.max) && (!options.hasOwnProperty('lt') || value < options.lt) && (!options.hasOwnProperty('gt') || value > options.gt);
}

var locales$2 = Object.keys(decimal);

var includes = function includes(arr, val) {
return arr.some(function (arrVal) {
return val === arrVal;
Expand Down Expand Up @@ -1155,7 +1157,7 @@ function isMobilePhone(str, locale, options) {
throw new Error('Invalid locale \'' + locale + '\'');
}

var locales$2 = Object.keys(phones);
var locales$3 = Object.keys(phones);

function currencyRegex(options) {
var decimal_digits = '\\d{' + options.digits_after_decimal[0] + '}';
Expand Down Expand Up @@ -1442,7 +1444,7 @@ var patterns = {
ZM: fiveDigit
};

var locales$3 = Object.keys(patterns);
var locales$4 = Object.keys(patterns);

var isPostalCode = function (str, locale) {
assertString(str);
Expand Down Expand Up @@ -1689,6 +1691,7 @@ var validator = {
isSurrogatePair: isSurrogatePair,
isInt: isInt,
isFloat: isFloat,
isFloatLocales: locales$2,
isDecimal: isDecimal,
isHexadecimal: isHexadecimal,
isDivisibleBy: isDivisibleBy,
Expand All @@ -1711,9 +1714,9 @@ var validator = {
isISBN: isISBN,
isISSN: isISSN,
isMobilePhone: isMobilePhone,
isMobilePhoneLocales: locales$2,
isMobilePhoneLocales: locales$3,
isPostalCode: isPostalCode,
isPostalCodeLocales: locales$3,
isPostalCodeLocales: locales$4,
isCurrency: isCurrency,
isISO8601: isISO8601,
isRFC3339: isRFC3339,
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit 2a333d9

Please sign in to comment.