validator-string 13.15.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +269 -0
- package/es/index.js +218 -0
- package/es/lib/alpha.js +151 -0
- package/es/lib/blacklist.js +5 -0
- package/es/lib/contains.js +15 -0
- package/es/lib/equals.js +5 -0
- package/es/lib/escape.js +5 -0
- package/es/lib/isAbaRouting.js +15 -0
- package/es/lib/isAfter.js +10 -0
- package/es/lib/isAlpha.js +23 -0
- package/es/lib/isAlphanumeric.js +23 -0
- package/es/lib/isAscii.js +10 -0
- package/es/lib/isBIC.js +16 -0
- package/es/lib/isBase32.js +15 -0
- package/es/lib/isBase58.js +8 -0
- package/es/lib/isBase64.js +23 -0
- package/es/lib/isBefore.js +10 -0
- package/es/lib/isBoolean.js +15 -0
- package/es/lib/isBtcAddress.js +7 -0
- package/es/lib/isByteLength.js +19 -0
- package/es/lib/isCreditCard.js +43 -0
- package/es/lib/isCurrency.js +74 -0
- package/es/lib/isDataURI.js +31 -0
- package/es/lib/isDate.js +93 -0
- package/es/lib/isDecimal.js +22 -0
- package/es/lib/isDivisibleBy.js +6 -0
- package/es/lib/isEAN.js +70 -0
- package/es/lib/isEmail.js +165 -0
- package/es/lib/isEmpty.js +10 -0
- package/es/lib/isEthereumAddress.js +6 -0
- package/es/lib/isFQDN.js +67 -0
- package/es/lib/isFloat.js +14 -0
- package/es/lib/isFullWidth.js +6 -0
- package/es/lib/isHSL.js +13 -0
- package/es/lib/isHalfWidth.js +6 -0
- package/es/lib/isHash.js +21 -0
- package/es/lib/isHexColor.js +13 -0
- package/es/lib/isHexadecimal.js +6 -0
- package/es/lib/isIBAN.js +171 -0
- package/es/lib/isIMEI.js +40 -0
- package/es/lib/isIP.js +58 -0
- package/es/lib/isIPRange.js +41 -0
- package/es/lib/isISBN.js +47 -0
- package/es/lib/isISIN.js +55 -0
- package/es/lib/isISO15924.js +9 -0
- package/es/lib/isISO31661Alpha2.js +21 -0
- package/es/lib/isISO31661Alpha3.js +20 -0
- package/es/lib/isISO31661Numeric.js +8 -0
- package/es/lib/isISO4217.js +9 -0
- package/es/lib/isISO6346.js +28 -0
- package/es/lib/isISO6391.js +6 -0
- package/es/lib/isISO8601.js +42 -0
- package/es/lib/isISRC.js +8 -0
- package/es/lib/isISSN.js +19 -0
- package/es/lib/isIdentityCard.js +407 -0
- package/es/lib/isIn.js +23 -0
- package/es/lib/isInt.js +19 -0
- package/es/lib/isJSON.js +26 -0
- package/es/lib/isJWT.js +15 -0
- package/es/lib/isLatLong.js +21 -0
- package/es/lib/isLength.js +27 -0
- package/es/lib/isLicensePlate.js +58 -0
- package/es/lib/isLocale.js +107 -0
- package/es/lib/isLowercase.js +5 -0
- package/es/lib/isLuhnNumber.js +25 -0
- package/es/lib/isMACAddress.js +36 -0
- package/es/lib/isMD5.js +6 -0
- package/es/lib/isMagnetURI.js +9 -0
- package/es/lib/isMailtoURI.js +75 -0
- package/es/lib/isMimeType.js +40 -0
- package/es/lib/isMobilePhone.js +212 -0
- package/es/lib/isMongoId.js +6 -0
- package/es/lib/isMultibyte.js +10 -0
- package/es/lib/isNumeric.js +10 -0
- package/es/lib/isOctal.js +6 -0
- package/es/lib/isPassportNumber.js +145 -0
- package/es/lib/isPort.js +8 -0
- package/es/lib/isPostalCode.js +100 -0
- package/es/lib/isRFC3339.js +21 -0
- package/es/lib/isRgbColor.js +34 -0
- package/es/lib/isSemVer.js +14 -0
- package/es/lib/isSlug.js +6 -0
- package/es/lib/isStrongPassword.js +90 -0
- package/es/lib/isSurrogatePair.js +6 -0
- package/es/lib/isTaxID.js +1407 -0
- package/es/lib/isTime.js +22 -0
- package/es/lib/isULID.js +5 -0
- package/es/lib/isURL.js +241 -0
- package/es/lib/isUUID.js +23 -0
- package/es/lib/isUppercase.js +5 -0
- package/es/lib/isVAT.js +264 -0
- package/es/lib/isVariableWidth.js +7 -0
- package/es/lib/isWhitelisted.js +10 -0
- package/es/lib/ltrim.js +7 -0
- package/es/lib/matches.js +8 -0
- package/es/lib/normalizeEmail.js +131 -0
- package/es/lib/rtrim.js +15 -0
- package/es/lib/stripLow.js +7 -0
- package/es/lib/toBoolean.js +8 -0
- package/es/lib/toDate.js +6 -0
- package/es/lib/toFloat.js +5 -0
- package/es/lib/toInt.js +5 -0
- package/es/lib/trim.js +5 -0
- package/es/lib/unescape.js +8 -0
- package/es/lib/util/algorithms.js +79 -0
- package/es/lib/util/assertString.js +4 -0
- package/es/lib/util/checkHost.js +12 -0
- package/es/lib/util/includesArray.js +6 -0
- package/es/lib/util/includesString.js +4 -0
- package/es/lib/util/merge.js +14 -0
- package/es/lib/util/multilineRegex.js +12 -0
- package/es/lib/util/nullUndefinedCheck.js +3 -0
- package/es/lib/util/toString.js +13 -0
- package/es/lib/util/typeOf.js +10 -0
- package/es/lib/whitelist.js +5 -0
- package/index.js +229 -0
- package/lib/alpha.js +157 -0
- package/lib/blacklist.js +14 -0
- package/lib/contains.js +24 -0
- package/lib/equals.js +14 -0
- package/lib/escape.js +14 -0
- package/lib/isAbaRouting.js +23 -0
- package/lib/isAfter.js +19 -0
- package/lib/isAlpha.js +31 -0
- package/lib/isAlphanumeric.js +31 -0
- package/lib/isAscii.js +18 -0
- package/lib/isBIC.js +24 -0
- package/lib/isBase32.js +24 -0
- package/lib/isBase58.js +16 -0
- package/lib/isBase64.js +32 -0
- package/lib/isBefore.js +19 -0
- package/lib/isBoolean.js +24 -0
- package/lib/isBtcAddress.js +16 -0
- package/lib/isByteLength.js +27 -0
- package/lib/isCreditCard.js +52 -0
- package/lib/isCurrency.js +83 -0
- package/lib/isDataURI.js +40 -0
- package/lib/isDate.js +102 -0
- package/lib/isDecimal.js +31 -0
- package/lib/isDivisibleBy.js +15 -0
- package/lib/isEAN.js +78 -0
- package/lib/isEmail.js +174 -0
- package/lib/isEmpty.js +19 -0
- package/lib/isEthereumAddress.js +15 -0
- package/lib/isFQDN.js +76 -0
- package/lib/isFloat.js +22 -0
- package/lib/isFullWidth.js +14 -0
- package/lib/isHSL.js +22 -0
- package/lib/isHalfWidth.js +14 -0
- package/lib/isHash.js +30 -0
- package/lib/isHexColor.js +22 -0
- package/lib/isHexadecimal.js +15 -0
- package/lib/isIBAN.js +178 -0
- package/lib/isIMEI.js +49 -0
- package/lib/isIP.js +67 -0
- package/lib/isIPRange.js +50 -0
- package/lib/isISBN.js +56 -0
- package/lib/isISIN.js +64 -0
- package/lib/isISO15924.js +16 -0
- package/lib/isISO31661Alpha2.js +28 -0
- package/lib/isISO31661Alpha3.js +28 -0
- package/lib/isISO31661Numeric.js +16 -0
- package/lib/isISO4217.js +16 -0
- package/lib/isISO6346.js +35 -0
- package/lib/isISO6391.js +15 -0
- package/lib/isISO8601.js +50 -0
- package/lib/isISRC.js +16 -0
- package/lib/isISSN.js +28 -0
- package/lib/isIdentityCard.js +416 -0
- package/lib/isIn.js +32 -0
- package/lib/isInt.js +28 -0
- package/lib/isJSON.js +35 -0
- package/lib/isJWT.js +24 -0
- package/lib/isLatLong.js +30 -0
- package/lib/isLength.js +35 -0
- package/lib/isLicensePlate.js +67 -0
- package/lib/isLocale.js +115 -0
- package/lib/isLowercase.js +14 -0
- package/lib/isLuhnNumber.js +34 -0
- package/lib/isMACAddress.js +45 -0
- package/lib/isMD5.js +15 -0
- package/lib/isMagnetURI.js +18 -0
- package/lib/isMailtoURI.js +84 -0
- package/lib/isMimeType.js +48 -0
- package/lib/isMobilePhone.js +219 -0
- package/lib/isMongoId.js +15 -0
- package/lib/isMultibyte.js +18 -0
- package/lib/isNumeric.js +19 -0
- package/lib/isOctal.js +15 -0
- package/lib/isPassportNumber.js +152 -0
- package/lib/isPort.js +17 -0
- package/lib/isPostalCode.js +107 -0
- package/lib/isRFC3339.js +29 -0
- package/lib/isRgbColor.js +42 -0
- package/lib/isSemVer.js +22 -0
- package/lib/isSlug.js +15 -0
- package/lib/isStrongPassword.js +99 -0
- package/lib/isSurrogatePair.js +15 -0
- package/lib/isTaxID.js +1417 -0
- package/lib/isTime.js +31 -0
- package/lib/isULID.js +14 -0
- package/lib/isURL.js +249 -0
- package/lib/isUUID.js +32 -0
- package/lib/isUppercase.js +14 -0
- package/lib/isVAT.js +274 -0
- package/lib/isVariableWidth.js +16 -0
- package/lib/isWhitelisted.js +19 -0
- package/lib/ltrim.js +16 -0
- package/lib/matches.js +17 -0
- package/lib/normalizeEmail.js +140 -0
- package/lib/rtrim.js +24 -0
- package/lib/stripLow.js +16 -0
- package/lib/toBoolean.js +17 -0
- package/lib/toDate.js +15 -0
- package/lib/toFloat.js +14 -0
- package/lib/toInt.js +14 -0
- package/lib/trim.js +14 -0
- package/lib/unescape.js +17 -0
- package/lib/util/algorithms.js +88 -0
- package/lib/util/assertString.js +12 -0
- package/lib/util/checkHost.js +20 -0
- package/lib/util/includesArray.js +14 -0
- package/lib/util/includesString.js +12 -0
- package/lib/util/merge.js +22 -0
- package/lib/util/multilineRegex.js +20 -0
- package/lib/util/nullUndefinedCheck.js +11 -0
- package/lib/util/toString.js +21 -0
- package/lib/util/typeOf.js +18 -0
- package/lib/whitelist.js +14 -0
- package/package.json +83 -0
- package/validator.js +5808 -0
- package/validator.min.js +23 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isCurrency;
|
|
7
|
+
var _merge = _interopRequireDefault(require("./util/merge"));
|
|
8
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
function currencyRegex(options) {
|
|
11
|
+
var decimal_digits = "\\d{".concat(options.digits_after_decimal[0], "}");
|
|
12
|
+
options.digits_after_decimal.forEach(function (digit, index) {
|
|
13
|
+
if (index !== 0) decimal_digits = "".concat(decimal_digits, "|\\d{").concat(digit, "}");
|
|
14
|
+
});
|
|
15
|
+
var symbol = "(".concat(options.symbol.replace(/\W/, function (m) {
|
|
16
|
+
return "\\".concat(m);
|
|
17
|
+
}), ")").concat(options.require_symbol ? '' : '?'),
|
|
18
|
+
negative = '-?',
|
|
19
|
+
whole_dollar_amount_without_sep = '[1-9]\\d*',
|
|
20
|
+
whole_dollar_amount_with_sep = "[1-9]\\d{0,2}(\\".concat(options.thousands_separator, "\\d{3})*"),
|
|
21
|
+
valid_whole_dollar_amounts = ['0', whole_dollar_amount_without_sep, whole_dollar_amount_with_sep],
|
|
22
|
+
whole_dollar_amount = "(".concat(valid_whole_dollar_amounts.join('|'), ")?"),
|
|
23
|
+
decimal_amount = "(\\".concat(options.decimal_separator, "(").concat(decimal_digits, "))").concat(options.require_decimal ? '' : '?');
|
|
24
|
+
var pattern = whole_dollar_amount + (options.allow_decimal || options.require_decimal ? decimal_amount : '');
|
|
25
|
+
|
|
26
|
+
// default is negative sign before symbol, but there are two other options (besides parens)
|
|
27
|
+
if (options.allow_negatives && !options.parens_for_negatives) {
|
|
28
|
+
if (options.negative_sign_after_digits) {
|
|
29
|
+
pattern += negative;
|
|
30
|
+
} else if (options.negative_sign_before_digits) {
|
|
31
|
+
pattern = negative + pattern;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// South African Rand, for example, uses R 123 (space) and R-123 (no space)
|
|
36
|
+
if (options.allow_negative_sign_placeholder) {
|
|
37
|
+
pattern = "( (?!\\-))?".concat(pattern);
|
|
38
|
+
} else if (options.allow_space_after_symbol) {
|
|
39
|
+
pattern = " ?".concat(pattern);
|
|
40
|
+
} else if (options.allow_space_after_digits) {
|
|
41
|
+
pattern += '( (?!$))?';
|
|
42
|
+
}
|
|
43
|
+
if (options.symbol_after_digits) {
|
|
44
|
+
pattern += symbol;
|
|
45
|
+
} else {
|
|
46
|
+
pattern = symbol + pattern;
|
|
47
|
+
}
|
|
48
|
+
if (options.allow_negatives) {
|
|
49
|
+
if (options.parens_for_negatives) {
|
|
50
|
+
pattern = "(\\(".concat(pattern, "\\)|").concat(pattern, ")");
|
|
51
|
+
} else if (!(options.negative_sign_before_digits || options.negative_sign_after_digits)) {
|
|
52
|
+
pattern = negative + pattern;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ensure there's a dollar and/or decimal amount, and that
|
|
57
|
+
// it doesn't start with a space or a negative sign followed by a space
|
|
58
|
+
return new RegExp("^(?!-? )(?=.*\\d)".concat(pattern, "$"));
|
|
59
|
+
}
|
|
60
|
+
var default_currency_options = {
|
|
61
|
+
symbol: '$',
|
|
62
|
+
require_symbol: false,
|
|
63
|
+
allow_space_after_symbol: false,
|
|
64
|
+
symbol_after_digits: false,
|
|
65
|
+
allow_negatives: true,
|
|
66
|
+
parens_for_negatives: false,
|
|
67
|
+
negative_sign_before_digits: false,
|
|
68
|
+
negative_sign_after_digits: false,
|
|
69
|
+
allow_negative_sign_placeholder: false,
|
|
70
|
+
thousands_separator: ',',
|
|
71
|
+
decimal_separator: '.',
|
|
72
|
+
allow_decimal: true,
|
|
73
|
+
require_decimal: false,
|
|
74
|
+
digits_after_decimal: [2],
|
|
75
|
+
allow_space_after_digits: false
|
|
76
|
+
};
|
|
77
|
+
function isCurrency(str, options) {
|
|
78
|
+
(0, _assertString.default)(str);
|
|
79
|
+
options = (0, _merge.default)(options, default_currency_options);
|
|
80
|
+
return currencyRegex(options).test(str);
|
|
81
|
+
}
|
|
82
|
+
module.exports = exports.default;
|
|
83
|
+
module.exports.default = exports.default;
|
package/lib/isDataURI.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isDataURI;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
var validMediaType = /^[a-z]+\/[a-z0-9\-\+\._]+$/i;
|
|
10
|
+
var validAttribute = /^[a-z\-]+=[a-z0-9\-]+$/i;
|
|
11
|
+
var validData = /^[a-z0-9!\$&'\(\)\*\+,;=\-\._~:@\/\?%\s]*$/i;
|
|
12
|
+
function isDataURI(str) {
|
|
13
|
+
(0, _assertString.default)(str);
|
|
14
|
+
var data = str.split(',');
|
|
15
|
+
if (data.length < 2) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
var attributes = data.shift().trim().split(';');
|
|
19
|
+
var schemeAndMediaType = attributes.shift();
|
|
20
|
+
if (schemeAndMediaType.slice(0, 5) !== 'data:') {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
var mediaType = schemeAndMediaType.slice(5);
|
|
24
|
+
if (mediaType !== '' && !validMediaType.test(mediaType)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
for (var i = 0; i < attributes.length; i++) {
|
|
28
|
+
if (!(i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64') && !validAttribute.test(attributes[i])) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
for (var _i = 0; _i < data.length; _i++) {
|
|
33
|
+
if (!validData.test(data[_i])) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
module.exports = exports.default;
|
|
40
|
+
module.exports.default = exports.default;
|
package/lib/isDate.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isDate;
|
|
7
|
+
var _merge = _interopRequireDefault(require("./util/merge"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
10
|
+
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."); }
|
|
11
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
12
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
13
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
14
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
15
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
16
|
+
var default_date_options = {
|
|
17
|
+
format: 'YYYY/MM/DD',
|
|
18
|
+
delimiters: ['/', '-'],
|
|
19
|
+
strictMode: false
|
|
20
|
+
};
|
|
21
|
+
function isValidFormat(format) {
|
|
22
|
+
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);
|
|
23
|
+
}
|
|
24
|
+
function zip(date, format) {
|
|
25
|
+
var zippedArr = [],
|
|
26
|
+
len = Math.max(date.length, format.length);
|
|
27
|
+
for (var i = 0; i < len; i++) {
|
|
28
|
+
zippedArr.push([date[i], format[i]]);
|
|
29
|
+
}
|
|
30
|
+
return zippedArr;
|
|
31
|
+
}
|
|
32
|
+
function isDate(input, options) {
|
|
33
|
+
if (typeof options === 'string') {
|
|
34
|
+
// Allow backward compatibility for old format isDate(input [, format])
|
|
35
|
+
options = (0, _merge.default)({
|
|
36
|
+
format: options
|
|
37
|
+
}, default_date_options);
|
|
38
|
+
} else {
|
|
39
|
+
options = (0, _merge.default)(options, default_date_options);
|
|
40
|
+
}
|
|
41
|
+
if (typeof input === 'string' && isValidFormat(options.format)) {
|
|
42
|
+
if (options.strictMode && input.length !== options.format.length) return false;
|
|
43
|
+
var formatDelimiter = options.delimiters.find(function (delimiter) {
|
|
44
|
+
return options.format.indexOf(delimiter) !== -1;
|
|
45
|
+
});
|
|
46
|
+
var dateDelimiter = options.strictMode ? formatDelimiter : options.delimiters.find(function (delimiter) {
|
|
47
|
+
return input.indexOf(delimiter) !== -1;
|
|
48
|
+
});
|
|
49
|
+
var dateAndFormat = zip(input.split(dateDelimiter), options.format.toLowerCase().split(formatDelimiter));
|
|
50
|
+
var dateObj = {};
|
|
51
|
+
var _iterator = _createForOfIteratorHelper(dateAndFormat),
|
|
52
|
+
_step;
|
|
53
|
+
try {
|
|
54
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
55
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
56
|
+
dateWord = _step$value[0],
|
|
57
|
+
formatWord = _step$value[1];
|
|
58
|
+
if (!dateWord || !formatWord || dateWord.length !== formatWord.length) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
dateObj[formatWord.charAt(0)] = dateWord;
|
|
62
|
+
}
|
|
63
|
+
} catch (err) {
|
|
64
|
+
_iterator.e(err);
|
|
65
|
+
} finally {
|
|
66
|
+
_iterator.f();
|
|
67
|
+
}
|
|
68
|
+
var fullYear = dateObj.y;
|
|
69
|
+
|
|
70
|
+
// Check if the year starts with a hyphen
|
|
71
|
+
if (fullYear.startsWith('-')) {
|
|
72
|
+
return false; // Hyphen before year is not allowed
|
|
73
|
+
}
|
|
74
|
+
if (dateObj.y.length === 2) {
|
|
75
|
+
var parsedYear = parseInt(dateObj.y, 10);
|
|
76
|
+
if (isNaN(parsedYear)) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
var currentYearLastTwoDigits = new Date().getFullYear() % 100;
|
|
80
|
+
if (parsedYear < currentYearLastTwoDigits) {
|
|
81
|
+
fullYear = "20".concat(dateObj.y);
|
|
82
|
+
} else {
|
|
83
|
+
fullYear = "19".concat(dateObj.y);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
var month = dateObj.m;
|
|
87
|
+
if (dateObj.m.length === 1) {
|
|
88
|
+
month = "0".concat(dateObj.m);
|
|
89
|
+
}
|
|
90
|
+
var day = dateObj.d;
|
|
91
|
+
if (dateObj.d.length === 1) {
|
|
92
|
+
day = "0".concat(dateObj.d);
|
|
93
|
+
}
|
|
94
|
+
return new Date("".concat(fullYear, "-").concat(month, "-").concat(day, "T00:00:00.000Z")).getUTCDate() === +dateObj.d;
|
|
95
|
+
}
|
|
96
|
+
if (!options.strictMode) {
|
|
97
|
+
return Object.prototype.toString.call(input) === '[object Date]' && isFinite(input);
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
module.exports = exports.default;
|
|
102
|
+
module.exports.default = exports.default;
|
package/lib/isDecimal.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isDecimal;
|
|
7
|
+
var _merge = _interopRequireDefault(require("./util/merge"));
|
|
8
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
9
|
+
var _includesArray = _interopRequireDefault(require("./util/includesArray"));
|
|
10
|
+
var _alpha = require("./alpha");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
function decimalRegExp(options) {
|
|
13
|
+
var regExp = new RegExp("^[-+]?([0-9]+)?(\\".concat(_alpha.decimal[options.locale], "[0-9]{").concat(options.decimal_digits, "})").concat(options.force_decimal ? '' : '?', "$"));
|
|
14
|
+
return regExp;
|
|
15
|
+
}
|
|
16
|
+
var default_decimal_options = {
|
|
17
|
+
force_decimal: false,
|
|
18
|
+
decimal_digits: '1,',
|
|
19
|
+
locale: 'en-US'
|
|
20
|
+
};
|
|
21
|
+
var blacklist = ['', '-', '+'];
|
|
22
|
+
function isDecimal(str, options) {
|
|
23
|
+
(0, _assertString.default)(str);
|
|
24
|
+
options = (0, _merge.default)(options, default_decimal_options);
|
|
25
|
+
if (options.locale in _alpha.decimal) {
|
|
26
|
+
return !(0, _includesArray.default)(blacklist, str.replace(/ /g, '')) && decimalRegExp(options).test(str);
|
|
27
|
+
}
|
|
28
|
+
throw new Error("Invalid locale '".concat(options.locale, "'"));
|
|
29
|
+
}
|
|
30
|
+
module.exports = exports.default;
|
|
31
|
+
module.exports.default = exports.default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isDivisibleBy;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
var _toFloat = _interopRequireDefault(require("./toFloat"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
function isDivisibleBy(str, num) {
|
|
11
|
+
(0, _assertString.default)(str);
|
|
12
|
+
return (0, _toFloat.default)(str) % parseInt(num, 10) === 0;
|
|
13
|
+
}
|
|
14
|
+
module.exports = exports.default;
|
|
15
|
+
module.exports.default = exports.default;
|
package/lib/isEAN.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isEAN;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
/**
|
|
10
|
+
* The most commonly used EAN standard is
|
|
11
|
+
* the thirteen-digit EAN-13, while the
|
|
12
|
+
* less commonly used 8-digit EAN-8 barcode was
|
|
13
|
+
* introduced for use on small packages.
|
|
14
|
+
* Also EAN/UCC-14 is used for Grouping of individual
|
|
15
|
+
* trade items above unit level(Intermediate, Carton or Pallet).
|
|
16
|
+
* For more info about EAN-14 checkout: https://www.gtin.info/itf-14-barcodes/
|
|
17
|
+
* EAN consists of:
|
|
18
|
+
* GS1 prefix, manufacturer code, product code and check digit
|
|
19
|
+
* Reference: https://en.wikipedia.org/wiki/International_Article_Number
|
|
20
|
+
* Reference: https://www.gtin.info/
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Define EAN Lengths; 8 for EAN-8; 13 for EAN-13; 14 for EAN-14
|
|
25
|
+
* and Regular Expression for valid EANs (EAN-8, EAN-13, EAN-14),
|
|
26
|
+
* with exact numeric matching of 8 or 13 or 14 digits [0-9]
|
|
27
|
+
*/
|
|
28
|
+
var LENGTH_EAN_8 = 8;
|
|
29
|
+
var LENGTH_EAN_14 = 14;
|
|
30
|
+
var validEanRegex = /^(\d{8}|\d{13}|\d{14})$/;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Get position weight given:
|
|
34
|
+
* EAN length and digit index/position
|
|
35
|
+
*
|
|
36
|
+
* @param {number} length
|
|
37
|
+
* @param {number} index
|
|
38
|
+
* @return {number}
|
|
39
|
+
*/
|
|
40
|
+
function getPositionWeightThroughLengthAndIndex(length, index) {
|
|
41
|
+
if (length === LENGTH_EAN_8 || length === LENGTH_EAN_14) {
|
|
42
|
+
return index % 2 === 0 ? 3 : 1;
|
|
43
|
+
}
|
|
44
|
+
return index % 2 === 0 ? 1 : 3;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Calculate EAN Check Digit
|
|
49
|
+
* Reference: https://en.wikipedia.org/wiki/International_Article_Number#Calculation_of_checksum_digit
|
|
50
|
+
*
|
|
51
|
+
* @param {string} ean
|
|
52
|
+
* @return {number}
|
|
53
|
+
*/
|
|
54
|
+
function calculateCheckDigit(ean) {
|
|
55
|
+
var checksum = ean.slice(0, -1).split('').map(function (char, index) {
|
|
56
|
+
return Number(char) * getPositionWeightThroughLengthAndIndex(ean.length, index);
|
|
57
|
+
}).reduce(function (acc, partialSum) {
|
|
58
|
+
return acc + partialSum;
|
|
59
|
+
}, 0);
|
|
60
|
+
var remainder = 10 - checksum % 10;
|
|
61
|
+
return remainder < 10 ? remainder : 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Check if string is valid EAN:
|
|
66
|
+
* Matches EAN-8/EAN-13/EAN-14 regex
|
|
67
|
+
* Has valid check digit.
|
|
68
|
+
*
|
|
69
|
+
* @param {string} str
|
|
70
|
+
* @return {boolean}
|
|
71
|
+
*/
|
|
72
|
+
function isEAN(str) {
|
|
73
|
+
(0, _assertString.default)(str);
|
|
74
|
+
var actualCheckDigit = Number(str.slice(-1));
|
|
75
|
+
return validEanRegex.test(str) && actualCheckDigit === calculateCheckDigit(str);
|
|
76
|
+
}
|
|
77
|
+
module.exports = exports.default;
|
|
78
|
+
module.exports.default = exports.default;
|
package/lib/isEmail.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isEmail;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
var _checkHost = _interopRequireDefault(require("./util/checkHost"));
|
|
9
|
+
var _isByteLength = _interopRequireDefault(require("./isByteLength"));
|
|
10
|
+
var _isFQDN = _interopRequireDefault(require("./isFQDN"));
|
|
11
|
+
var _isIP = _interopRequireDefault(require("./isIP"));
|
|
12
|
+
var _merge = _interopRequireDefault(require("./util/merge"));
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
var default_email_options = {
|
|
15
|
+
allow_display_name: false,
|
|
16
|
+
allow_underscores: false,
|
|
17
|
+
require_display_name: false,
|
|
18
|
+
allow_utf8_local_part: true,
|
|
19
|
+
require_tld: true,
|
|
20
|
+
blacklisted_chars: '',
|
|
21
|
+
ignore_max_length: false,
|
|
22
|
+
host_blacklist: [],
|
|
23
|
+
host_whitelist: []
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/* eslint-disable max-len */
|
|
27
|
+
/* eslint-disable no-control-regex */
|
|
28
|
+
var splitNameAddress = /^([^\x00-\x1F\x7F-\x9F\cX]+)</i;
|
|
29
|
+
var emailUserPart = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i;
|
|
30
|
+
var gmailUserPart = /^[a-z\d]+$/;
|
|
31
|
+
var quotedEmailUser = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i;
|
|
32
|
+
var emailUserUtf8Part = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A1-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i;
|
|
33
|
+
var quotedEmailUserUtf8 = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i;
|
|
34
|
+
var defaultMaxEmailLength = 254;
|
|
35
|
+
/* eslint-enable max-len */
|
|
36
|
+
/* eslint-enable no-control-regex */
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Validate display name according to the RFC2822: https://tools.ietf.org/html/rfc2822#appendix-A.1.2
|
|
40
|
+
* @param {String} display_name
|
|
41
|
+
*/
|
|
42
|
+
function validateDisplayName(display_name) {
|
|
43
|
+
var display_name_without_quotes = display_name.replace(/^"(.+)"$/, '$1');
|
|
44
|
+
// display name with only spaces is not valid
|
|
45
|
+
if (!display_name_without_quotes.trim()) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// check whether display name contains illegal character
|
|
50
|
+
var contains_illegal = /[\.";<>]/.test(display_name_without_quotes);
|
|
51
|
+
if (contains_illegal) {
|
|
52
|
+
// if contains illegal characters,
|
|
53
|
+
// must to be enclosed in double-quotes, otherwise it's not a valid display name
|
|
54
|
+
if (display_name_without_quotes === display_name) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// the quotes in display name must start with character symbol \
|
|
59
|
+
var all_start_with_back_slash = display_name_without_quotes.split('"').length === display_name_without_quotes.split('\\"').length;
|
|
60
|
+
if (!all_start_with_back_slash) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
function isEmail(str, options) {
|
|
67
|
+
(0, _assertString.default)(str);
|
|
68
|
+
options = (0, _merge.default)(options, default_email_options);
|
|
69
|
+
if (options.require_display_name || options.allow_display_name) {
|
|
70
|
+
var display_email = str.match(splitNameAddress);
|
|
71
|
+
if (display_email) {
|
|
72
|
+
var display_name = display_email[1];
|
|
73
|
+
|
|
74
|
+
// Remove display name and angle brackets to get email address
|
|
75
|
+
// Can be done in the regex but will introduce a ReDOS (See #1597 for more info)
|
|
76
|
+
str = str.replace(display_name, '').replace(/(^<|>$)/g, '');
|
|
77
|
+
|
|
78
|
+
// sometimes need to trim the last space to get the display name
|
|
79
|
+
// because there may be a space between display name and email address
|
|
80
|
+
// eg. myname <address@gmail.com>
|
|
81
|
+
// the display name is `myname` instead of `myname `, so need to trim the last space
|
|
82
|
+
if (display_name.endsWith(' ')) {
|
|
83
|
+
display_name = display_name.slice(0, -1);
|
|
84
|
+
}
|
|
85
|
+
if (!validateDisplayName(display_name)) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
} else if (options.require_display_name) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!options.ignore_max_length && str.length > defaultMaxEmailLength) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
var parts = str.split('@');
|
|
96
|
+
var domain = parts.pop();
|
|
97
|
+
var lower_domain = domain.toLowerCase();
|
|
98
|
+
if (options.host_blacklist.length > 0 && (0, _checkHost.default)(lower_domain, options.host_blacklist)) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
if (options.host_whitelist.length > 0 && !(0, _checkHost.default)(lower_domain, options.host_whitelist)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
var user = parts.join('@');
|
|
105
|
+
if (options.domain_specific_validation && (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com')) {
|
|
106
|
+
/*
|
|
107
|
+
Previously we removed dots for gmail addresses before validating.
|
|
108
|
+
This was removed because it allows `multiple..dots@gmail.com`
|
|
109
|
+
to be reported as valid, but it is not.
|
|
110
|
+
Gmail only normalizes single dots, removing them from here is pointless,
|
|
111
|
+
should be done in normalizeEmail
|
|
112
|
+
*/
|
|
113
|
+
user = user.toLowerCase();
|
|
114
|
+
|
|
115
|
+
// Removing sub-address from username before gmail validation
|
|
116
|
+
var username = user.split('+')[0];
|
|
117
|
+
|
|
118
|
+
// Dots are not included in gmail length restriction
|
|
119
|
+
if (!(0, _isByteLength.default)(username.replace(/\./g, ''), {
|
|
120
|
+
min: 6,
|
|
121
|
+
max: 30
|
|
122
|
+
})) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
var _user_parts = username.split('.');
|
|
126
|
+
for (var i = 0; i < _user_parts.length; i++) {
|
|
127
|
+
if (!gmailUserPart.test(_user_parts[i])) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (options.ignore_max_length === false && (!(0, _isByteLength.default)(user, {
|
|
133
|
+
max: 64
|
|
134
|
+
}) || !(0, _isByteLength.default)(domain, {
|
|
135
|
+
max: 254
|
|
136
|
+
}))) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
if (!(0, _isFQDN.default)(domain, {
|
|
140
|
+
require_tld: options.require_tld,
|
|
141
|
+
ignore_max_length: options.ignore_max_length,
|
|
142
|
+
allow_underscores: options.allow_underscores
|
|
143
|
+
})) {
|
|
144
|
+
if (!options.allow_ip_domain) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
if (!(0, _isIP.default)(domain)) {
|
|
148
|
+
if (!domain.startsWith('[') || !domain.endsWith(']')) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
var noBracketdomain = domain.slice(1, -1);
|
|
152
|
+
if (noBracketdomain.length === 0 || !(0, _isIP.default)(noBracketdomain)) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (options.blacklisted_chars) {
|
|
158
|
+
if (user.search(new RegExp("[".concat(options.blacklisted_chars, "]+"), 'g')) !== -1) return false;
|
|
159
|
+
}
|
|
160
|
+
if (user[0] === '"' && user[user.length - 1] === '"') {
|
|
161
|
+
user = user.slice(1, user.length - 1);
|
|
162
|
+
return options.allow_utf8_local_part ? quotedEmailUserUtf8.test(user) : quotedEmailUser.test(user);
|
|
163
|
+
}
|
|
164
|
+
var pattern = options.allow_utf8_local_part ? emailUserUtf8Part : emailUserPart;
|
|
165
|
+
var user_parts = user.split('.');
|
|
166
|
+
for (var _i = 0; _i < user_parts.length; _i++) {
|
|
167
|
+
if (!pattern.test(user_parts[_i])) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
module.exports = exports.default;
|
|
174
|
+
module.exports.default = exports.default;
|
package/lib/isEmpty.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isEmpty;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
var _merge = _interopRequireDefault(require("./util/merge"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
var default_is_empty_options = {
|
|
11
|
+
ignore_whitespace: false
|
|
12
|
+
};
|
|
13
|
+
function isEmpty(str, options) {
|
|
14
|
+
(0, _assertString.default)(str);
|
|
15
|
+
options = (0, _merge.default)(options, default_is_empty_options);
|
|
16
|
+
return (options.ignore_whitespace ? str.trim().length : str.length) === 0;
|
|
17
|
+
}
|
|
18
|
+
module.exports = exports.default;
|
|
19
|
+
module.exports.default = exports.default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isEthereumAddress;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
var eth = /^(0x)[0-9a-f]{40}$/i;
|
|
10
|
+
function isEthereumAddress(str) {
|
|
11
|
+
(0, _assertString.default)(str);
|
|
12
|
+
return eth.test(str);
|
|
13
|
+
}
|
|
14
|
+
module.exports = exports.default;
|
|
15
|
+
module.exports.default = exports.default;
|
package/lib/isFQDN.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isFQDN;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
var _merge = _interopRequireDefault(require("./util/merge"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
var default_fqdn_options = {
|
|
11
|
+
require_tld: true,
|
|
12
|
+
allow_underscores: false,
|
|
13
|
+
allow_trailing_dot: false,
|
|
14
|
+
allow_numeric_tld: false,
|
|
15
|
+
allow_wildcard: false,
|
|
16
|
+
ignore_max_length: false
|
|
17
|
+
};
|
|
18
|
+
function isFQDN(str, options) {
|
|
19
|
+
(0, _assertString.default)(str);
|
|
20
|
+
options = (0, _merge.default)(options, default_fqdn_options);
|
|
21
|
+
|
|
22
|
+
/* Remove the optional trailing dot before checking validity */
|
|
23
|
+
if (options.allow_trailing_dot && str[str.length - 1] === '.') {
|
|
24
|
+
str = str.substring(0, str.length - 1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* Remove the optional wildcard before checking validity */
|
|
28
|
+
if (options.allow_wildcard === true && str.indexOf('*.') === 0) {
|
|
29
|
+
str = str.substring(2);
|
|
30
|
+
}
|
|
31
|
+
var parts = str.split('.');
|
|
32
|
+
var tld = parts[parts.length - 1];
|
|
33
|
+
if (options.require_tld) {
|
|
34
|
+
// disallow fqdns without tld
|
|
35
|
+
if (parts.length < 2) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (!options.allow_numeric_tld && !/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// disallow spaces
|
|
43
|
+
if (/\s/.test(tld)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// reject numeric TLDs
|
|
49
|
+
if (!options.allow_numeric_tld && /^\d+$/.test(tld)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return parts.every(function (part) {
|
|
53
|
+
if (part.length > 63 && !options.ignore_max_length) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(part)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// disallow full-width chars
|
|
61
|
+
if (/[\uff01-\uff5e]/.test(part)) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// disallow parts starting or ending with hyphen
|
|
66
|
+
if (/^-|-$/.test(part)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
if (!options.allow_underscores && /_/.test(part)) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
module.exports = exports.default;
|
|
76
|
+
module.exports.default = exports.default;
|
package/lib/isFloat.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isFloat;
|
|
7
|
+
exports.locales = void 0;
|
|
8
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
9
|
+
var _nullUndefinedCheck = _interopRequireDefault(require("./util/nullUndefinedCheck"));
|
|
10
|
+
var _alpha = require("./alpha");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
function isFloat(str, options) {
|
|
13
|
+
(0, _assertString.default)(str);
|
|
14
|
+
options = options || {};
|
|
15
|
+
var float = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\".concat(options.locale ? _alpha.decimal[options.locale] : '.', "[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$"));
|
|
16
|
+
if (str === '' || str === '.' || str === ',' || str === '-' || str === '+') {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
var value = parseFloat(str.replace(',', '.'));
|
|
20
|
+
return float.test(str) && (!options.hasOwnProperty('min') || (0, _nullUndefinedCheck.default)(options.min) || value >= options.min) && (!options.hasOwnProperty('max') || (0, _nullUndefinedCheck.default)(options.max) || value <= options.max) && (!options.hasOwnProperty('lt') || (0, _nullUndefinedCheck.default)(options.lt) || value < options.lt) && (!options.hasOwnProperty('gt') || (0, _nullUndefinedCheck.default)(options.gt) || value > options.gt);
|
|
21
|
+
}
|
|
22
|
+
var locales = exports.locales = Object.keys(_alpha.decimal);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isFullWidth;
|
|
7
|
+
exports.fullWidth = void 0;
|
|
8
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
var fullWidth = exports.fullWidth = /[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;
|
|
11
|
+
function isFullWidth(str) {
|
|
12
|
+
(0, _assertString.default)(str);
|
|
13
|
+
return fullWidth.test(str);
|
|
14
|
+
}
|