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/lib/isEAN.js
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isEAN;
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
9
|
+
/**
|
10
|
+
* The most commonly used EAN standard is
|
11
|
+
* the thirteen-digit EAN-13, while the
|
12
|
+
* less commonly used 8-digit EAN-8 barcode was
|
13
|
+
* introduced for use on small packages.
|
14
|
+
* Also EAN/UCC-14 is used for Grouping of individual
|
15
|
+
* trade items above unit level(Intermediate, Carton or Pallet).
|
16
|
+
* For more info about EAN-14 checkout: https://www.gtin.info/itf-14-barcodes/
|
17
|
+
* EAN consists of:
|
18
|
+
* GS1 prefix, manufacturer code, product code and check digit
|
19
|
+
* Reference: https://en.wikipedia.org/wiki/International_Article_Number
|
20
|
+
* Reference: https://www.gtin.info/
|
21
|
+
*/
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Define EAN Lenghts; 8 for EAN-8; 13 for EAN-13; 14 for EAN-14
|
25
|
+
* and Regular Expression for valid EANs (EAN-8, EAN-13, EAN-14),
|
26
|
+
* with exact numberic matching of 8 or 13 or 14 digits [0-9]
|
27
|
+
*/
|
28
|
+
var LENGTH_EAN_8 = 8;
|
29
|
+
var LENGTH_EAN_14 = 14;
|
30
|
+
var validEanRegex = /^(\d{8}|\d{13}|\d{14})$/;
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Get position weight given:
|
34
|
+
* EAN length and digit index/position
|
35
|
+
*
|
36
|
+
* @param {number} length
|
37
|
+
* @param {number} index
|
38
|
+
* @return {number}
|
39
|
+
*/
|
40
|
+
function getPositionWeightThroughLengthAndIndex(length, index) {
|
41
|
+
if (length === LENGTH_EAN_8 || length === LENGTH_EAN_14) {
|
42
|
+
return index % 2 === 0 ? 3 : 1;
|
43
|
+
}
|
44
|
+
return index % 2 === 0 ? 1 : 3;
|
45
|
+
}
|
46
|
+
|
47
|
+
/**
|
48
|
+
* Calculate EAN Check Digit
|
49
|
+
* Reference: https://en.wikipedia.org/wiki/International_Article_Number#Calculation_of_checksum_digit
|
50
|
+
*
|
51
|
+
* @param {string} ean
|
52
|
+
* @return {number}
|
53
|
+
*/
|
54
|
+
function calculateCheckDigit(ean) {
|
55
|
+
var checksum = ean.slice(0, -1).split('').map(function (char, index) {
|
56
|
+
return Number(char) * getPositionWeightThroughLengthAndIndex(ean.length, index);
|
57
|
+
}).reduce(function (acc, partialSum) {
|
58
|
+
return acc + partialSum;
|
59
|
+
}, 0);
|
60
|
+
var remainder = 10 - checksum % 10;
|
61
|
+
return remainder < 10 ? remainder : 0;
|
62
|
+
}
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Check if string is valid EAN:
|
66
|
+
* Matches EAN-8/EAN-13/EAN-14 regex
|
67
|
+
* Has valid check digit.
|
68
|
+
*
|
69
|
+
* @param {string} str
|
70
|
+
* @return {boolean}
|
71
|
+
*/
|
72
|
+
function isEAN(str) {
|
73
|
+
(0, _assertString.default)(str);
|
74
|
+
var actualCheckDigit = Number(str.slice(-1));
|
75
|
+
return validEanRegex.test(str) && actualCheckDigit === calculateCheckDigit(str);
|
76
|
+
}
|
77
|
+
module.exports = exports.default;
|
78
|
+
module.exports.default = exports.default;
|
package/lib/isEmail.js
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isEmail;
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
8
|
+
var _isByteLength = _interopRequireDefault(require("./isByteLength"));
|
9
|
+
var _isFQDN = _interopRequireDefault(require("./isFQDN"));
|
10
|
+
var _isIP = _interopRequireDefault(require("./isIP"));
|
11
|
+
var _merge = _interopRequireDefault(require("./util/merge"));
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
+
var default_email_options = {
|
14
|
+
allow_display_name: false,
|
15
|
+
allow_underscores: false,
|
16
|
+
require_display_name: false,
|
17
|
+
allow_utf8_local_part: true,
|
18
|
+
require_tld: true,
|
19
|
+
blacklisted_chars: '',
|
20
|
+
ignore_max_length: false,
|
21
|
+
host_blacklist: [],
|
22
|
+
host_whitelist: []
|
23
|
+
};
|
24
|
+
|
25
|
+
/* eslint-disable max-len */
|
26
|
+
/* eslint-disable no-control-regex */
|
27
|
+
var splitNameAddress = /^([^\x00-\x1F\x7F-\x9F\cX]+)</i;
|
28
|
+
var emailUserPart = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i;
|
29
|
+
var gmailUserPart = /^[a-z\d]+$/;
|
30
|
+
var quotedEmailUser = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i;
|
31
|
+
var emailUserUtf8Part = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A1-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i;
|
32
|
+
var quotedEmailUserUtf8 = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i;
|
33
|
+
var defaultMaxEmailLength = 254;
|
34
|
+
/* eslint-enable max-len */
|
35
|
+
/* eslint-enable no-control-regex */
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Validate display name according to the RFC2822: https://tools.ietf.org/html/rfc2822#appendix-A.1.2
|
39
|
+
* @param {String} display_name
|
40
|
+
*/
|
41
|
+
function validateDisplayName(display_name) {
|
42
|
+
var display_name_without_quotes = display_name.replace(/^"(.+)"$/, '$1');
|
43
|
+
// display name with only spaces is not valid
|
44
|
+
if (!display_name_without_quotes.trim()) {
|
45
|
+
return false;
|
46
|
+
}
|
47
|
+
|
48
|
+
// check whether display name contains illegal character
|
49
|
+
var contains_illegal = /[\.";<>]/.test(display_name_without_quotes);
|
50
|
+
if (contains_illegal) {
|
51
|
+
// if contains illegal characters,
|
52
|
+
// must to be enclosed in double-quotes, otherwise it's not a valid display name
|
53
|
+
if (display_name_without_quotes === display_name) {
|
54
|
+
return false;
|
55
|
+
}
|
56
|
+
|
57
|
+
// the quotes in display name must start with character symbol \
|
58
|
+
var all_start_with_back_slash = display_name_without_quotes.split('"').length === display_name_without_quotes.split('\\"').length;
|
59
|
+
if (!all_start_with_back_slash) {
|
60
|
+
return false;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
return true;
|
64
|
+
}
|
65
|
+
function isEmail(str, options) {
|
66
|
+
(0, _assertString.default)(str);
|
67
|
+
options = (0, _merge.default)(options, default_email_options);
|
68
|
+
if (options.require_display_name || options.allow_display_name) {
|
69
|
+
var display_email = str.match(splitNameAddress);
|
70
|
+
if (display_email) {
|
71
|
+
var display_name = display_email[1];
|
72
|
+
|
73
|
+
// Remove display name and angle brackets to get email address
|
74
|
+
// Can be done in the regex but will introduce a ReDOS (See #1597 for more info)
|
75
|
+
str = str.replace(display_name, '').replace(/(^<|>$)/g, '');
|
76
|
+
|
77
|
+
// sometimes need to trim the last space to get the display name
|
78
|
+
// because there may be a space between display name and email address
|
79
|
+
// eg. myname <address@gmail.com>
|
80
|
+
// the display name is `myname` instead of `myname `, so need to trim the last space
|
81
|
+
if (display_name.endsWith(' ')) {
|
82
|
+
display_name = display_name.slice(0, -1);
|
83
|
+
}
|
84
|
+
if (!validateDisplayName(display_name)) {
|
85
|
+
return false;
|
86
|
+
}
|
87
|
+
} else if (options.require_display_name) {
|
88
|
+
return false;
|
89
|
+
}
|
90
|
+
}
|
91
|
+
if (!options.ignore_max_length && str.length > defaultMaxEmailLength) {
|
92
|
+
return false;
|
93
|
+
}
|
94
|
+
var parts = str.split('@');
|
95
|
+
var domain = parts.pop();
|
96
|
+
var lower_domain = domain.toLowerCase();
|
97
|
+
if (options.host_blacklist.includes(lower_domain)) {
|
98
|
+
return false;
|
99
|
+
}
|
100
|
+
if (options.host_whitelist.length > 0 && !options.host_whitelist.includes(lower_domain)) {
|
101
|
+
return false;
|
102
|
+
}
|
103
|
+
var user = parts.join('@');
|
104
|
+
if (options.domain_specific_validation && (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com')) {
|
105
|
+
/*
|
106
|
+
Previously we removed dots for gmail addresses before validating.
|
107
|
+
This was removed because it allows `multiple..dots@gmail.com`
|
108
|
+
to be reported as valid, but it is not.
|
109
|
+
Gmail only normalizes single dots, removing them from here is pointless,
|
110
|
+
should be done in normalizeEmail
|
111
|
+
*/
|
112
|
+
user = user.toLowerCase();
|
113
|
+
|
114
|
+
// Removing sub-address from username before gmail validation
|
115
|
+
var username = user.split('+')[0];
|
116
|
+
|
117
|
+
// Dots are not included in gmail length restriction
|
118
|
+
if (!(0, _isByteLength.default)(username.replace(/\./g, ''), {
|
119
|
+
min: 6,
|
120
|
+
max: 30
|
121
|
+
})) {
|
122
|
+
return false;
|
123
|
+
}
|
124
|
+
var _user_parts = username.split('.');
|
125
|
+
for (var i = 0; i < _user_parts.length; i++) {
|
126
|
+
if (!gmailUserPart.test(_user_parts[i])) {
|
127
|
+
return false;
|
128
|
+
}
|
129
|
+
}
|
130
|
+
}
|
131
|
+
if (options.ignore_max_length === false && (!(0, _isByteLength.default)(user, {
|
132
|
+
max: 64
|
133
|
+
}) || !(0, _isByteLength.default)(domain, {
|
134
|
+
max: 254
|
135
|
+
}))) {
|
136
|
+
return false;
|
137
|
+
}
|
138
|
+
if (!(0, _isFQDN.default)(domain, {
|
139
|
+
require_tld: options.require_tld,
|
140
|
+
ignore_max_length: options.ignore_max_length,
|
141
|
+
allow_underscores: options.allow_underscores
|
142
|
+
})) {
|
143
|
+
if (!options.allow_ip_domain) {
|
144
|
+
return false;
|
145
|
+
}
|
146
|
+
if (!(0, _isIP.default)(domain)) {
|
147
|
+
if (!domain.startsWith('[') || !domain.endsWith(']')) {
|
148
|
+
return false;
|
149
|
+
}
|
150
|
+
var noBracketdomain = domain.slice(1, -1);
|
151
|
+
if (noBracketdomain.length === 0 || !(0, _isIP.default)(noBracketdomain)) {
|
152
|
+
return false;
|
153
|
+
}
|
154
|
+
}
|
155
|
+
}
|
156
|
+
if (user[0] === '"') {
|
157
|
+
user = user.slice(1, user.length - 1);
|
158
|
+
return options.allow_utf8_local_part ? quotedEmailUserUtf8.test(user) : quotedEmailUser.test(user);
|
159
|
+
}
|
160
|
+
var pattern = options.allow_utf8_local_part ? emailUserUtf8Part : emailUserPart;
|
161
|
+
var user_parts = user.split('.');
|
162
|
+
for (var _i = 0; _i < user_parts.length; _i++) {
|
163
|
+
if (!pattern.test(user_parts[_i])) {
|
164
|
+
return false;
|
165
|
+
}
|
166
|
+
}
|
167
|
+
if (options.blacklisted_chars) {
|
168
|
+
if (user.search(new RegExp("[".concat(options.blacklisted_chars, "]+"), 'g')) !== -1) return false;
|
169
|
+
}
|
170
|
+
return true;
|
171
|
+
}
|
172
|
+
module.exports = exports.default;
|
173
|
+
module.exports.default = exports.default;
|
package/lib/isEmpty.js
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isEmpty;
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
8
|
+
var _merge = _interopRequireDefault(require("./util/merge"));
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
|
+
var default_is_empty_options = {
|
11
|
+
ignore_whitespace: false
|
12
|
+
};
|
13
|
+
function isEmpty(str, options) {
|
14
|
+
(0, _assertString.default)(str);
|
15
|
+
options = (0, _merge.default)(options, default_is_empty_options);
|
16
|
+
return (options.ignore_whitespace ? str.trim().length : str.length) === 0;
|
17
|
+
}
|
18
|
+
module.exports = exports.default;
|
19
|
+
module.exports.default = exports.default;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isEthereumAddress;
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
9
|
+
var eth = /^(0x)[0-9a-f]{40}$/i;
|
10
|
+
function isEthereumAddress(str) {
|
11
|
+
(0, _assertString.default)(str);
|
12
|
+
return eth.test(str);
|
13
|
+
}
|
14
|
+
module.exports = exports.default;
|
15
|
+
module.exports.default = exports.default;
|
package/lib/isFQDN.js
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isFQDN;
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
8
|
+
var _merge = _interopRequireDefault(require("./util/merge"));
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
|
+
var default_fqdn_options = {
|
11
|
+
require_tld: true,
|
12
|
+
allow_underscores: false,
|
13
|
+
allow_trailing_dot: false,
|
14
|
+
allow_numeric_tld: false,
|
15
|
+
allow_wildcard: false,
|
16
|
+
ignore_max_length: false
|
17
|
+
};
|
18
|
+
function isFQDN(str, options) {
|
19
|
+
(0, _assertString.default)(str);
|
20
|
+
options = (0, _merge.default)(options, default_fqdn_options);
|
21
|
+
|
22
|
+
/* Remove the optional trailing dot before checking validity */
|
23
|
+
if (options.allow_trailing_dot && str[str.length - 1] === '.') {
|
24
|
+
str = str.substring(0, str.length - 1);
|
25
|
+
}
|
26
|
+
|
27
|
+
/* Remove the optional wildcard before checking validity */
|
28
|
+
if (options.allow_wildcard === true && str.indexOf('*.') === 0) {
|
29
|
+
str = str.substring(2);
|
30
|
+
}
|
31
|
+
var parts = str.split('.');
|
32
|
+
var tld = parts[parts.length - 1];
|
33
|
+
if (options.require_tld) {
|
34
|
+
// disallow fqdns without tld
|
35
|
+
if (parts.length < 2) {
|
36
|
+
return false;
|
37
|
+
}
|
38
|
+
if (!options.allow_numeric_tld && !/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
|
39
|
+
return false;
|
40
|
+
}
|
41
|
+
|
42
|
+
// disallow spaces
|
43
|
+
if (/\s/.test(tld)) {
|
44
|
+
return false;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
// reject numeric TLDs
|
49
|
+
if (!options.allow_numeric_tld && /^\d+$/.test(tld)) {
|
50
|
+
return false;
|
51
|
+
}
|
52
|
+
return parts.every(function (part) {
|
53
|
+
if (part.length > 63 && !options.ignore_max_length) {
|
54
|
+
return false;
|
55
|
+
}
|
56
|
+
if (!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(part)) {
|
57
|
+
return false;
|
58
|
+
}
|
59
|
+
|
60
|
+
// disallow full-width chars
|
61
|
+
if (/[\uff01-\uff5e]/.test(part)) {
|
62
|
+
return false;
|
63
|
+
}
|
64
|
+
|
65
|
+
// disallow parts starting or ending with hyphen
|
66
|
+
if (/^-|-$/.test(part)) {
|
67
|
+
return false;
|
68
|
+
}
|
69
|
+
if (!options.allow_underscores && /_/.test(part)) {
|
70
|
+
return false;
|
71
|
+
}
|
72
|
+
return true;
|
73
|
+
});
|
74
|
+
}
|
75
|
+
module.exports = exports.default;
|
76
|
+
module.exports.default = exports.default;
|
package/lib/isFloat.js
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isFloat;
|
7
|
+
exports.locales = void 0;
|
8
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
9
|
+
var _alpha = require("./alpha");
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
|
+
function isFloat(str, options) {
|
12
|
+
(0, _assertString.default)(str);
|
13
|
+
options = options || {};
|
14
|
+
var float = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\".concat(options.locale ? _alpha.decimal[options.locale] : '.', "[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$"));
|
15
|
+
if (str === '' || str === '.' || str === ',' || str === '-' || str === '+') {
|
16
|
+
return false;
|
17
|
+
}
|
18
|
+
var value = parseFloat(str.replace(',', '.'));
|
19
|
+
return float.test(str) && (!options.hasOwnProperty('min') || value >= options.min) && (!options.hasOwnProperty('max') || value <= options.max) && (!options.hasOwnProperty('lt') || value < options.lt) && (!options.hasOwnProperty('gt') || value > options.gt);
|
20
|
+
}
|
21
|
+
var locales = exports.locales = Object.keys(_alpha.decimal);
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isFullWidth;
|
7
|
+
exports.fullWidth = void 0;
|
8
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
|
+
var fullWidth = exports.fullWidth = /[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;
|
11
|
+
function isFullWidth(str) {
|
12
|
+
(0, _assertString.default)(str);
|
13
|
+
return fullWidth.test(str);
|
14
|
+
}
|
package/lib/isHSL.js
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isHSL;
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
9
|
+
var hslComma = /^hsla?\(((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)?(,(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}(,((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?))?\)$/i;
|
10
|
+
var hslSpace = /^hsla?\(((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?))(deg|grad|rad|turn)?(\s(\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%){2}\s?(\/\s((\+|\-)?([0-9]+(\.[0-9]+)?(e(\+|\-)?[0-9]+)?|\.[0-9]+(e(\+|\-)?[0-9]+)?)%?)\s?)?\)$/i;
|
11
|
+
function isHSL(str) {
|
12
|
+
(0, _assertString.default)(str);
|
13
|
+
|
14
|
+
// Strip duplicate spaces before calling the validation regex (See #1598 for more info)
|
15
|
+
var strippedStr = str.replace(/\s+/g, ' ').replace(/\s?(hsla?\(|\)|,)\s?/ig, '$1');
|
16
|
+
if (strippedStr.indexOf(',') !== -1) {
|
17
|
+
return hslComma.test(strippedStr);
|
18
|
+
}
|
19
|
+
return hslSpace.test(strippedStr);
|
20
|
+
}
|
21
|
+
module.exports = exports.default;
|
22
|
+
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 = isHalfWidth;
|
7
|
+
exports.halfWidth = void 0;
|
8
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
|
+
var halfWidth = exports.halfWidth = /[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;
|
11
|
+
function isHalfWidth(str) {
|
12
|
+
(0, _assertString.default)(str);
|
13
|
+
return halfWidth.test(str);
|
14
|
+
}
|
package/lib/isHash.js
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isHash;
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
9
|
+
var lengths = {
|
10
|
+
md5: 32,
|
11
|
+
md4: 32,
|
12
|
+
sha1: 40,
|
13
|
+
sha256: 64,
|
14
|
+
sha384: 96,
|
15
|
+
sha512: 128,
|
16
|
+
ripemd128: 32,
|
17
|
+
ripemd160: 40,
|
18
|
+
tiger128: 32,
|
19
|
+
tiger160: 40,
|
20
|
+
tiger192: 48,
|
21
|
+
crc32: 8,
|
22
|
+
crc32b: 8
|
23
|
+
};
|
24
|
+
function isHash(str, algorithm) {
|
25
|
+
(0, _assertString.default)(str);
|
26
|
+
var hash = new RegExp("^[a-fA-F0-9]{".concat(lengths[algorithm], "}$"));
|
27
|
+
return hash.test(str);
|
28
|
+
}
|
29
|
+
module.exports = exports.default;
|
30
|
+
module.exports.default = exports.default;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isHexColor;
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
9
|
+
var hexcolor = /^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;
|
10
|
+
function isHexColor(str) {
|
11
|
+
(0, _assertString.default)(str);
|
12
|
+
return hexcolor.test(str);
|
13
|
+
}
|
14
|
+
module.exports = exports.default;
|
15
|
+
module.exports.default = exports.default;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isHexadecimal;
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
9
|
+
var hexadecimal = /^(0x|0h)?[0-9A-F]+$/i;
|
10
|
+
function isHexadecimal(str) {
|
11
|
+
(0, _assertString.default)(str);
|
12
|
+
return hexadecimal.test(str);
|
13
|
+
}
|
14
|
+
module.exports = exports.default;
|
15
|
+
module.exports.default = exports.default;
|
package/lib/isIBAN.js
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = isIBAN;
|
7
|
+
exports.locales = void 0;
|
8
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
10
|
+
/**
|
11
|
+
* List of country codes with
|
12
|
+
* corresponding IBAN regular expression
|
13
|
+
* Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number
|
14
|
+
*/
|
15
|
+
var ibanRegexThroughCountryCode = {
|
16
|
+
AD: /^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,
|
17
|
+
AE: /^(AE[0-9]{2})\d{3}\d{16}$/,
|
18
|
+
AL: /^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,
|
19
|
+
AT: /^(AT[0-9]{2})\d{16}$/,
|
20
|
+
AZ: /^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,
|
21
|
+
BA: /^(BA[0-9]{2})\d{16}$/,
|
22
|
+
BE: /^(BE[0-9]{2})\d{12}$/,
|
23
|
+
BG: /^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,
|
24
|
+
BH: /^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,
|
25
|
+
BR: /^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,
|
26
|
+
BY: /^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,
|
27
|
+
CH: /^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,
|
28
|
+
CR: /^(CR[0-9]{2})\d{18}$/,
|
29
|
+
CY: /^(CY[0-9]{2})\d{8}[A-Z0-9]{16}$/,
|
30
|
+
CZ: /^(CZ[0-9]{2})\d{20}$/,
|
31
|
+
DE: /^(DE[0-9]{2})\d{18}$/,
|
32
|
+
DK: /^(DK[0-9]{2})\d{14}$/,
|
33
|
+
DO: /^(DO[0-9]{2})[A-Z]{4}\d{20}$/,
|
34
|
+
DZ: /^(DZ\d{24})$/,
|
35
|
+
EE: /^(EE[0-9]{2})\d{16}$/,
|
36
|
+
EG: /^(EG[0-9]{2})\d{25}$/,
|
37
|
+
ES: /^(ES[0-9]{2})\d{20}$/,
|
38
|
+
FI: /^(FI[0-9]{2})\d{14}$/,
|
39
|
+
FO: /^(FO[0-9]{2})\d{14}$/,
|
40
|
+
FR: /^(FR[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/,
|
41
|
+
GB: /^(GB[0-9]{2})[A-Z]{4}\d{14}$/,
|
42
|
+
GE: /^(GE[0-9]{2})[A-Z0-9]{2}\d{16}$/,
|
43
|
+
GI: /^(GI[0-9]{2})[A-Z]{4}[A-Z0-9]{15}$/,
|
44
|
+
GL: /^(GL[0-9]{2})\d{14}$/,
|
45
|
+
GR: /^(GR[0-9]{2})\d{7}[A-Z0-9]{16}$/,
|
46
|
+
GT: /^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,
|
47
|
+
HR: /^(HR[0-9]{2})\d{17}$/,
|
48
|
+
HU: /^(HU[0-9]{2})\d{24}$/,
|
49
|
+
IE: /^(IE[0-9]{2})[A-Z0-9]{4}\d{14}$/,
|
50
|
+
IL: /^(IL[0-9]{2})\d{19}$/,
|
51
|
+
IQ: /^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,
|
52
|
+
IR: /^(IR[0-9]{2})0\d{2}0\d{18}$/,
|
53
|
+
IS: /^(IS[0-9]{2})\d{22}$/,
|
54
|
+
IT: /^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,
|
55
|
+
JO: /^(JO[0-9]{2})[A-Z]{4}\d{22}$/,
|
56
|
+
KW: /^(KW[0-9]{2})[A-Z]{4}[A-Z0-9]{22}$/,
|
57
|
+
KZ: /^(KZ[0-9]{2})\d{3}[A-Z0-9]{13}$/,
|
58
|
+
LB: /^(LB[0-9]{2})\d{4}[A-Z0-9]{20}$/,
|
59
|
+
LC: /^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,
|
60
|
+
LI: /^(LI[0-9]{2})\d{5}[A-Z0-9]{12}$/,
|
61
|
+
LT: /^(LT[0-9]{2})\d{16}$/,
|
62
|
+
LU: /^(LU[0-9]{2})\d{3}[A-Z0-9]{13}$/,
|
63
|
+
LV: /^(LV[0-9]{2})[A-Z]{4}[A-Z0-9]{13}$/,
|
64
|
+
MA: /^(MA[0-9]{26})$/,
|
65
|
+
MC: /^(MC[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/,
|
66
|
+
MD: /^(MD[0-9]{2})[A-Z0-9]{20}$/,
|
67
|
+
ME: /^(ME[0-9]{2})\d{18}$/,
|
68
|
+
MK: /^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,
|
69
|
+
MR: /^(MR[0-9]{2})\d{23}$/,
|
70
|
+
MT: /^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,
|
71
|
+
MU: /^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,
|
72
|
+
MZ: /^(MZ[0-9]{2})\d{21}$/,
|
73
|
+
NL: /^(NL[0-9]{2})[A-Z]{4}\d{10}$/,
|
74
|
+
NO: /^(NO[0-9]{2})\d{11}$/,
|
75
|
+
PK: /^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,
|
76
|
+
PL: /^(PL[0-9]{2})\d{24}$/,
|
77
|
+
PS: /^(PS[0-9]{2})[A-Z0-9]{4}\d{21}$/,
|
78
|
+
PT: /^(PT[0-9]{2})\d{21}$/,
|
79
|
+
QA: /^(QA[0-9]{2})[A-Z]{4}[A-Z0-9]{21}$/,
|
80
|
+
RO: /^(RO[0-9]{2})[A-Z]{4}[A-Z0-9]{16}$/,
|
81
|
+
RS: /^(RS[0-9]{2})\d{18}$/,
|
82
|
+
SA: /^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,
|
83
|
+
SC: /^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,
|
84
|
+
SE: /^(SE[0-9]{2})\d{20}$/,
|
85
|
+
SI: /^(SI[0-9]{2})\d{15}$/,
|
86
|
+
SK: /^(SK[0-9]{2})\d{20}$/,
|
87
|
+
SM: /^(SM[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,
|
88
|
+
SV: /^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,
|
89
|
+
TL: /^(TL[0-9]{2})\d{19}$/,
|
90
|
+
TN: /^(TN[0-9]{2})\d{20}$/,
|
91
|
+
TR: /^(TR[0-9]{2})\d{5}[A-Z0-9]{17}$/,
|
92
|
+
UA: /^(UA[0-9]{2})\d{6}[A-Z0-9]{19}$/,
|
93
|
+
VA: /^(VA[0-9]{2})\d{18}$/,
|
94
|
+
VG: /^(VG[0-9]{2})[A-Z0-9]{4}\d{16}$/,
|
95
|
+
XK: /^(XK[0-9]{2})\d{16}$/
|
96
|
+
};
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Check if the country codes passed are valid using the
|
100
|
+
* ibanRegexThroughCountryCode as a reference
|
101
|
+
*
|
102
|
+
* @param {array} countryCodeArray
|
103
|
+
* @return {boolean}
|
104
|
+
*/
|
105
|
+
|
106
|
+
function hasOnlyValidCountryCodes(countryCodeArray) {
|
107
|
+
var countryCodeArrayFilteredWithObjectIbanCode = countryCodeArray.filter(function (countryCode) {
|
108
|
+
return !(countryCode in ibanRegexThroughCountryCode);
|
109
|
+
});
|
110
|
+
if (countryCodeArrayFilteredWithObjectIbanCode.length > 0) {
|
111
|
+
return false;
|
112
|
+
}
|
113
|
+
return true;
|
114
|
+
}
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Check whether string has correct universal IBAN format
|
118
|
+
* The IBAN consists of up to 34 alphanumeric characters, as follows:
|
119
|
+
* Country Code using ISO 3166-1 alpha-2, two letters
|
120
|
+
* check digits, two digits and
|
121
|
+
* Basic Bank Account Number (BBAN), up to 30 alphanumeric characters.
|
122
|
+
* NOTE: Permitted IBAN characters are: digits [0-9] and the 26 latin alphabetic [A-Z]
|
123
|
+
*
|
124
|
+
* @param {string} str - string under validation
|
125
|
+
* @param {object} options - object to pass the countries to be either whitelisted or blacklisted
|
126
|
+
* @return {boolean}
|
127
|
+
*/
|
128
|
+
function hasValidIbanFormat(str, options) {
|
129
|
+
// Strip white spaces and hyphens
|
130
|
+
var strippedStr = str.replace(/[\s\-]+/gi, '').toUpperCase();
|
131
|
+
var isoCountryCode = strippedStr.slice(0, 2).toUpperCase();
|
132
|
+
var isoCountryCodeInIbanRegexCodeObject = (isoCountryCode in ibanRegexThroughCountryCode);
|
133
|
+
if (options.whitelist) {
|
134
|
+
if (!hasOnlyValidCountryCodes(options.whitelist)) {
|
135
|
+
return false;
|
136
|
+
}
|
137
|
+
var isoCountryCodeInWhiteList = options.whitelist.includes(isoCountryCode);
|
138
|
+
if (!isoCountryCodeInWhiteList) {
|
139
|
+
return false;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
if (options.blacklist) {
|
143
|
+
var isoCountryCodeInBlackList = options.blacklist.includes(isoCountryCode);
|
144
|
+
if (isoCountryCodeInBlackList) {
|
145
|
+
return false;
|
146
|
+
}
|
147
|
+
}
|
148
|
+
return isoCountryCodeInIbanRegexCodeObject && ibanRegexThroughCountryCode[isoCountryCode].test(strippedStr);
|
149
|
+
}
|
150
|
+
|
151
|
+
/**
|
152
|
+
* Check whether string has valid IBAN Checksum
|
153
|
+
* by performing basic mod-97 operation and
|
154
|
+
* the remainder should equal 1
|
155
|
+
* -- Start by rearranging the IBAN by moving the four initial characters to the end of the string
|
156
|
+
* -- Replace each letter in the string with two digits, A -> 10, B = 11, Z = 35
|
157
|
+
* -- Interpret the string as a decimal integer and
|
158
|
+
* -- compute the remainder on division by 97 (mod 97)
|
159
|
+
* Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number
|
160
|
+
*
|
161
|
+
* @param {string} str
|
162
|
+
* @return {boolean}
|
163
|
+
*/
|
164
|
+
function hasValidIbanChecksum(str) {
|
165
|
+
var strippedStr = str.replace(/[^A-Z0-9]+/gi, '').toUpperCase(); // Keep only digits and A-Z latin alphabetic
|
166
|
+
var rearranged = strippedStr.slice(4) + strippedStr.slice(0, 4);
|
167
|
+
var alphaCapsReplacedWithDigits = rearranged.replace(/[A-Z]/g, function (char) {
|
168
|
+
return char.charCodeAt(0) - 55;
|
169
|
+
});
|
170
|
+
var remainder = alphaCapsReplacedWithDigits.match(/\d{1,7}/g).reduce(function (acc, value) {
|
171
|
+
return Number(acc + value) % 97;
|
172
|
+
}, '');
|
173
|
+
return remainder === 1;
|
174
|
+
}
|
175
|
+
function isIBAN(str) {
|
176
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
177
|
+
(0, _assertString.default)(str);
|
178
|
+
return hasValidIbanFormat(str, options) && hasValidIbanChecksum(str);
|
179
|
+
}
|
180
|
+
var locales = exports.locales = Object.keys(ibanRegexThroughCountryCode);
|