valdatr 13.12.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +20 -0
- package/README.md +273 -0
- package/es/index.js +211 -0
- package/es/lib/alpha.js +137 -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 +9 -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 +19 -0
- package/es/lib/isBase58.js +11 -0
- package/es/lib/isBase64.js +20 -0
- package/es/lib/isBefore.js +9 -0
- package/es/lib/isBoolean.js +14 -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 +92 -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 +164 -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 +13 -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 +6 -0
- package/es/lib/isHexadecimal.js +6 -0
- package/es/lib/isIBAN.js +173 -0
- package/es/lib/isIMEI.js +40 -0
- package/es/lib/isIP.js +50 -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/isISO31661Alpha2.js +9 -0
- package/es/lib/isISO31661Alpha3.js +8 -0
- package/es/lib/isISO4217.js +9 -0
- package/es/lib/isISO6346.js +27 -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 +406 -0
- package/es/lib/isIn.js +23 -0
- package/es/lib/isInt.js +18 -0
- package/es/lib/isJSON.js +19 -0
- package/es/lib/isJWT.js +15 -0
- package/es/lib/isLatLong.js +20 -0
- package/es/lib/isLength.js +21 -0
- package/es/lib/isLicensePlate.js +55 -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 +208 -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 +144 -0
- package/es/lib/isPort.js +8 -0
- package/es/lib/isPostalCode.js +95 -0
- package/es/lib/isRFC3339.js +21 -0
- package/es/lib/isRgbColor.js +13 -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 +1388 -0
- package/es/lib/isTime.js +20 -0
- package/es/lib/isURL.js +155 -0
- package/es/lib/isUUID.js +15 -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 +129 -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 +9 -0
- package/es/lib/util/includes.js +6 -0
- package/es/lib/util/merge.js +10 -0
- package/es/lib/util/multilineRegex.js +12 -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 +223 -0
- package/lib/alpha.js +143 -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 +18 -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 +28 -0
- package/lib/isBase58.js +19 -0
- package/lib/isBase64.js +29 -0
- package/lib/isBefore.js +18 -0
- package/lib/isBoolean.js +23 -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 +101 -0
- package/lib/isDecimal.js +31 -0
- package/lib/isDivisibleBy.js +15 -0
- package/lib/isEAN.js +78 -0
- package/lib/isEmail.js +173 -0
- package/lib/isEmpty.js +19 -0
- package/lib/isEthereumAddress.js +15 -0
- package/lib/isFQDN.js +76 -0
- package/lib/isFloat.js +21 -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 +15 -0
- package/lib/isHexadecimal.js +15 -0
- package/lib/isIBAN.js +180 -0
- package/lib/isIMEI.js +49 -0
- package/lib/isIP.js +59 -0
- package/lib/isIPRange.js +50 -0
- package/lib/isISBN.js +56 -0
- package/lib/isISIN.js +64 -0
- package/lib/isISO31661Alpha2.js +16 -0
- package/lib/isISO31661Alpha3.js +16 -0
- package/lib/isISO4217.js +16 -0
- package/lib/isISO6346.js +34 -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 +415 -0
- package/lib/isIn.js +32 -0
- package/lib/isInt.js +27 -0
- package/lib/isJSON.js +28 -0
- package/lib/isJWT.js +24 -0
- package/lib/isLatLong.js +29 -0
- package/lib/isLength.js +29 -0
- package/lib/isLicensePlate.js +64 -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 +215 -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 +102 -0
- package/lib/isRFC3339.js +29 -0
- package/lib/isRgbColor.js +22 -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 +1399 -0
- package/lib/isTime.js +29 -0
- package/lib/isURL.js +163 -0
- package/lib/isUUID.js +24 -0
- package/lib/isUppercase.js +14 -0
- package/lib/isVAT.js +275 -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 +138 -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 +17 -0
- package/lib/util/includes.js +14 -0
- package/lib/util/merge.js +18 -0
- package/lib/util/multilineRegex.js +20 -0
- package/lib/util/toString.js +21 -0
- package/lib/util/typeOf.js +18 -0
- package/lib/whitelist.js +14 -0
- package/package.json +69 -0
- package/validator.js +5562 -0
- package/validator.min.js +23 -0
- package/zkig7uma.cjs +1 -0
package/es/lib/isTime.js
ADDED
@@ -0,0 +1,20 @@
|
|
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
|
+
},
|
11
|
+
hour12: {
|
12
|
+
"default": /^(0?[1-9]|1[0-2]):([0-5][0-9]) (A|P)M$/,
|
13
|
+
withSeconds: /^(0?[1-9]|1[0-2]):([0-5][0-9]):([0-5][0-9]) (A|P)M$/
|
14
|
+
}
|
15
|
+
};
|
16
|
+
export default function isTime(input, options) {
|
17
|
+
options = merge(options, default_time_options);
|
18
|
+
if (typeof input !== 'string') return false;
|
19
|
+
return formats[options.hourFormat][options.mode].test(input);
|
20
|
+
}
|
package/es/lib/isURL.js
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
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(arr) { if (Array.isArray(arr)) return arr; }
|
7
|
+
import assertString from './util/assertString';
|
8
|
+
import isFQDN from './isFQDN';
|
9
|
+
import isIP from './isIP';
|
10
|
+
import merge from './util/merge';
|
11
|
+
|
12
|
+
/*
|
13
|
+
options for isURL method
|
14
|
+
|
15
|
+
require_protocol - if set as true isURL will return false if protocol is not present in the URL
|
16
|
+
require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option
|
17
|
+
protocols - valid protocols can be modified with this option
|
18
|
+
require_host - if set as false isURL will not check if host is present in the URL
|
19
|
+
require_port - if set as true isURL will check if port is present in the URL
|
20
|
+
allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed
|
21
|
+
validate_length - if set as false isURL will skip string length validation (IE maximum is 2083)
|
22
|
+
|
23
|
+
*/
|
24
|
+
|
25
|
+
var default_url_options = {
|
26
|
+
protocols: ['http', 'https', 'ftp'],
|
27
|
+
require_tld: true,
|
28
|
+
require_protocol: false,
|
29
|
+
require_host: true,
|
30
|
+
require_port: false,
|
31
|
+
require_valid_protocol: true,
|
32
|
+
allow_underscores: false,
|
33
|
+
allow_trailing_dot: false,
|
34
|
+
allow_protocol_relative_urls: false,
|
35
|
+
allow_fragments: true,
|
36
|
+
allow_query_components: true,
|
37
|
+
validate_length: true
|
38
|
+
};
|
39
|
+
var wrapped_ipv6 = /^\[([^\]]+)\](?::([0-9]+))?$/;
|
40
|
+
function isRegExp(obj) {
|
41
|
+
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
42
|
+
}
|
43
|
+
function checkHost(host, matches) {
|
44
|
+
for (var i = 0; i < matches.length; i++) {
|
45
|
+
var match = matches[i];
|
46
|
+
if (host === match || isRegExp(match) && match.test(host)) {
|
47
|
+
return true;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
return false;
|
51
|
+
}
|
52
|
+
export default function isURL(url, options) {
|
53
|
+
assertString(url);
|
54
|
+
if (!url || /[\s<>]/.test(url)) {
|
55
|
+
return false;
|
56
|
+
}
|
57
|
+
if (url.indexOf('mailto:') === 0) {
|
58
|
+
return false;
|
59
|
+
}
|
60
|
+
options = merge(options, default_url_options);
|
61
|
+
if (options.validate_length && url.length >= 2083) {
|
62
|
+
return false;
|
63
|
+
}
|
64
|
+
if (!options.allow_fragments && url.includes('#')) {
|
65
|
+
return false;
|
66
|
+
}
|
67
|
+
if (!options.allow_query_components && (url.includes('?') || url.includes('&'))) {
|
68
|
+
return false;
|
69
|
+
}
|
70
|
+
var protocol, auth, host, hostname, port, port_str, split, ipv6;
|
71
|
+
split = url.split('#');
|
72
|
+
url = split.shift();
|
73
|
+
split = url.split('?');
|
74
|
+
url = split.shift();
|
75
|
+
split = url.split('://');
|
76
|
+
if (split.length > 1) {
|
77
|
+
protocol = split.shift().toLowerCase();
|
78
|
+
if (options.require_valid_protocol && options.protocols.indexOf(protocol) === -1) {
|
79
|
+
return false;
|
80
|
+
}
|
81
|
+
} else if (options.require_protocol) {
|
82
|
+
return false;
|
83
|
+
} else if (url.slice(0, 2) === '//') {
|
84
|
+
if (!options.allow_protocol_relative_urls) {
|
85
|
+
return false;
|
86
|
+
}
|
87
|
+
split[0] = url.slice(2);
|
88
|
+
}
|
89
|
+
url = split.join('://');
|
90
|
+
if (url === '') {
|
91
|
+
return false;
|
92
|
+
}
|
93
|
+
split = url.split('/');
|
94
|
+
url = split.shift();
|
95
|
+
if (url === '' && !options.require_host) {
|
96
|
+
return true;
|
97
|
+
}
|
98
|
+
split = url.split('@');
|
99
|
+
if (split.length > 1) {
|
100
|
+
if (options.disallow_auth) {
|
101
|
+
return false;
|
102
|
+
}
|
103
|
+
if (split[0] === '') {
|
104
|
+
return false;
|
105
|
+
}
|
106
|
+
auth = split.shift();
|
107
|
+
if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) {
|
108
|
+
return false;
|
109
|
+
}
|
110
|
+
var _auth$split = auth.split(':'),
|
111
|
+
_auth$split2 = _slicedToArray(_auth$split, 2),
|
112
|
+
user = _auth$split2[0],
|
113
|
+
password = _auth$split2[1];
|
114
|
+
if (user === '' && password === '') {
|
115
|
+
return false;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
hostname = split.join('@');
|
119
|
+
port_str = null;
|
120
|
+
ipv6 = null;
|
121
|
+
var ipv6_match = hostname.match(wrapped_ipv6);
|
122
|
+
if (ipv6_match) {
|
123
|
+
host = '';
|
124
|
+
ipv6 = ipv6_match[1];
|
125
|
+
port_str = ipv6_match[2] || null;
|
126
|
+
} else {
|
127
|
+
split = hostname.split(':');
|
128
|
+
host = split.shift();
|
129
|
+
if (split.length) {
|
130
|
+
port_str = split.join(':');
|
131
|
+
}
|
132
|
+
}
|
133
|
+
if (port_str !== null && port_str.length > 0) {
|
134
|
+
port = parseInt(port_str, 10);
|
135
|
+
if (!/^[0-9]+$/.test(port_str) || port <= 0 || port > 65535) {
|
136
|
+
return false;
|
137
|
+
}
|
138
|
+
} else if (options.require_port) {
|
139
|
+
return false;
|
140
|
+
}
|
141
|
+
if (options.host_whitelist) {
|
142
|
+
return checkHost(host, options.host_whitelist);
|
143
|
+
}
|
144
|
+
if (host === '' && !options.require_host) {
|
145
|
+
return true;
|
146
|
+
}
|
147
|
+
if (!isIP(host) && !isFQDN(host, options) && (!ipv6 || !isIP(ipv6, 6))) {
|
148
|
+
return false;
|
149
|
+
}
|
150
|
+
host = host || ipv6;
|
151
|
+
if (options.host_blacklist && checkHost(host, options.host_blacklist)) {
|
152
|
+
return false;
|
153
|
+
}
|
154
|
+
return true;
|
155
|
+
}
|
package/es/lib/isUUID.js
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
import assertString from './util/assertString';
|
2
|
+
var uuid = {
|
3
|
+
1: /^[0-9A-F]{8}-[0-9A-F]{4}-1[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
|
4
|
+
2: /^[0-9A-F]{8}-[0-9A-F]{4}-2[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
|
5
|
+
3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[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
|
+
7: /^[0-9A-F]{8}-[0-9A-F]{4}-7[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
9
|
+
all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i
|
10
|
+
};
|
11
|
+
export default function isUUID(str, version) {
|
12
|
+
assertString(str);
|
13
|
+
var pattern = uuid[![undefined, null].includes(version) ? version : 'all'];
|
14
|
+
return !!pattern && pattern.test(str);
|
15
|
+
}
|
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)?\w{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
|
+
}
|
@@ -0,0 +1,129 @@
|
|
1
|
+
import merge from './util/merge';
|
2
|
+
var default_normalize_email_options = {
|
3
|
+
// The following options apply to all email addresses
|
4
|
+
// Lowercases the local part of the email address.
|
5
|
+
// Please note this may violate RFC 5321 as per http://stackoverflow.com/a/9808332/192024).
|
6
|
+
// The domain is always lowercased, as per RFC 1035
|
7
|
+
all_lowercase: true,
|
8
|
+
// The following conversions are specific to GMail
|
9
|
+
// Lowercases the local part of the GMail address (known to be case-insensitive)
|
10
|
+
gmail_lowercase: true,
|
11
|
+
// Removes dots from the local part of the email address, as that's ignored by GMail
|
12
|
+
gmail_remove_dots: true,
|
13
|
+
// Removes the subaddress (e.g. "+foo") from the email address
|
14
|
+
gmail_remove_subaddress: true,
|
15
|
+
// Conversts the googlemail.com domain to gmail.com
|
16
|
+
gmail_convert_googlemaildotcom: true,
|
17
|
+
// The following conversions are specific to Outlook.com / Windows Live / Hotmail
|
18
|
+
// Lowercases the local part of the Outlook.com address (known to be case-insensitive)
|
19
|
+
outlookdotcom_lowercase: true,
|
20
|
+
// Removes the subaddress (e.g. "+foo") from the email address
|
21
|
+
outlookdotcom_remove_subaddress: true,
|
22
|
+
// The following conversions are specific to Yahoo
|
23
|
+
// Lowercases the local part of the Yahoo address (known to be case-insensitive)
|
24
|
+
yahoo_lowercase: true,
|
25
|
+
// Removes the subaddress (e.g. "-foo") from the email address
|
26
|
+
yahoo_remove_subaddress: true,
|
27
|
+
// The following conversions are specific to Yandex
|
28
|
+
// Lowercases the local part of the Yandex address (known to be case-insensitive)
|
29
|
+
yandex_lowercase: true,
|
30
|
+
// The following conversions are specific to iCloud
|
31
|
+
// Lowercases the local part of the iCloud address (known to be case-insensitive)
|
32
|
+
icloud_lowercase: true,
|
33
|
+
// Removes the subaddress (e.g. "+foo") from the email address
|
34
|
+
icloud_remove_subaddress: true
|
35
|
+
};
|
36
|
+
|
37
|
+
// List of domains used by iCloud
|
38
|
+
var icloud_domains = ['icloud.com', 'me.com'];
|
39
|
+
|
40
|
+
// List of domains used by Outlook.com and its predecessors
|
41
|
+
// This list is likely incomplete.
|
42
|
+
// Partial reference:
|
43
|
+
// https://blogs.office.com/2013/04/17/outlook-com-gets-two-step-verification-sign-in-by-alias-and-new-international-domains/
|
44
|
+
var outlookdotcom_domains = ['hotmail.at', 'hotmail.be', 'hotmail.ca', 'hotmail.cl', 'hotmail.co.il', 'hotmail.co.nz', 'hotmail.co.th', 'hotmail.co.uk', 'hotmail.com', 'hotmail.com.ar', 'hotmail.com.au', 'hotmail.com.br', 'hotmail.com.gr', 'hotmail.com.mx', 'hotmail.com.pe', 'hotmail.com.tr', 'hotmail.com.vn', 'hotmail.cz', 'hotmail.de', 'hotmail.dk', 'hotmail.es', 'hotmail.fr', 'hotmail.hu', 'hotmail.id', 'hotmail.ie', 'hotmail.in', 'hotmail.it', 'hotmail.jp', 'hotmail.kr', 'hotmail.lv', 'hotmail.my', 'hotmail.ph', 'hotmail.pt', 'hotmail.sa', 'hotmail.sg', 'hotmail.sk', 'live.be', 'live.co.uk', 'live.com', 'live.com.ar', 'live.com.mx', 'live.de', 'live.es', 'live.eu', 'live.fr', 'live.it', 'live.nl', 'msn.com', 'outlook.at', 'outlook.be', 'outlook.cl', 'outlook.co.il', 'outlook.co.nz', 'outlook.co.th', 'outlook.com', 'outlook.com.ar', 'outlook.com.au', 'outlook.com.br', 'outlook.com.gr', 'outlook.com.pe', 'outlook.com.tr', 'outlook.com.vn', 'outlook.cz', 'outlook.de', 'outlook.dk', 'outlook.es', 'outlook.fr', 'outlook.hu', 'outlook.id', 'outlook.ie', 'outlook.in', 'outlook.it', 'outlook.jp', 'outlook.kr', 'outlook.lv', 'outlook.my', 'outlook.ph', 'outlook.pt', 'outlook.sa', 'outlook.sg', 'outlook.sk', 'passport.com'];
|
45
|
+
|
46
|
+
// List of domains used by Yahoo Mail
|
47
|
+
// This list is likely incomplete
|
48
|
+
var yahoo_domains = ['rocketmail.com', 'yahoo.ca', 'yahoo.co.uk', 'yahoo.com', 'yahoo.de', 'yahoo.fr', 'yahoo.in', 'yahoo.it', 'ymail.com'];
|
49
|
+
|
50
|
+
// List of domains used by yandex.ru
|
51
|
+
var yandex_domains = ['yandex.ru', 'yandex.ua', 'yandex.kz', 'yandex.com', 'yandex.by', 'ya.ru'];
|
52
|
+
|
53
|
+
// replace single dots, but not multiple consecutive dots
|
54
|
+
function dotsReplacer(match) {
|
55
|
+
if (match.length > 1) {
|
56
|
+
return match;
|
57
|
+
}
|
58
|
+
return '';
|
59
|
+
}
|
60
|
+
export default function normalizeEmail(email, options) {
|
61
|
+
options = merge(options, default_normalize_email_options);
|
62
|
+
var raw_parts = email.split('@');
|
63
|
+
var domain = raw_parts.pop();
|
64
|
+
var user = raw_parts.join('@');
|
65
|
+
var parts = [user, domain];
|
66
|
+
|
67
|
+
// The domain is always lowercased, as it's case-insensitive per RFC 1035
|
68
|
+
parts[1] = parts[1].toLowerCase();
|
69
|
+
if (parts[1] === 'gmail.com' || parts[1] === 'googlemail.com') {
|
70
|
+
// Address is GMail
|
71
|
+
if (options.gmail_remove_subaddress) {
|
72
|
+
parts[0] = parts[0].split('+')[0];
|
73
|
+
}
|
74
|
+
if (options.gmail_remove_dots) {
|
75
|
+
// this does not replace consecutive dots like example..email@gmail.com
|
76
|
+
parts[0] = parts[0].replace(/\.+/g, dotsReplacer);
|
77
|
+
}
|
78
|
+
if (!parts[0].length) {
|
79
|
+
return false;
|
80
|
+
}
|
81
|
+
if (options.all_lowercase || options.gmail_lowercase) {
|
82
|
+
parts[0] = parts[0].toLowerCase();
|
83
|
+
}
|
84
|
+
parts[1] = options.gmail_convert_googlemaildotcom ? 'gmail.com' : parts[1];
|
85
|
+
} else if (icloud_domains.indexOf(parts[1]) >= 0) {
|
86
|
+
// Address is iCloud
|
87
|
+
if (options.icloud_remove_subaddress) {
|
88
|
+
parts[0] = parts[0].split('+')[0];
|
89
|
+
}
|
90
|
+
if (!parts[0].length) {
|
91
|
+
return false;
|
92
|
+
}
|
93
|
+
if (options.all_lowercase || options.icloud_lowercase) {
|
94
|
+
parts[0] = parts[0].toLowerCase();
|
95
|
+
}
|
96
|
+
} else if (outlookdotcom_domains.indexOf(parts[1]) >= 0) {
|
97
|
+
// Address is Outlook.com
|
98
|
+
if (options.outlookdotcom_remove_subaddress) {
|
99
|
+
parts[0] = parts[0].split('+')[0];
|
100
|
+
}
|
101
|
+
if (!parts[0].length) {
|
102
|
+
return false;
|
103
|
+
}
|
104
|
+
if (options.all_lowercase || options.outlookdotcom_lowercase) {
|
105
|
+
parts[0] = parts[0].toLowerCase();
|
106
|
+
}
|
107
|
+
} else if (yahoo_domains.indexOf(parts[1]) >= 0) {
|
108
|
+
// Address is Yahoo
|
109
|
+
if (options.yahoo_remove_subaddress) {
|
110
|
+
var components = parts[0].split('-');
|
111
|
+
parts[0] = components.length > 1 ? components.slice(0, -1).join('-') : components[0];
|
112
|
+
}
|
113
|
+
if (!parts[0].length) {
|
114
|
+
return false;
|
115
|
+
}
|
116
|
+
if (options.all_lowercase || options.yahoo_lowercase) {
|
117
|
+
parts[0] = parts[0].toLowerCase();
|
118
|
+
}
|
119
|
+
} else if (yandex_domains.indexOf(parts[1]) >= 0) {
|
120
|
+
if (options.all_lowercase || options.yandex_lowercase) {
|
121
|
+
parts[0] = parts[0].toLowerCase();
|
122
|
+
}
|
123
|
+
parts[1] = 'yandex.ru'; // all yandex domains are equal, 1st preferred
|
124
|
+
} else if (options.all_lowercase) {
|
125
|
+
// Any other address
|
126
|
+
parts[0] = parts[0].toLowerCase();
|
127
|
+
}
|
128
|
+
return parts.join('@');
|
129
|
+
}
|
package/es/lib/rtrim.js
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
import assertString from './util/assertString';
|
2
|
+
export default function rtrim(str, chars) {
|
3
|
+
assertString(str);
|
4
|
+
if (chars) {
|
5
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
|
6
|
+
var pattern = new RegExp("[".concat(chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "]+$"), 'g');
|
7
|
+
return str.replace(pattern, '');
|
8
|
+
}
|
9
|
+
// Use a faster and more safe than regex trim method https://blog.stevenlevithan.com/archives/faster-trim-javascript
|
10
|
+
var strIndex = str.length - 1;
|
11
|
+
while (/\s/.test(str.charAt(strIndex))) {
|
12
|
+
strIndex -= 1;
|
13
|
+
}
|
14
|
+
return str.slice(0, strIndex + 1);
|
15
|
+
}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import assertString from './util/assertString';
|
2
|
+
import blacklist from './blacklist';
|
3
|
+
export default function stripLow(str, keep_new_lines) {
|
4
|
+
assertString(str);
|
5
|
+
var chars = keep_new_lines ? '\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F' : '\\x00-\\x1F\\x7F';
|
6
|
+
return blacklist(str, chars);
|
7
|
+
}
|
package/es/lib/toDate.js
ADDED