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
package/lib/isTime.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isTime;
|
|
7
|
+
var _merge = _interopRequireDefault(require("./util/merge"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
var default_time_options = {
|
|
10
|
+
hourFormat: 'hour24',
|
|
11
|
+
mode: 'default'
|
|
12
|
+
};
|
|
13
|
+
var formats = {
|
|
14
|
+
hour24: {
|
|
15
|
+
default: /^([01]?[0-9]|2[0-3]):([0-5][0-9])$/,
|
|
16
|
+
withSeconds: /^([01]?[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/,
|
|
17
|
+
withOptionalSeconds: /^([01]?[0-9]|2[0-3]):([0-5][0-9])(?::([0-5][0-9]))?$/
|
|
18
|
+
},
|
|
19
|
+
hour12: {
|
|
20
|
+
default: /^(0?[1-9]|1[0-2]):([0-5][0-9]) (A|P)M$/,
|
|
21
|
+
withSeconds: /^(0?[1-9]|1[0-2]):([0-5][0-9]):([0-5][0-9]) (A|P)M$/,
|
|
22
|
+
withOptionalSeconds: /^(0?[1-9]|1[0-2]):([0-5][0-9])(?::([0-5][0-9]))? (A|P)M$/
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
function isTime(input, options) {
|
|
26
|
+
options = (0, _merge.default)(options, default_time_options);
|
|
27
|
+
if (typeof input !== 'string') return false;
|
|
28
|
+
return formats[options.hourFormat][options.mode].test(input);
|
|
29
|
+
}
|
|
30
|
+
module.exports = exports.default;
|
|
31
|
+
module.exports.default = exports.default;
|
package/lib/isULID.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isULID;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
function isULID(str) {
|
|
10
|
+
(0, _assertString.default)(str);
|
|
11
|
+
return /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i.test(str);
|
|
12
|
+
}
|
|
13
|
+
module.exports = exports.default;
|
|
14
|
+
module.exports.default = exports.default;
|
package/lib/isURL.js
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isURL;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
var _checkHost = _interopRequireDefault(require("./util/checkHost"));
|
|
9
|
+
var _includesString = _interopRequireDefault(require("./util/includesString"));
|
|
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
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
15
|
+
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."); }
|
|
16
|
+
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; } }
|
|
17
|
+
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; }
|
|
18
|
+
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; } }
|
|
19
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
20
|
+
/*
|
|
21
|
+
options for isURL method
|
|
22
|
+
|
|
23
|
+
protocols - valid protocols can be modified with this option.
|
|
24
|
+
require_tld - If set to false isURL will not check if the URL's host includes a top-level domain.
|
|
25
|
+
require_protocol - if set to true isURL will return false if protocol is not present in the URL.
|
|
26
|
+
require_host - if set to false isURL will not check if host is present in the URL.
|
|
27
|
+
require_port - if set to true isURL will check if port is present in the URL.
|
|
28
|
+
require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option.
|
|
29
|
+
allow_underscores - if set to true, the validator will allow underscores in the URL.
|
|
30
|
+
host_whitelist - if set to an array of strings or regexp, and the domain matches none of the strings
|
|
31
|
+
defined in it, the validation fails.
|
|
32
|
+
host_blacklist - if set to an array of strings or regexp, and the domain matches any of the strings
|
|
33
|
+
defined in it, the validation fails.
|
|
34
|
+
allow_trailing_dot - if set to true, the validator will allow the domain to end with
|
|
35
|
+
a `.` character.
|
|
36
|
+
allow_protocol_relative_urls - if set to true protocol relative URLs will be allowed.
|
|
37
|
+
allow_fragments - if set to false isURL will return false if fragments are present.
|
|
38
|
+
allow_query_components - if set to false isURL will return false if query components are present.
|
|
39
|
+
disallow_auth - if set to true, the validator will fail if the URL contains an authentication
|
|
40
|
+
component, e.g. `http://username:password@example.com`
|
|
41
|
+
validate_length - if set to false isURL will skip string length validation. `max_allowed_length`
|
|
42
|
+
will be ignored if this is set as `false`.
|
|
43
|
+
max_allowed_length - if set, isURL will not allow URLs longer than the specified value (default is
|
|
44
|
+
2084 that IE maximum URL length).
|
|
45
|
+
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
var default_url_options = {
|
|
49
|
+
protocols: ['http', 'https', 'ftp'],
|
|
50
|
+
require_tld: true,
|
|
51
|
+
require_protocol: false,
|
|
52
|
+
require_host: true,
|
|
53
|
+
require_port: false,
|
|
54
|
+
require_valid_protocol: true,
|
|
55
|
+
allow_underscores: false,
|
|
56
|
+
allow_trailing_dot: false,
|
|
57
|
+
allow_protocol_relative_urls: false,
|
|
58
|
+
allow_fragments: true,
|
|
59
|
+
allow_query_components: true,
|
|
60
|
+
validate_length: true,
|
|
61
|
+
max_allowed_length: 2084
|
|
62
|
+
};
|
|
63
|
+
var wrapped_ipv6 = /^\[([^\]]+)\](?::([0-9]+))?$/;
|
|
64
|
+
function isURL(url, options) {
|
|
65
|
+
(0, _assertString.default)(url);
|
|
66
|
+
if (!url || /[\s<>]/.test(url)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
if (url.indexOf('mailto:') === 0) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
options = (0, _merge.default)(options, default_url_options);
|
|
73
|
+
if (options.validate_length && url.length > options.max_allowed_length) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
if (!options.allow_fragments && (0, _includesString.default)(url, '#')) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
if (!options.allow_query_components && ((0, _includesString.default)(url, '?') || (0, _includesString.default)(url, '&'))) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
var protocol, auth, host, hostname, port, port_str, split, ipv6;
|
|
83
|
+
split = url.split('#');
|
|
84
|
+
url = split.shift();
|
|
85
|
+
split = url.split('?');
|
|
86
|
+
url = split.shift();
|
|
87
|
+
|
|
88
|
+
// Replaced the 'split("://")' logic with a regex to match the protocol.
|
|
89
|
+
// This correctly identifies schemes like `javascript:` which don't use `//`.
|
|
90
|
+
// However, we need to be careful not to confuse authentication credentials (user:password@host)
|
|
91
|
+
// with protocols. A colon before an @ symbol might be part of auth, not a protocol separator.
|
|
92
|
+
var protocol_match = url.match(/^([a-z][a-z0-9+\-.]*):/i);
|
|
93
|
+
var had_explicit_protocol = false;
|
|
94
|
+
var cleanUpProtocol = function cleanUpProtocol(potential_protocol) {
|
|
95
|
+
had_explicit_protocol = true;
|
|
96
|
+
protocol = potential_protocol.toLowerCase();
|
|
97
|
+
if (options.require_valid_protocol && options.protocols.indexOf(protocol) === -1) {
|
|
98
|
+
// The identified protocol is not in the allowed list.
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Remove the protocol from the URL string.
|
|
103
|
+
return url.substring(protocol_match[0].length);
|
|
104
|
+
};
|
|
105
|
+
if (protocol_match) {
|
|
106
|
+
var potential_protocol = protocol_match[1];
|
|
107
|
+
var after_colon = url.substring(protocol_match[0].length);
|
|
108
|
+
|
|
109
|
+
// Check if what follows looks like authentication credentials (user:password@host)
|
|
110
|
+
// rather than a protocol. This happens when:
|
|
111
|
+
// 1. There's no `//` after the colon (protocols like `http://` have this)
|
|
112
|
+
// 2. There's an `@` symbol before any `/`
|
|
113
|
+
// 3. The part before `@` contains only valid auth characters (alphanumeric, -, _, ., %, :)
|
|
114
|
+
var starts_with_slashes = after_colon.slice(0, 2) === '//';
|
|
115
|
+
if (!starts_with_slashes) {
|
|
116
|
+
var first_slash_position = after_colon.indexOf('/');
|
|
117
|
+
var before_slash = first_slash_position === -1 ? after_colon : after_colon.substring(0, first_slash_position);
|
|
118
|
+
var at_position = before_slash.indexOf('@');
|
|
119
|
+
if (at_position !== -1) {
|
|
120
|
+
var before_at = before_slash.substring(0, at_position);
|
|
121
|
+
var valid_auth_regex = /^[a-zA-Z0-9\-_.%:]*$/;
|
|
122
|
+
var is_valid_auth = valid_auth_regex.test(before_at);
|
|
123
|
+
|
|
124
|
+
// Check if this contains URL-encoded content that could be malicious
|
|
125
|
+
// For example: javascript:%61%6c%65%72%74%28%31%29@example.com
|
|
126
|
+
// The encoded part decodes to: alert(1)
|
|
127
|
+
var has_encoded_content = /%[0-9a-fA-F]{2}/.test(before_at);
|
|
128
|
+
if (is_valid_auth && !has_encoded_content) {
|
|
129
|
+
// This looks like authentication (e.g., user:password@host), not a protocol
|
|
130
|
+
if (options.require_protocol) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Don't consume the colon; let the auth parsing handle it later
|
|
135
|
+
} else {
|
|
136
|
+
// This looks like a malicious protocol (e.g., javascript:alert();@host)
|
|
137
|
+
// or URL-encoded protocol handler (e.g., javascript:%61%6c%65%72%74%28%31%29@host)
|
|
138
|
+
url = cleanUpProtocol(potential_protocol);
|
|
139
|
+
if (url === false) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
// No @ symbol found. Check if this could be a port number instead of a protocol.
|
|
145
|
+
// If what's after the colon is numeric (or starts with a digit and contains only
|
|
146
|
+
// valid port characters until a path separator), it's likely hostname:port, not a protocol.
|
|
147
|
+
var looks_like_port = /^[0-9]/.test(after_colon);
|
|
148
|
+
if (looks_like_port) {
|
|
149
|
+
// This looks like hostname:port, not a protocol
|
|
150
|
+
if (options.require_protocol) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
// Don't consume anything; let it be parsed as hostname:port
|
|
154
|
+
} else {
|
|
155
|
+
// This is definitely a protocol
|
|
156
|
+
url = cleanUpProtocol(potential_protocol);
|
|
157
|
+
if (url === false) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
// Starts with '//', this is definitely a protocol like http://
|
|
164
|
+
url = cleanUpProtocol(potential_protocol);
|
|
165
|
+
if (url === false) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
} else if (options.require_protocol) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Handle leading '//' only as protocol-relative when there was NO explicit protocol.
|
|
174
|
+
// If there was an explicit protocol, '//' is the normal separator
|
|
175
|
+
// and should be stripped unconditionally.
|
|
176
|
+
if (url.slice(0, 2) === '//') {
|
|
177
|
+
if (!had_explicit_protocol && !options.allow_protocol_relative_urls) {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
url = url.slice(2);
|
|
181
|
+
}
|
|
182
|
+
if (url === '') {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
split = url.split('/');
|
|
186
|
+
url = split.shift();
|
|
187
|
+
if (url === '' && !options.require_host) {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
split = url.split('@');
|
|
191
|
+
if (split.length > 1) {
|
|
192
|
+
if (options.disallow_auth) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
if (split[0] === '') {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
auth = split.shift();
|
|
199
|
+
if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
var _auth$split = auth.split(':'),
|
|
203
|
+
_auth$split2 = _slicedToArray(_auth$split, 2),
|
|
204
|
+
user = _auth$split2[0],
|
|
205
|
+
password = _auth$split2[1];
|
|
206
|
+
if (user === '' && password === '') {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
hostname = split.join('@');
|
|
211
|
+
port_str = null;
|
|
212
|
+
ipv6 = null;
|
|
213
|
+
var ipv6_match = hostname.match(wrapped_ipv6);
|
|
214
|
+
if (ipv6_match) {
|
|
215
|
+
host = '';
|
|
216
|
+
ipv6 = ipv6_match[1];
|
|
217
|
+
port_str = ipv6_match[2] || null;
|
|
218
|
+
} else {
|
|
219
|
+
split = hostname.split(':');
|
|
220
|
+
host = split.shift();
|
|
221
|
+
if (split.length) {
|
|
222
|
+
port_str = split.join(':');
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (port_str !== null && port_str.length > 0) {
|
|
226
|
+
port = parseInt(port_str, 10);
|
|
227
|
+
if (!/^[0-9]+$/.test(port_str) || port <= 0 || port > 65535) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
} else if (options.require_port) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
if (options.host_whitelist) {
|
|
234
|
+
return (0, _checkHost.default)(host, options.host_whitelist);
|
|
235
|
+
}
|
|
236
|
+
if (host === '' && !options.require_host) {
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
if (!(0, _isIP.default)(host) && !(0, _isFQDN.default)(host, options) && (!ipv6 || !(0, _isIP.default)(ipv6, 6))) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
host = host || ipv6;
|
|
243
|
+
if (options.host_blacklist && (0, _checkHost.default)(host, options.host_blacklist)) {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
module.exports = exports.default;
|
|
249
|
+
module.exports.default = exports.default;
|
package/lib/isUUID.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isUUID;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
var uuid = {
|
|
10
|
+
1: /^[0-9A-F]{8}-[0-9A-F]{4}-1[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
11
|
+
2: /^[0-9A-F]{8}-[0-9A-F]{4}-2[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
12
|
+
3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
13
|
+
4: /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
14
|
+
5: /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
15
|
+
6: /^[0-9A-F]{8}-[0-9A-F]{4}-6[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
16
|
+
7: /^[0-9A-F]{8}-[0-9A-F]{4}-7[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
17
|
+
8: /^[0-9A-F]{8}-[0-9A-F]{4}-8[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
18
|
+
nil: /^00000000-0000-0000-0000-000000000000$/i,
|
|
19
|
+
max: /^ffffffff-ffff-ffff-ffff-ffffffffffff$/i,
|
|
20
|
+
loose: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
|
|
21
|
+
// From https://github.com/uuidjs/uuid/blob/main/src/regex.js
|
|
22
|
+
all: /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i
|
|
23
|
+
};
|
|
24
|
+
function isUUID(str, version) {
|
|
25
|
+
(0, _assertString.default)(str);
|
|
26
|
+
if (version === undefined || version === null) {
|
|
27
|
+
version = 'all';
|
|
28
|
+
}
|
|
29
|
+
return version in uuid ? uuid[version].test(str) : false;
|
|
30
|
+
}
|
|
31
|
+
module.exports = exports.default;
|
|
32
|
+
module.exports.default = exports.default;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isUppercase;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
function isUppercase(str) {
|
|
10
|
+
(0, _assertString.default)(str);
|
|
11
|
+
return str === str.toUpperCase();
|
|
12
|
+
}
|
|
13
|
+
module.exports = exports.default;
|
|
14
|
+
module.exports.default = exports.default;
|
package/lib/isVAT.js
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = isVAT;
|
|
8
|
+
exports.vatMatchers = void 0;
|
|
9
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
10
|
+
var algorithms = _interopRequireWildcard(require("./util/algorithms"));
|
|
11
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
var AU = function AU(str) {
|
|
14
|
+
var match = str.match(/^(AU)?(\d{11})$/);
|
|
15
|
+
if (!match) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
// @see {@link https://abr.business.gov.au/Help/AbnFormat}
|
|
19
|
+
var weights = [10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19];
|
|
20
|
+
str = str.replace(/^AU/, '');
|
|
21
|
+
var ABN = (parseInt(str.slice(0, 1), 10) - 1).toString() + str.slice(1);
|
|
22
|
+
var total = 0;
|
|
23
|
+
for (var i = 0; i < 11; i++) {
|
|
24
|
+
total += weights[i] * ABN.charAt(i);
|
|
25
|
+
}
|
|
26
|
+
return total !== 0 && total % 89 === 0;
|
|
27
|
+
};
|
|
28
|
+
var CH = function CH(str) {
|
|
29
|
+
// @see {@link https://www.ech.ch/de/ech/ech-0097/5.2.0}
|
|
30
|
+
var hasValidCheckNumber = function hasValidCheckNumber(digits) {
|
|
31
|
+
var lastDigit = digits.pop(); // used as check number
|
|
32
|
+
var weights = [5, 4, 3, 2, 7, 6, 5, 4];
|
|
33
|
+
var calculatedCheckNumber = (11 - digits.reduce(function (acc, el, idx) {
|
|
34
|
+
return acc + el * weights[idx];
|
|
35
|
+
}, 0) % 11) % 11;
|
|
36
|
+
return lastDigit === calculatedCheckNumber;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// @see {@link https://www.estv.admin.ch/estv/de/home/mehrwertsteuer/uid/mwst-uid-nummer.html}
|
|
40
|
+
return /^(CHE[- ]?)?(\d{9}|(\d{3}\.\d{3}\.\d{3})|(\d{3} \d{3} \d{3})) ?(TVA|MWST|IVA)?$/.test(str) && hasValidCheckNumber(str.match(/\d/g).map(function (el) {
|
|
41
|
+
return +el;
|
|
42
|
+
}));
|
|
43
|
+
};
|
|
44
|
+
var PT = function PT(str) {
|
|
45
|
+
var match = str.match(/^(PT)?(\d{9})$/);
|
|
46
|
+
if (!match) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
var tin = match[2];
|
|
50
|
+
var checksum = 11 - algorithms.reverseMultiplyAndSum(tin.split('').slice(0, 8).map(function (a) {
|
|
51
|
+
return parseInt(a, 10);
|
|
52
|
+
}), 9) % 11;
|
|
53
|
+
if (checksum > 9) {
|
|
54
|
+
return parseInt(tin[8], 10) === 0;
|
|
55
|
+
}
|
|
56
|
+
return checksum === parseInt(tin[8], 10);
|
|
57
|
+
};
|
|
58
|
+
var vatMatchers = exports.vatMatchers = {
|
|
59
|
+
/**
|
|
60
|
+
* European Union VAT identification numbers
|
|
61
|
+
*/
|
|
62
|
+
AT: function AT(str) {
|
|
63
|
+
return /^(AT)?U\d{8}$/.test(str);
|
|
64
|
+
},
|
|
65
|
+
BE: function BE(str) {
|
|
66
|
+
return /^(BE)?\d{10}$/.test(str);
|
|
67
|
+
},
|
|
68
|
+
BG: function BG(str) {
|
|
69
|
+
return /^(BG)?\d{9,10}$/.test(str);
|
|
70
|
+
},
|
|
71
|
+
HR: function HR(str) {
|
|
72
|
+
return /^(HR)?\d{11}$/.test(str);
|
|
73
|
+
},
|
|
74
|
+
CY: function CY(str) {
|
|
75
|
+
return /^(CY)?\w{9}$/.test(str);
|
|
76
|
+
},
|
|
77
|
+
CZ: function CZ(str) {
|
|
78
|
+
return /^(CZ)?\d{8,10}$/.test(str);
|
|
79
|
+
},
|
|
80
|
+
DK: function DK(str) {
|
|
81
|
+
return /^(DK)?\d{8}$/.test(str);
|
|
82
|
+
},
|
|
83
|
+
EE: function EE(str) {
|
|
84
|
+
return /^(EE)?\d{9}$/.test(str);
|
|
85
|
+
},
|
|
86
|
+
FI: function FI(str) {
|
|
87
|
+
return /^(FI)?\d{8}$/.test(str);
|
|
88
|
+
},
|
|
89
|
+
FR: function FR(str) {
|
|
90
|
+
return /^(FR)([A-Z0-9]{2}\d{9})$/.test(str);
|
|
91
|
+
},
|
|
92
|
+
DE: function DE(str) {
|
|
93
|
+
return /^(DE)?\d{9}$/.test(str);
|
|
94
|
+
},
|
|
95
|
+
EL: function EL(str) {
|
|
96
|
+
return /^(EL)?\d{9}$/.test(str);
|
|
97
|
+
},
|
|
98
|
+
HU: function HU(str) {
|
|
99
|
+
return /^(HU)?\d{8}$/.test(str);
|
|
100
|
+
},
|
|
101
|
+
IE: function IE(str) {
|
|
102
|
+
return /^(IE)?\d{7}\w{1}(W)?$/.test(str);
|
|
103
|
+
},
|
|
104
|
+
IT: function IT(str) {
|
|
105
|
+
return /^(IT)?\d{11}$/.test(str);
|
|
106
|
+
},
|
|
107
|
+
LV: function LV(str) {
|
|
108
|
+
return /^(LV)?\d{11}$/.test(str);
|
|
109
|
+
},
|
|
110
|
+
LT: function LT(str) {
|
|
111
|
+
return /^(LT)?\d{9,12}$/.test(str);
|
|
112
|
+
},
|
|
113
|
+
LU: function LU(str) {
|
|
114
|
+
return /^(LU)?\d{8}$/.test(str);
|
|
115
|
+
},
|
|
116
|
+
MT: function MT(str) {
|
|
117
|
+
return /^(MT)?\d{8}$/.test(str);
|
|
118
|
+
},
|
|
119
|
+
NL: function NL(str) {
|
|
120
|
+
return /^(NL)?\d{9}B\d{2}$/.test(str);
|
|
121
|
+
},
|
|
122
|
+
PL: function PL(str) {
|
|
123
|
+
return /^(PL)?(\d{10}|(\d{3}-\d{3}-\d{2}-\d{2})|(\d{3}-\d{2}-\d{2}-\d{3}))$/.test(str);
|
|
124
|
+
},
|
|
125
|
+
PT: PT,
|
|
126
|
+
RO: function RO(str) {
|
|
127
|
+
return /^(RO)?\d{2,10}$/.test(str);
|
|
128
|
+
},
|
|
129
|
+
SK: function SK(str) {
|
|
130
|
+
return /^(SK)?\d{10}$/.test(str);
|
|
131
|
+
},
|
|
132
|
+
SI: function SI(str) {
|
|
133
|
+
return /^(SI)?\d{8}$/.test(str);
|
|
134
|
+
},
|
|
135
|
+
ES: function ES(str) {
|
|
136
|
+
return /^(ES)?\w\d{7}[A-Z]$/.test(str);
|
|
137
|
+
},
|
|
138
|
+
SE: function SE(str) {
|
|
139
|
+
return /^(SE)?\d{12}$/.test(str);
|
|
140
|
+
},
|
|
141
|
+
/**
|
|
142
|
+
* VAT numbers of non-EU countries
|
|
143
|
+
*/
|
|
144
|
+
AL: function AL(str) {
|
|
145
|
+
return /^(AL)?\w{9}[A-Z]$/.test(str);
|
|
146
|
+
},
|
|
147
|
+
MK: function MK(str) {
|
|
148
|
+
return /^(MK)?\d{13}$/.test(str);
|
|
149
|
+
},
|
|
150
|
+
AU: AU,
|
|
151
|
+
BY: function BY(str) {
|
|
152
|
+
return /^(УНП )?\d{9}$/.test(str);
|
|
153
|
+
},
|
|
154
|
+
CA: function CA(str) {
|
|
155
|
+
return /^(CA)?\d{9}$/.test(str);
|
|
156
|
+
},
|
|
157
|
+
IS: function IS(str) {
|
|
158
|
+
return /^(IS)?\d{5,6}$/.test(str);
|
|
159
|
+
},
|
|
160
|
+
IN: function IN(str) {
|
|
161
|
+
return /^(IN)?\d{15}$/.test(str);
|
|
162
|
+
},
|
|
163
|
+
ID: function ID(str) {
|
|
164
|
+
return /^(ID)?(\d{15}|(\d{2}.\d{3}.\d{3}.\d{1}-\d{3}.\d{3}))$/.test(str);
|
|
165
|
+
},
|
|
166
|
+
IL: function IL(str) {
|
|
167
|
+
return /^(IL)?\d{9}$/.test(str);
|
|
168
|
+
},
|
|
169
|
+
KZ: function KZ(str) {
|
|
170
|
+
return /^(KZ)?\d{12}$/.test(str);
|
|
171
|
+
},
|
|
172
|
+
NZ: function NZ(str) {
|
|
173
|
+
return /^(NZ)?\d{9}$/.test(str);
|
|
174
|
+
},
|
|
175
|
+
NG: function NG(str) {
|
|
176
|
+
return /^(NG)?(\d{12}|(\d{8}-\d{4}))$/.test(str);
|
|
177
|
+
},
|
|
178
|
+
NO: function NO(str) {
|
|
179
|
+
return /^(NO)?\d{9}MVA$/.test(str);
|
|
180
|
+
},
|
|
181
|
+
PH: function PH(str) {
|
|
182
|
+
return /^(PH)?(\d{12}|\d{3} \d{3} \d{3} \d{3})$/.test(str);
|
|
183
|
+
},
|
|
184
|
+
RU: function RU(str) {
|
|
185
|
+
return /^(RU)?(\d{10}|\d{12})$/.test(str);
|
|
186
|
+
},
|
|
187
|
+
SM: function SM(str) {
|
|
188
|
+
return /^(SM)?\d{5}$/.test(str);
|
|
189
|
+
},
|
|
190
|
+
SA: function SA(str) {
|
|
191
|
+
return /^(SA)?\d{15}$/.test(str);
|
|
192
|
+
},
|
|
193
|
+
RS: function RS(str) {
|
|
194
|
+
return /^(RS)?\d{9}$/.test(str);
|
|
195
|
+
},
|
|
196
|
+
CH: CH,
|
|
197
|
+
TR: function TR(str) {
|
|
198
|
+
return /^(TR)?\d{10}$/.test(str);
|
|
199
|
+
},
|
|
200
|
+
UA: function UA(str) {
|
|
201
|
+
return /^(UA)?\d{12}$/.test(str);
|
|
202
|
+
},
|
|
203
|
+
GB: function GB(str) {
|
|
204
|
+
return /^GB((\d{3} \d{4} ([0-8][0-9]|9[0-6]))|(\d{9} \d{3})|(((GD[0-4])|(HA[5-9]))[0-9]{2}))$/.test(str);
|
|
205
|
+
},
|
|
206
|
+
UZ: function UZ(str) {
|
|
207
|
+
return /^(UZ)?\d{9}$/.test(str);
|
|
208
|
+
},
|
|
209
|
+
/**
|
|
210
|
+
* VAT numbers of Latin American countries
|
|
211
|
+
*/
|
|
212
|
+
AR: function AR(str) {
|
|
213
|
+
return /^(AR)?\d{11}$/.test(str);
|
|
214
|
+
},
|
|
215
|
+
BO: function BO(str) {
|
|
216
|
+
return /^(BO)?\d{7}$/.test(str);
|
|
217
|
+
},
|
|
218
|
+
BR: function BR(str) {
|
|
219
|
+
return /^(BR)?((\d{2}.\d{3}.\d{3}\/\d{4}-\d{2})|(\d{3}.\d{3}.\d{3}-\d{2}))$/.test(str);
|
|
220
|
+
},
|
|
221
|
+
CL: function CL(str) {
|
|
222
|
+
return /^(CL)?\d{8}-\d{1}$/.test(str);
|
|
223
|
+
},
|
|
224
|
+
CO: function CO(str) {
|
|
225
|
+
return /^(CO)?\d{10}$/.test(str);
|
|
226
|
+
},
|
|
227
|
+
CR: function CR(str) {
|
|
228
|
+
return /^(CR)?\d{9,12}$/.test(str);
|
|
229
|
+
},
|
|
230
|
+
EC: function EC(str) {
|
|
231
|
+
return /^(EC)?\d{13}$/.test(str);
|
|
232
|
+
},
|
|
233
|
+
SV: function SV(str) {
|
|
234
|
+
return /^(SV)?\d{4}-\d{6}-\d{3}-\d{1}$/.test(str);
|
|
235
|
+
},
|
|
236
|
+
GT: function GT(str) {
|
|
237
|
+
return /^(GT)?\d{7}-\d{1}$/.test(str);
|
|
238
|
+
},
|
|
239
|
+
HN: function HN(str) {
|
|
240
|
+
return /^(HN)?$/.test(str);
|
|
241
|
+
},
|
|
242
|
+
MX: function MX(str) {
|
|
243
|
+
return /^(MX)?\w{3,4}\d{6}\w{3}$/.test(str);
|
|
244
|
+
},
|
|
245
|
+
NI: function NI(str) {
|
|
246
|
+
return /^(NI)?\d{3}-\d{6}-\d{4}\w{1}$/.test(str);
|
|
247
|
+
},
|
|
248
|
+
PA: function PA(str) {
|
|
249
|
+
return /^(PA)?$/.test(str);
|
|
250
|
+
},
|
|
251
|
+
PY: function PY(str) {
|
|
252
|
+
return /^(PY)?\d{6,8}-\d{1}$/.test(str);
|
|
253
|
+
},
|
|
254
|
+
PE: function PE(str) {
|
|
255
|
+
return /^(PE)?\d{11}$/.test(str);
|
|
256
|
+
},
|
|
257
|
+
DO: function DO(str) {
|
|
258
|
+
return /^(DO)?(\d{11}|(\d{3}-\d{7}-\d{1})|[1,4,5]{1}\d{8}|([1,4,5]{1})-\d{2}-\d{5}-\d{1})$/.test(str);
|
|
259
|
+
},
|
|
260
|
+
UY: function UY(str) {
|
|
261
|
+
return /^(UY)?\d{12}$/.test(str);
|
|
262
|
+
},
|
|
263
|
+
VE: function VE(str) {
|
|
264
|
+
return /^(VE)?[J,G,V,E]{1}-(\d{9}|(\d{8}-\d{1}))$/.test(str);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
function isVAT(str, countryCode) {
|
|
268
|
+
(0, _assertString.default)(str);
|
|
269
|
+
(0, _assertString.default)(countryCode);
|
|
270
|
+
if (countryCode in vatMatchers) {
|
|
271
|
+
return vatMatchers[countryCode](str);
|
|
272
|
+
}
|
|
273
|
+
throw new Error("Invalid country code: '".concat(countryCode, "'"));
|
|
274
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isVariableWidth;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
var _isFullWidth = require("./isFullWidth");
|
|
9
|
+
var _isHalfWidth = require("./isHalfWidth");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
function isVariableWidth(str) {
|
|
12
|
+
(0, _assertString.default)(str);
|
|
13
|
+
return _isFullWidth.fullWidth.test(str) && _isHalfWidth.halfWidth.test(str);
|
|
14
|
+
}
|
|
15
|
+
module.exports = exports.default;
|
|
16
|
+
module.exports.default = exports.default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isWhitelisted;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
function isWhitelisted(str, chars) {
|
|
10
|
+
(0, _assertString.default)(str);
|
|
11
|
+
for (var i = str.length - 1; i >= 0; i--) {
|
|
12
|
+
if (chars.indexOf(str[i]) === -1) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
module.exports = exports.default;
|
|
19
|
+
module.exports.default = exports.default;
|
package/lib/ltrim.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = ltrim;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
function ltrim(str, chars) {
|
|
10
|
+
(0, _assertString.default)(str);
|
|
11
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
|
|
12
|
+
var pattern = chars ? new RegExp("^[".concat(chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "]+"), 'g') : /^\s+/g;
|
|
13
|
+
return str.replace(pattern, '');
|
|
14
|
+
}
|
|
15
|
+
module.exports = exports.default;
|
|
16
|
+
module.exports.default = exports.default;
|