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