Skip to content

Commit

Permalink
chore: sync compiled versions
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Oct 4, 2020
1 parent 685c3d2 commit 26f3715
Show file tree
Hide file tree
Showing 14 changed files with 271 additions and 114 deletions.
2 changes: 2 additions & 0 deletions es/lib/alpha.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export var alpha = {
'en-US': /^[A-Z]+$/i,
'az-AZ': /^[A-VXYZÇƏĞİıÖŞÜ]+$/i,
'bg-BG': /^[А-Я]+$/i,
'cs-CZ': /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
'da-DK': /^[A-ZÆØÅ]+$/i,
Expand Down Expand Up @@ -30,6 +31,7 @@ export var alpha = {
};
export var alphanumeric = {
'en-US': /^[0-9A-Z]+$/i,
'az-AZ': /^[0-9A-VXYZÇƏĞİıÖŞÜ]+$/i,
'bg-BG': /^[0-9А-Я]+$/i,
'cs-CZ': /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
'da-DK': /^[0-9A-ZÆØÅ]+$/i,
Expand Down
37 changes: 30 additions & 7 deletions es/lib/isDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

import merge from './util/merge';
var default_date_options = {
format: 'YYYY/MM/DD',
delimiters: ['/', '-'],
strictMode: false
};

function isValidFormat(format) {
return /(^(y{4}|y{2})[\/-](m{1,2})[\/-](d{1,2})$)|(^(m{1,2})[\/-](d{1,2})[\/-]((y{4}|y{2})$))|(^(d{1,2})[\/-](m{1,2})[\/-]((y{4}|y{2})$))/gi.test(format);
}
Expand All @@ -27,13 +34,25 @@ function zip(date, format) {
return zippedArr;
}

export default function isDate(input) {
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'YYYY/MM/DD';
export default function isDate(input, options) {
if (typeof options === 'string') {
// Allow backward compatbility for old format isDate(input [, format])
options = merge({
format: options
}, default_date_options);
} else {
options = merge(options, default_date_options);
}

if (typeof input === 'string' && isValidFormat(format)) {
var splitter = /[-/]/,
dateAndFormat = zip(input.split(splitter), format.toLowerCase().split(splitter)),
dateObj = {};
if (typeof input === 'string' && isValidFormat(options.format)) {
var formatDelimiter = options.delimiters.find(function (delimiter) {
return options.format.indexOf(delimiter) !== -1;
});
var dateDelimiter = options.strictMode ? formatDelimiter : options.delimiters.find(function (delimiter) {
return input.indexOf(delimiter) !== -1;
});
var dateAndFormat = zip(input.split(dateDelimiter), options.format.toLowerCase().split(formatDelimiter));
var dateObj = {};

var _iterator = _createForOfIteratorHelper(dateAndFormat),
_step;
Expand All @@ -59,5 +78,9 @@ export default function isDate(input) {
return new Date("".concat(dateObj.m, "/").concat(dateObj.d, "/").concat(dateObj.y)).getDate() === +dateObj.d;
}

return Object.prototype.toString.call(input) === '[object Date]' && isFinite(input);
if (!options.strictMode) {
return Object.prototype.toString.call(input) === '[object Date]' && isFinite(input);
}

return false;
}
7 changes: 4 additions & 3 deletions es/lib/isEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var default_email_options = {
allow_display_name: false,
require_display_name: false,
allow_utf8_local_part: true,
require_tld: true
require_tld: true,
ignore_max_length: false
};
/* eslint-disable max-len */

Expand Down Expand Up @@ -138,11 +139,11 @@ export default function isEmail(str, options) {
}
}

if (!isByteLength(user, {
if (options.ignore_max_length === false && (!isByteLength(user, {
max: 64
}) || !isByteLength(domain, {
max: 254
})) {
}))) {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions es/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var phones = {
'en-ZA': /^(\+?27|0)\d{9}$/,
'en-ZM': /^(\+?26)?09[567]\d{7}$/,
'en-ZW': /^(\+263)[0-9]{9}$/,
'es-AR': /^\+?549(11|[2368]\d)\d{8}$/,
'es-CO': /^(\+?57)?([1-8]{1}|3[0-9]{2})?[2-9]{1}\d{6}$/,
'es-CL': /^(\+?56|0)[2-9]\d{1}\d{7}$/,
'es-CR': /^(\+506)?[2-8]\d{7}$/,
Expand Down
77 changes: 49 additions & 28 deletions es/lib/isTaxID.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len

import assertString from './util/assertString';
/**
* en-US TIN Validation
*
* An Employer Identification Number (EIN), also known as a Federal Tax Identification Number,
* is used to identify a business entity.
*
Expand All @@ -22,47 +24,61 @@ import assertString from './util/assertString';
* See `http://www.irs.gov/Businesses/Small-Businesses-&-Self-Employed/How-EINs-are-Assigned-and-Valid-EIN-Prefixes`
* for more information.
*/

/**
* Campus prefixes according to locales
*/

var campusPrefix = {
'en-US': {
andover: ['10', '12'],
atlanta: ['60', '67'],
austin: ['50', '53'],
brookhaven: ['01', '02', '03', '04', '05', '06', '11', '13', '14', '16', '21', '22', '23', '25', '34', '51', '52', '54', '55', '56', '57', '58', '59', '65'],
cincinnati: ['30', '32', '35', '36', '37', '38', '61'],
fresno: ['15', '24'],
internet: ['20', '26', '27', '45', '46', '47'],
kansas: ['40', '44'],
memphis: ['94', '95'],
ogden: ['80', '90'],
philadelphia: ['33', '39', '41', '42', '43', '46', '48', '62', '63', '64', '66', '68', '71', '72', '73', '74', '75', '76', '77', '81', '82', '83', '84', '85', '86', '87', '88', '91', '92', '93', '98', '99'],
sba: ['31']
}
};

function getPrefixes(locale) {
// Valid US IRS campus prefixes

var enUsCampusPrefix = {
andover: ['10', '12'],
atlanta: ['60', '67'],
austin: ['50', '53'],
brookhaven: ['01', '02', '03', '04', '05', '06', '11', '13', '14', '16', '21', '22', '23', '25', '34', '51', '52', '54', '55', '56', '57', '58', '59', '65'],
cincinnati: ['30', '32', '35', '36', '37', '38', '61'],
fresno: ['15', '24'],
internet: ['20', '26', '27', '45', '46', '47'],
kansas: ['40', '44'],
memphis: ['94', '95'],
ogden: ['80', '90'],
philadelphia: ['33', '39', '41', '42', '43', '46', '48', '62', '63', '64', '66', '68', '71', '72', '73', '74', '75', '76', '77', '81', '82', '83', '84', '85', '86', '87', '88', '91', '92', '93', '98', '99'],
sba: ['31']
}; // Return an array of all US IRS campus prefixes

function enUsGetPrefixes() {
var prefixes = [];

for (var location in campusPrefix[locale]) {
for (var location in enUsCampusPrefix) {
// https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
// istanbul ignore else
if (campusPrefix[locale].hasOwnProperty(location)) {
prefixes.push.apply(prefixes, _toConsumableArray(campusPrefix[locale][location]));
if (enUsCampusPrefix.hasOwnProperty(location)) {
prefixes.push.apply(prefixes, _toConsumableArray(enUsCampusPrefix[location]));
}
}

prefixes.sort();
return prefixes;
}
/*
* en-US validation function
* Verify that the TIN starts with a valid IRS campus prefix
*/


function enUsCheck(tin) {
return enUsGetPrefixes().indexOf(tin.substr(0, 2)) !== -1;
} // tax id regex formats for various locales


var taxIdFormat = {
'en-US': /^\d{2}[- ]{0,1}\d{7}$/
}; // Algorithmic tax id check functions for various locales

var taxIdCheck = {
'en-US': enUsCheck
};
/*
* Validator function
* Return true if the passed string is a valid tax identification number
* for the specified locale.
* Throw an error exception if the locale is not supported.
*/

export default function isTaxID(str) {
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
assertString(str);
Expand All @@ -72,7 +88,12 @@ export default function isTaxID(str) {
return false;
}

return getPrefixes(locale).indexOf(str.substr(0, 2)) !== -1;
if (locale in taxIdCheck) {
return taxIdCheck[locale](str);
} // Fallthrough; not all locales have algorithmic checks


return true;
}

throw new Error("Invalid locale '".concat(locale, "'"));
Expand Down
4 changes: 4 additions & 0 deletions es/lib/isURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require_protocol - if set as true isURL will return false if protocol is not pre
require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option
protocols - valid protocols can be modified with this option
require_host - if set as false isURL will not check if host is present in the URL
require_port - if set as true isURL will check if port is present in the URL
allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed
validate_length - if set as false isURL will skip string length validation (IE maximum is 2083)
Expand All @@ -19,6 +20,7 @@ var default_url_options = {
require_tld: true,
require_protocol: false,
require_host: true,
require_port: false,
require_valid_protocol: true,
allow_underscores: false,
allow_trailing_dot: false,
Expand Down Expand Up @@ -134,6 +136,8 @@ export default function isURL(url, options) {
if (!/^[0-9]+$/.test(port_str) || port <= 0 || port > 65535) {
return false;
}
} else if (options.require_port) {
return false;
}

if (!isIP(host) && !isFQDN(host, options) && (!ipv6 || !isIP(ipv6, 6))) {
Expand Down
2 changes: 2 additions & 0 deletions lib/alpha.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
exports.commaDecimal = exports.dotDecimal = exports.farsiLocales = exports.arabicLocales = exports.englishLocales = exports.decimal = exports.alphanumeric = exports.alpha = void 0;
var alpha = {
'en-US': /^[A-Z]+$/i,
'az-AZ': /^[A-VXYZÇƏĞİıÖŞÜ]+$/i,
'bg-BG': /^[А-Я]+$/i,
'cs-CZ': /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
'da-DK': /^[A-ZÆØÅ]+$/i,
Expand Down Expand Up @@ -37,6 +38,7 @@ var alpha = {
exports.alpha = alpha;
var alphanumeric = {
'en-US': /^[0-9A-Z]+$/i,
'az-AZ': /^[0-9A-VXYZÇƏĞİıÖŞÜ]+$/i,
'bg-BG': /^[0-9А-Я]+$/i,
'cs-CZ': /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
'da-DK': /^[0-9A-ZÆØÅ]+$/i,
Expand Down
40 changes: 33 additions & 7 deletions lib/isDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = isDate;

var _merge = _interopRequireDefault(require("./util/merge"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
Expand All @@ -19,6 +23,12 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

var default_date_options = {
format: 'YYYY/MM/DD',
delimiters: ['/', '-'],
strictMode: false
};

function isValidFormat(format) {
return /(^(y{4}|y{2})[\/-](m{1,2})[\/-](d{1,2})$)|(^(m{1,2})[\/-](d{1,2})[\/-]((y{4}|y{2})$))|(^(d{1,2})[\/-](m{1,2})[\/-]((y{4}|y{2})$))/gi.test(format);
}
Expand All @@ -34,13 +44,25 @@ function zip(date, format) {
return zippedArr;
}

function isDate(input) {
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'YYYY/MM/DD';
function isDate(input, options) {
if (typeof options === 'string') {
// Allow backward compatbility for old format isDate(input [, format])
options = (0, _merge.default)({
format: options
}, default_date_options);
} else {
options = (0, _merge.default)(options, default_date_options);
}

if (typeof input === 'string' && isValidFormat(format)) {
var splitter = /[-/]/,
dateAndFormat = zip(input.split(splitter), format.toLowerCase().split(splitter)),
dateObj = {};
if (typeof input === 'string' && isValidFormat(options.format)) {
var formatDelimiter = options.delimiters.find(function (delimiter) {
return options.format.indexOf(delimiter) !== -1;
});
var dateDelimiter = options.strictMode ? formatDelimiter : options.delimiters.find(function (delimiter) {
return input.indexOf(delimiter) !== -1;
});
var dateAndFormat = zip(input.split(dateDelimiter), options.format.toLowerCase().split(formatDelimiter));
var dateObj = {};

var _iterator = _createForOfIteratorHelper(dateAndFormat),
_step;
Expand All @@ -66,7 +88,11 @@ function isDate(input) {
return new Date("".concat(dateObj.m, "/").concat(dateObj.d, "/").concat(dateObj.y)).getDate() === +dateObj.d;
}

return Object.prototype.toString.call(input) === '[object Date]' && isFinite(input);
if (!options.strictMode) {
return Object.prototype.toString.call(input) === '[object Date]' && isFinite(input);
}

return false;
}

module.exports = exports.default;
Expand Down
7 changes: 4 additions & 3 deletions lib/isEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ var default_email_options = {
allow_display_name: false,
require_display_name: false,
allow_utf8_local_part: true,
require_tld: true
require_tld: true,
ignore_max_length: false
};
/* eslint-disable max-len */

Expand Down Expand Up @@ -152,11 +153,11 @@ function isEmail(str, options) {
}
}

if (!(0, _isByteLength.default)(user, {
if (options.ignore_max_length === false && (!(0, _isByteLength.default)(user, {
max: 64
}) || !(0, _isByteLength.default)(domain, {
max: 254
})) {
}))) {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var phones = {
'en-ZA': /^(\+?27|0)\d{9}$/,
'en-ZM': /^(\+?26)?09[567]\d{7}$/,
'en-ZW': /^(\+263)[0-9]{9}$/,
'es-AR': /^\+?549(11|[2368]\d)\d{8}$/,
'es-CO': /^(\+?57)?([1-8]{1}|3[0-9]{2})?[2-9]{1}\d{6}$/,
'es-CL': /^(\+?56|0)[2-9]\d{1}\d{7}$/,
'es-CR': /^(\+506)?[2-8]\d{7}$/,
Expand Down
Loading

0 comments on commit 26f3715

Please sign in to comment.