validator-string 13.15.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +269 -0
- package/es/index.js +218 -0
- package/es/lib/alpha.js +151 -0
- package/es/lib/blacklist.js +5 -0
- package/es/lib/contains.js +15 -0
- package/es/lib/equals.js +5 -0
- package/es/lib/escape.js +5 -0
- package/es/lib/isAbaRouting.js +15 -0
- package/es/lib/isAfter.js +10 -0
- package/es/lib/isAlpha.js +23 -0
- package/es/lib/isAlphanumeric.js +23 -0
- package/es/lib/isAscii.js +10 -0
- package/es/lib/isBIC.js +16 -0
- package/es/lib/isBase32.js +15 -0
- package/es/lib/isBase58.js +8 -0
- package/es/lib/isBase64.js +23 -0
- package/es/lib/isBefore.js +10 -0
- package/es/lib/isBoolean.js +15 -0
- package/es/lib/isBtcAddress.js +7 -0
- package/es/lib/isByteLength.js +19 -0
- package/es/lib/isCreditCard.js +43 -0
- package/es/lib/isCurrency.js +74 -0
- package/es/lib/isDataURI.js +31 -0
- package/es/lib/isDate.js +93 -0
- package/es/lib/isDecimal.js +22 -0
- package/es/lib/isDivisibleBy.js +6 -0
- package/es/lib/isEAN.js +70 -0
- package/es/lib/isEmail.js +165 -0
- package/es/lib/isEmpty.js +10 -0
- package/es/lib/isEthereumAddress.js +6 -0
- package/es/lib/isFQDN.js +67 -0
- package/es/lib/isFloat.js +14 -0
- package/es/lib/isFullWidth.js +6 -0
- package/es/lib/isHSL.js +13 -0
- package/es/lib/isHalfWidth.js +6 -0
- package/es/lib/isHash.js +21 -0
- package/es/lib/isHexColor.js +13 -0
- package/es/lib/isHexadecimal.js +6 -0
- package/es/lib/isIBAN.js +171 -0
- package/es/lib/isIMEI.js +40 -0
- package/es/lib/isIP.js +58 -0
- package/es/lib/isIPRange.js +41 -0
- package/es/lib/isISBN.js +47 -0
- package/es/lib/isISIN.js +55 -0
- package/es/lib/isISO15924.js +9 -0
- package/es/lib/isISO31661Alpha2.js +21 -0
- package/es/lib/isISO31661Alpha3.js +20 -0
- package/es/lib/isISO31661Numeric.js +8 -0
- package/es/lib/isISO4217.js +9 -0
- package/es/lib/isISO6346.js +28 -0
- package/es/lib/isISO6391.js +6 -0
- package/es/lib/isISO8601.js +42 -0
- package/es/lib/isISRC.js +8 -0
- package/es/lib/isISSN.js +19 -0
- package/es/lib/isIdentityCard.js +407 -0
- package/es/lib/isIn.js +23 -0
- package/es/lib/isInt.js +19 -0
- package/es/lib/isJSON.js +26 -0
- package/es/lib/isJWT.js +15 -0
- package/es/lib/isLatLong.js +21 -0
- package/es/lib/isLength.js +27 -0
- package/es/lib/isLicensePlate.js +58 -0
- package/es/lib/isLocale.js +107 -0
- package/es/lib/isLowercase.js +5 -0
- package/es/lib/isLuhnNumber.js +25 -0
- package/es/lib/isMACAddress.js +36 -0
- package/es/lib/isMD5.js +6 -0
- package/es/lib/isMagnetURI.js +9 -0
- package/es/lib/isMailtoURI.js +75 -0
- package/es/lib/isMimeType.js +40 -0
- package/es/lib/isMobilePhone.js +212 -0
- package/es/lib/isMongoId.js +6 -0
- package/es/lib/isMultibyte.js +10 -0
- package/es/lib/isNumeric.js +10 -0
- package/es/lib/isOctal.js +6 -0
- package/es/lib/isPassportNumber.js +145 -0
- package/es/lib/isPort.js +8 -0
- package/es/lib/isPostalCode.js +100 -0
- package/es/lib/isRFC3339.js +21 -0
- package/es/lib/isRgbColor.js +34 -0
- package/es/lib/isSemVer.js +14 -0
- package/es/lib/isSlug.js +6 -0
- package/es/lib/isStrongPassword.js +90 -0
- package/es/lib/isSurrogatePair.js +6 -0
- package/es/lib/isTaxID.js +1407 -0
- package/es/lib/isTime.js +22 -0
- package/es/lib/isULID.js +5 -0
- package/es/lib/isURL.js +241 -0
- package/es/lib/isUUID.js +23 -0
- package/es/lib/isUppercase.js +5 -0
- package/es/lib/isVAT.js +264 -0
- package/es/lib/isVariableWidth.js +7 -0
- package/es/lib/isWhitelisted.js +10 -0
- package/es/lib/ltrim.js +7 -0
- package/es/lib/matches.js +8 -0
- package/es/lib/normalizeEmail.js +131 -0
- package/es/lib/rtrim.js +15 -0
- package/es/lib/stripLow.js +7 -0
- package/es/lib/toBoolean.js +8 -0
- package/es/lib/toDate.js +6 -0
- package/es/lib/toFloat.js +5 -0
- package/es/lib/toInt.js +5 -0
- package/es/lib/trim.js +5 -0
- package/es/lib/unescape.js +8 -0
- package/es/lib/util/algorithms.js +79 -0
- package/es/lib/util/assertString.js +4 -0
- package/es/lib/util/checkHost.js +12 -0
- package/es/lib/util/includesArray.js +6 -0
- package/es/lib/util/includesString.js +4 -0
- package/es/lib/util/merge.js +14 -0
- package/es/lib/util/multilineRegex.js +12 -0
- package/es/lib/util/nullUndefinedCheck.js +3 -0
- package/es/lib/util/toString.js +13 -0
- package/es/lib/util/typeOf.js +10 -0
- package/es/lib/whitelist.js +5 -0
- package/index.js +229 -0
- package/lib/alpha.js +157 -0
- package/lib/blacklist.js +14 -0
- package/lib/contains.js +24 -0
- package/lib/equals.js +14 -0
- package/lib/escape.js +14 -0
- package/lib/isAbaRouting.js +23 -0
- package/lib/isAfter.js +19 -0
- package/lib/isAlpha.js +31 -0
- package/lib/isAlphanumeric.js +31 -0
- package/lib/isAscii.js +18 -0
- package/lib/isBIC.js +24 -0
- package/lib/isBase32.js +24 -0
- package/lib/isBase58.js +16 -0
- package/lib/isBase64.js +32 -0
- package/lib/isBefore.js +19 -0
- package/lib/isBoolean.js +24 -0
- package/lib/isBtcAddress.js +16 -0
- package/lib/isByteLength.js +27 -0
- package/lib/isCreditCard.js +52 -0
- package/lib/isCurrency.js +83 -0
- package/lib/isDataURI.js +40 -0
- package/lib/isDate.js +102 -0
- package/lib/isDecimal.js +31 -0
- package/lib/isDivisibleBy.js +15 -0
- package/lib/isEAN.js +78 -0
- package/lib/isEmail.js +174 -0
- package/lib/isEmpty.js +19 -0
- package/lib/isEthereumAddress.js +15 -0
- package/lib/isFQDN.js +76 -0
- package/lib/isFloat.js +22 -0
- package/lib/isFullWidth.js +14 -0
- package/lib/isHSL.js +22 -0
- package/lib/isHalfWidth.js +14 -0
- package/lib/isHash.js +30 -0
- package/lib/isHexColor.js +22 -0
- package/lib/isHexadecimal.js +15 -0
- package/lib/isIBAN.js +178 -0
- package/lib/isIMEI.js +49 -0
- package/lib/isIP.js +67 -0
- package/lib/isIPRange.js +50 -0
- package/lib/isISBN.js +56 -0
- package/lib/isISIN.js +64 -0
- package/lib/isISO15924.js +16 -0
- package/lib/isISO31661Alpha2.js +28 -0
- package/lib/isISO31661Alpha3.js +28 -0
- package/lib/isISO31661Numeric.js +16 -0
- package/lib/isISO4217.js +16 -0
- package/lib/isISO6346.js +35 -0
- package/lib/isISO6391.js +15 -0
- package/lib/isISO8601.js +50 -0
- package/lib/isISRC.js +16 -0
- package/lib/isISSN.js +28 -0
- package/lib/isIdentityCard.js +416 -0
- package/lib/isIn.js +32 -0
- package/lib/isInt.js +28 -0
- package/lib/isJSON.js +35 -0
- package/lib/isJWT.js +24 -0
- package/lib/isLatLong.js +30 -0
- package/lib/isLength.js +35 -0
- package/lib/isLicensePlate.js +67 -0
- package/lib/isLocale.js +115 -0
- package/lib/isLowercase.js +14 -0
- package/lib/isLuhnNumber.js +34 -0
- package/lib/isMACAddress.js +45 -0
- package/lib/isMD5.js +15 -0
- package/lib/isMagnetURI.js +18 -0
- package/lib/isMailtoURI.js +84 -0
- package/lib/isMimeType.js +48 -0
- package/lib/isMobilePhone.js +219 -0
- package/lib/isMongoId.js +15 -0
- package/lib/isMultibyte.js +18 -0
- package/lib/isNumeric.js +19 -0
- package/lib/isOctal.js +15 -0
- package/lib/isPassportNumber.js +152 -0
- package/lib/isPort.js +17 -0
- package/lib/isPostalCode.js +107 -0
- package/lib/isRFC3339.js +29 -0
- package/lib/isRgbColor.js +42 -0
- package/lib/isSemVer.js +22 -0
- package/lib/isSlug.js +15 -0
- package/lib/isStrongPassword.js +99 -0
- package/lib/isSurrogatePair.js +15 -0
- package/lib/isTaxID.js +1417 -0
- package/lib/isTime.js +31 -0
- package/lib/isULID.js +14 -0
- package/lib/isURL.js +249 -0
- package/lib/isUUID.js +32 -0
- package/lib/isUppercase.js +14 -0
- package/lib/isVAT.js +274 -0
- package/lib/isVariableWidth.js +16 -0
- package/lib/isWhitelisted.js +19 -0
- package/lib/ltrim.js +16 -0
- package/lib/matches.js +17 -0
- package/lib/normalizeEmail.js +140 -0
- package/lib/rtrim.js +24 -0
- package/lib/stripLow.js +16 -0
- package/lib/toBoolean.js +17 -0
- package/lib/toDate.js +15 -0
- package/lib/toFloat.js +14 -0
- package/lib/toInt.js +14 -0
- package/lib/trim.js +14 -0
- package/lib/unescape.js +17 -0
- package/lib/util/algorithms.js +88 -0
- package/lib/util/assertString.js +12 -0
- package/lib/util/checkHost.js +20 -0
- package/lib/util/includesArray.js +14 -0
- package/lib/util/includesString.js +12 -0
- package/lib/util/merge.js +22 -0
- package/lib/util/multilineRegex.js +20 -0
- package/lib/util/nullUndefinedCheck.js +11 -0
- package/lib/util/toString.js +21 -0
- package/lib/util/typeOf.js +18 -0
- package/lib/whitelist.js +14 -0
- package/package.json +83 -0
- package/validator.js +5808 -0
- package/validator.min.js +23 -0
package/lib/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(e) { return e && e.__esModule ? e : { default: e }; }
|
|
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(e) { return e && e.__esModule ? e : { default: e }; }
|
|
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(e) { return e && e.__esModule ? e : { default: e }; }
|
|
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,22 @@
|
|
|
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
|
+
var _merge = _interopRequireDefault(require("./util/merge"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
var hexcolor = /^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;
|
|
11
|
+
var hexcolor_with_prefix = /^#([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;
|
|
12
|
+
var default_is_hexcolor_options = {
|
|
13
|
+
require_hashtag: false
|
|
14
|
+
};
|
|
15
|
+
function isHexColor(str, options) {
|
|
16
|
+
(0, _assertString.default)(str);
|
|
17
|
+
options = (0, _merge.default)(options, default_is_hexcolor_options);
|
|
18
|
+
var hexcolor_regex = options.require_hashtag ? hexcolor_with_prefix : hexcolor;
|
|
19
|
+
return hexcolor_regex.test(str);
|
|
20
|
+
}
|
|
21
|
+
module.exports = exports.default;
|
|
22
|
+
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(e) { return e && e.__esModule ? e : { default: e }; }
|
|
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,178 @@
|
|
|
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
|
+
var _includesArray = _interopRequireDefault(require("./util/includesArray"));
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
/**
|
|
12
|
+
* List of country codes with
|
|
13
|
+
* corresponding IBAN regular expression
|
|
14
|
+
* Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number
|
|
15
|
+
*/
|
|
16
|
+
var ibanRegexThroughCountryCode = {
|
|
17
|
+
AD: /^(AD[0-9]{2})\d{8}[A-Z0-9]{12}$/,
|
|
18
|
+
AE: /^(AE[0-9]{2})\d{3}\d{16}$/,
|
|
19
|
+
AL: /^(AL[0-9]{2})\d{8}[A-Z0-9]{16}$/,
|
|
20
|
+
AT: /^(AT[0-9]{2})\d{16}$/,
|
|
21
|
+
AZ: /^(AZ[0-9]{2})[A-Z0-9]{4}\d{20}$/,
|
|
22
|
+
BA: /^(BA[0-9]{2})\d{16}$/,
|
|
23
|
+
BE: /^(BE[0-9]{2})\d{12}$/,
|
|
24
|
+
BG: /^(BG[0-9]{2})[A-Z]{4}\d{6}[A-Z0-9]{8}$/,
|
|
25
|
+
BH: /^(BH[0-9]{2})[A-Z]{4}[A-Z0-9]{14}$/,
|
|
26
|
+
BR: /^(BR[0-9]{2})\d{23}[A-Z]{1}[A-Z0-9]{1}$/,
|
|
27
|
+
BY: /^(BY[0-9]{2})[A-Z0-9]{4}\d{20}$/,
|
|
28
|
+
CH: /^(CH[0-9]{2})\d{5}[A-Z0-9]{12}$/,
|
|
29
|
+
CR: /^(CR[0-9]{2})\d{18}$/,
|
|
30
|
+
CY: /^(CY[0-9]{2})\d{8}[A-Z0-9]{16}$/,
|
|
31
|
+
CZ: /^(CZ[0-9]{2})\d{20}$/,
|
|
32
|
+
DE: /^(DE[0-9]{2})\d{18}$/,
|
|
33
|
+
DK: /^(DK[0-9]{2})\d{14}$/,
|
|
34
|
+
DO: /^(DO[0-9]{2})[A-Z]{4}\d{20}$/,
|
|
35
|
+
DZ: /^(DZ\d{24})$/,
|
|
36
|
+
EE: /^(EE[0-9]{2})\d{16}$/,
|
|
37
|
+
EG: /^(EG[0-9]{2})\d{25}$/,
|
|
38
|
+
ES: /^(ES[0-9]{2})\d{20}$/,
|
|
39
|
+
FI: /^(FI[0-9]{2})\d{14}$/,
|
|
40
|
+
FO: /^(FO[0-9]{2})\d{14}$/,
|
|
41
|
+
FR: /^(FR[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/,
|
|
42
|
+
GB: /^(GB[0-9]{2})[A-Z]{4}\d{14}$/,
|
|
43
|
+
GE: /^(GE[0-9]{2})[A-Z0-9]{2}\d{16}$/,
|
|
44
|
+
GI: /^(GI[0-9]{2})[A-Z]{4}[A-Z0-9]{15}$/,
|
|
45
|
+
GL: /^(GL[0-9]{2})\d{14}$/,
|
|
46
|
+
GR: /^(GR[0-9]{2})\d{7}[A-Z0-9]{16}$/,
|
|
47
|
+
GT: /^(GT[0-9]{2})[A-Z0-9]{4}[A-Z0-9]{20}$/,
|
|
48
|
+
HR: /^(HR[0-9]{2})\d{17}$/,
|
|
49
|
+
HU: /^(HU[0-9]{2})\d{24}$/,
|
|
50
|
+
IE: /^(IE[0-9]{2})[A-Z]{4}\d{14}$/,
|
|
51
|
+
IL: /^(IL[0-9]{2})\d{19}$/,
|
|
52
|
+
IQ: /^(IQ[0-9]{2})[A-Z]{4}\d{15}$/,
|
|
53
|
+
IR: /^(IR[0-9]{2})\d{22}$/,
|
|
54
|
+
IS: /^(IS[0-9]{2})\d{22}$/,
|
|
55
|
+
IT: /^(IT[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,
|
|
56
|
+
JO: /^(JO[0-9]{2})[A-Z]{4}\d{22}$/,
|
|
57
|
+
KW: /^(KW[0-9]{2})[A-Z]{4}[A-Z0-9]{22}$/,
|
|
58
|
+
KZ: /^(KZ[0-9]{2})\d{3}[A-Z0-9]{13}$/,
|
|
59
|
+
LB: /^(LB[0-9]{2})\d{4}[A-Z0-9]{20}$/,
|
|
60
|
+
LC: /^(LC[0-9]{2})[A-Z]{4}[A-Z0-9]{24}$/,
|
|
61
|
+
LI: /^(LI[0-9]{2})\d{5}[A-Z0-9]{12}$/,
|
|
62
|
+
LT: /^(LT[0-9]{2})\d{16}$/,
|
|
63
|
+
LU: /^(LU[0-9]{2})\d{3}[A-Z0-9]{13}$/,
|
|
64
|
+
LV: /^(LV[0-9]{2})[A-Z]{4}[A-Z0-9]{13}$/,
|
|
65
|
+
MA: /^(MA[0-9]{26})$/,
|
|
66
|
+
MC: /^(MC[0-9]{2})\d{10}[A-Z0-9]{11}\d{2}$/,
|
|
67
|
+
MD: /^(MD[0-9]{2})[A-Z0-9]{20}$/,
|
|
68
|
+
ME: /^(ME[0-9]{2})\d{18}$/,
|
|
69
|
+
MK: /^(MK[0-9]{2})\d{3}[A-Z0-9]{10}\d{2}$/,
|
|
70
|
+
MR: /^(MR[0-9]{2})\d{23}$/,
|
|
71
|
+
MT: /^(MT[0-9]{2})[A-Z]{4}\d{5}[A-Z0-9]{18}$/,
|
|
72
|
+
MU: /^(MU[0-9]{2})[A-Z]{4}\d{19}[A-Z]{3}$/,
|
|
73
|
+
MZ: /^(MZ[0-9]{2})\d{21}$/,
|
|
74
|
+
NL: /^(NL[0-9]{2})[A-Z]{4}\d{10}$/,
|
|
75
|
+
NO: /^(NO[0-9]{2})\d{11}$/,
|
|
76
|
+
PK: /^(PK[0-9]{2})[A-Z0-9]{4}\d{16}$/,
|
|
77
|
+
PL: /^(PL[0-9]{2})\d{24}$/,
|
|
78
|
+
PS: /^(PS[0-9]{2})[A-Z]{4}[A-Z0-9]{21}$/,
|
|
79
|
+
PT: /^(PT[0-9]{2})\d{21}$/,
|
|
80
|
+
QA: /^(QA[0-9]{2})[A-Z]{4}[A-Z0-9]{21}$/,
|
|
81
|
+
RO: /^(RO[0-9]{2})[A-Z]{4}[A-Z0-9]{16}$/,
|
|
82
|
+
RS: /^(RS[0-9]{2})\d{18}$/,
|
|
83
|
+
SA: /^(SA[0-9]{2})\d{2}[A-Z0-9]{18}$/,
|
|
84
|
+
SC: /^(SC[0-9]{2})[A-Z]{4}\d{20}[A-Z]{3}$/,
|
|
85
|
+
SE: /^(SE[0-9]{2})\d{20}$/,
|
|
86
|
+
SI: /^(SI[0-9]{2})\d{15}$/,
|
|
87
|
+
SK: /^(SK[0-9]{2})\d{20}$/,
|
|
88
|
+
SM: /^(SM[0-9]{2})[A-Z]{1}\d{10}[A-Z0-9]{12}$/,
|
|
89
|
+
SV: /^(SV[0-9]{2})[A-Z0-9]{4}\d{20}$/,
|
|
90
|
+
TL: /^(TL[0-9]{2})\d{19}$/,
|
|
91
|
+
TN: /^(TN[0-9]{2})\d{20}$/,
|
|
92
|
+
TR: /^(TR[0-9]{2})\d{5}[A-Z0-9]{17}$/,
|
|
93
|
+
UA: /^(UA[0-9]{2})\d{6}[A-Z0-9]{19}$/,
|
|
94
|
+
VA: /^(VA[0-9]{2})\d{18}$/,
|
|
95
|
+
VG: /^(VG[0-9]{2})[A-Z]{4}\d{16}$/,
|
|
96
|
+
XK: /^(XK[0-9]{2})\d{16}$/
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Check if the country codes passed are valid using the
|
|
101
|
+
* ibanRegexThroughCountryCode as a reference
|
|
102
|
+
*
|
|
103
|
+
* @param {array} countryCodeArray
|
|
104
|
+
* @return {boolean}
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
function hasOnlyValidCountryCodes(countryCodeArray) {
|
|
108
|
+
var countryCodeArrayFilteredWithObjectIbanCode = countryCodeArray.filter(function (countryCode) {
|
|
109
|
+
return !(countryCode in ibanRegexThroughCountryCode);
|
|
110
|
+
});
|
|
111
|
+
return countryCodeArrayFilteredWithObjectIbanCode.length === 0;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Check whether string has correct universal IBAN format
|
|
116
|
+
* The IBAN consists of up to 34 alphanumeric characters, as follows:
|
|
117
|
+
* Country Code using ISO 3166-1 alpha-2, two letters
|
|
118
|
+
* check digits, two digits and
|
|
119
|
+
* Basic Bank Account Number (BBAN), up to 30 alphanumeric characters.
|
|
120
|
+
* NOTE: Permitted IBAN characters are: digits [0-9] and the 26 latin alphabetic [A-Z]
|
|
121
|
+
*
|
|
122
|
+
* @param {string} str - string under validation
|
|
123
|
+
* @param {object} options - object to pass the countries to be either whitelisted or blacklisted
|
|
124
|
+
* @return {boolean}
|
|
125
|
+
*/
|
|
126
|
+
function hasValidIbanFormat(str, options) {
|
|
127
|
+
// Strip white spaces and hyphens
|
|
128
|
+
var strippedStr = str.replace(/[\s\-]+/gi, '').toUpperCase();
|
|
129
|
+
var isoCountryCode = strippedStr.slice(0, 2).toUpperCase();
|
|
130
|
+
var isoCountryCodeInIbanRegexCodeObject = isoCountryCode in ibanRegexThroughCountryCode;
|
|
131
|
+
if (options.whitelist) {
|
|
132
|
+
if (!hasOnlyValidCountryCodes(options.whitelist)) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
var isoCountryCodeInWhiteList = (0, _includesArray.default)(options.whitelist, isoCountryCode);
|
|
136
|
+
if (!isoCountryCodeInWhiteList) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (options.blacklist) {
|
|
141
|
+
var isoCountryCodeInBlackList = (0, _includesArray.default)(options.blacklist, isoCountryCode);
|
|
142
|
+
if (isoCountryCodeInBlackList) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return isoCountryCodeInIbanRegexCodeObject && ibanRegexThroughCountryCode[isoCountryCode].test(strippedStr);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Check whether string has valid IBAN Checksum
|
|
151
|
+
* by performing basic mod-97 operation and
|
|
152
|
+
* the remainder should equal 1
|
|
153
|
+
* -- Start by rearranging the IBAN by moving the four initial characters to the end of the string
|
|
154
|
+
* -- Replace each letter in the string with two digits, A -> 10, B = 11, Z = 35
|
|
155
|
+
* -- Interpret the string as a decimal integer and
|
|
156
|
+
* -- compute the remainder on division by 97 (mod 97)
|
|
157
|
+
* Reference: https://en.wikipedia.org/wiki/International_Bank_Account_Number
|
|
158
|
+
*
|
|
159
|
+
* @param {string} str
|
|
160
|
+
* @return {boolean}
|
|
161
|
+
*/
|
|
162
|
+
function hasValidIbanChecksum(str) {
|
|
163
|
+
var strippedStr = str.replace(/[^A-Z0-9]+/gi, '').toUpperCase(); // Keep only digits and A-Z latin alphabetic
|
|
164
|
+
var rearranged = strippedStr.slice(4) + strippedStr.slice(0, 4);
|
|
165
|
+
var alphaCapsReplacedWithDigits = rearranged.replace(/[A-Z]/g, function (char) {
|
|
166
|
+
return char.charCodeAt(0) - 55;
|
|
167
|
+
});
|
|
168
|
+
var remainder = alphaCapsReplacedWithDigits.match(/\d{1,7}/g).reduce(function (acc, value) {
|
|
169
|
+
return Number(acc + value) % 97;
|
|
170
|
+
}, '');
|
|
171
|
+
return remainder === 1;
|
|
172
|
+
}
|
|
173
|
+
function isIBAN(str) {
|
|
174
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
175
|
+
(0, _assertString.default)(str);
|
|
176
|
+
return hasValidIbanFormat(str, options) && hasValidIbanChecksum(str);
|
|
177
|
+
}
|
|
178
|
+
var locales = exports.locales = Object.keys(ibanRegexThroughCountryCode);
|
package/lib/isIMEI.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isIMEI;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
var imeiRegexWithoutHyphens = /^[0-9]{15}$/;
|
|
10
|
+
var imeiRegexWithHyphens = /^\d{2}-\d{6}-\d{6}-\d{1}$/;
|
|
11
|
+
function isIMEI(str, options) {
|
|
12
|
+
(0, _assertString.default)(str);
|
|
13
|
+
options = options || {};
|
|
14
|
+
|
|
15
|
+
// default regex for checking imei is the one without hyphens
|
|
16
|
+
|
|
17
|
+
var imeiRegex = imeiRegexWithoutHyphens;
|
|
18
|
+
if (options.allow_hyphens) {
|
|
19
|
+
imeiRegex = imeiRegexWithHyphens;
|
|
20
|
+
}
|
|
21
|
+
if (!imeiRegex.test(str)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
str = str.replace(/-/g, '');
|
|
25
|
+
var sum = 0,
|
|
26
|
+
mul = 2,
|
|
27
|
+
l = 14;
|
|
28
|
+
for (var i = 0; i < l; i++) {
|
|
29
|
+
var digit = str.substring(l - i - 1, l - i);
|
|
30
|
+
var tp = parseInt(digit, 10) * mul;
|
|
31
|
+
if (tp >= 10) {
|
|
32
|
+
sum += tp % 10 + 1;
|
|
33
|
+
} else {
|
|
34
|
+
sum += tp;
|
|
35
|
+
}
|
|
36
|
+
if (mul === 1) {
|
|
37
|
+
mul += 1;
|
|
38
|
+
} else {
|
|
39
|
+
mul -= 1;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
var chk = (10 - sum % 10) % 10;
|
|
43
|
+
if (chk !== parseInt(str.substring(14, 15), 10)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
module.exports = exports.default;
|
|
49
|
+
module.exports.default = exports.default;
|
package/lib/isIP.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isIP;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
10
|
+
/**
|
|
11
|
+
11.3. Examples
|
|
12
|
+
|
|
13
|
+
The following addresses
|
|
14
|
+
|
|
15
|
+
fe80::1234 (on the 1st link of the node)
|
|
16
|
+
ff02::5678 (on the 5th link of the node)
|
|
17
|
+
ff08::9abc (on the 10th organization of the node)
|
|
18
|
+
|
|
19
|
+
would be represented as follows:
|
|
20
|
+
|
|
21
|
+
fe80::1234%1
|
|
22
|
+
ff02::5678%5
|
|
23
|
+
ff08::9abc%10
|
|
24
|
+
|
|
25
|
+
(Here we assume a natural translation from a zone index to the
|
|
26
|
+
<zone_id> part, where the Nth zone of any scope is translated into
|
|
27
|
+
"N".)
|
|
28
|
+
|
|
29
|
+
If we use interface names as <zone_id>, those addresses could also be
|
|
30
|
+
represented as follows:
|
|
31
|
+
|
|
32
|
+
fe80::1234%ne0
|
|
33
|
+
ff02::5678%pvc1.3
|
|
34
|
+
ff08::9abc%interface10
|
|
35
|
+
|
|
36
|
+
where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs
|
|
37
|
+
to the 5th link, and "interface10" belongs to the 10th organization.
|
|
38
|
+
* * */
|
|
39
|
+
var IPv4SegmentFormat = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])';
|
|
40
|
+
var IPv4AddressFormat = "(".concat(IPv4SegmentFormat, "[.]){3}").concat(IPv4SegmentFormat);
|
|
41
|
+
var IPv4AddressRegExp = new RegExp("^".concat(IPv4AddressFormat, "$"));
|
|
42
|
+
var IPv6SegmentFormat = '(?:[0-9a-fA-F]{1,4})';
|
|
43
|
+
var IPv6AddressRegExp = new RegExp('^(' + "(?:".concat(IPv6SegmentFormat, ":){7}(?:").concat(IPv6SegmentFormat, "|:)|") + "(?:".concat(IPv6SegmentFormat, ":){6}(?:").concat(IPv4AddressFormat, "|:").concat(IPv6SegmentFormat, "|:)|") + "(?:".concat(IPv6SegmentFormat, ":){5}(?::").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,2}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){4}(?:(:").concat(IPv6SegmentFormat, "){0,1}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,3}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){3}(?:(:").concat(IPv6SegmentFormat, "){0,2}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,4}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){2}(?:(:").concat(IPv6SegmentFormat, "){0,3}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,5}|:)|") + "(?:".concat(IPv6SegmentFormat, ":){1}(?:(:").concat(IPv6SegmentFormat, "){0,4}:").concat(IPv4AddressFormat, "|(:").concat(IPv6SegmentFormat, "){1,6}|:)|") + "(?::((?::".concat(IPv6SegmentFormat, "){0,5}:").concat(IPv4AddressFormat, "|(?::").concat(IPv6SegmentFormat, "){1,7}|:))") + ')(%[0-9a-zA-Z.]{1,})?$');
|
|
44
|
+
function isIP(ipAddress) {
|
|
45
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
46
|
+
(0, _assertString.default)(ipAddress);
|
|
47
|
+
|
|
48
|
+
// accessing 'arguments' for backwards compatibility: isIP(ipAddress [, version])
|
|
49
|
+
// eslint-disable-next-line prefer-rest-params
|
|
50
|
+
var version = (_typeof(options) === 'object' ? options.version : arguments[1]) || '';
|
|
51
|
+
if (!version) {
|
|
52
|
+
return isIP(ipAddress, {
|
|
53
|
+
version: 4
|
|
54
|
+
}) || isIP(ipAddress, {
|
|
55
|
+
version: 6
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (version.toString() === '4') {
|
|
59
|
+
return IPv4AddressRegExp.test(ipAddress);
|
|
60
|
+
}
|
|
61
|
+
if (version.toString() === '6') {
|
|
62
|
+
return IPv6AddressRegExp.test(ipAddress);
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
module.exports = exports.default;
|
|
67
|
+
module.exports.default = exports.default;
|
package/lib/isIPRange.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isIPRange;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
var _isIP = _interopRequireDefault(require("./isIP"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
var subnetMaybe = /^\d{1,3}$/;
|
|
11
|
+
var v4Subnet = 32;
|
|
12
|
+
var v6Subnet = 128;
|
|
13
|
+
function isIPRange(str) {
|
|
14
|
+
var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
15
|
+
(0, _assertString.default)(str);
|
|
16
|
+
var parts = str.split('/');
|
|
17
|
+
|
|
18
|
+
// parts[0] -> ip, parts[1] -> subnet
|
|
19
|
+
if (parts.length !== 2) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (!subnetMaybe.test(parts[1])) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Disallow preceding 0 i.e. 01, 02, ...
|
|
27
|
+
if (parts[1].length > 1 && parts[1].startsWith('0')) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
var isValidIP = (0, _isIP.default)(parts[0], version);
|
|
31
|
+
if (!isValidIP) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Define valid subnet according to IP's version
|
|
36
|
+
var expectedSubnet = null;
|
|
37
|
+
switch (String(version)) {
|
|
38
|
+
case '4':
|
|
39
|
+
expectedSubnet = v4Subnet;
|
|
40
|
+
break;
|
|
41
|
+
case '6':
|
|
42
|
+
expectedSubnet = v6Subnet;
|
|
43
|
+
break;
|
|
44
|
+
default:
|
|
45
|
+
expectedSubnet = (0, _isIP.default)(parts[0], '6') ? v6Subnet : v4Subnet;
|
|
46
|
+
}
|
|
47
|
+
return parts[1] <= expectedSubnet && parts[1] >= 0;
|
|
48
|
+
}
|
|
49
|
+
module.exports = exports.default;
|
|
50
|
+
module.exports.default = exports.default;
|
package/lib/isISBN.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isISBN;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
var possibleIsbn10 = /^(?:[0-9]{9}X|[0-9]{10})$/;
|
|
10
|
+
var possibleIsbn13 = /^(?:[0-9]{13})$/;
|
|
11
|
+
var factor = [1, 3];
|
|
12
|
+
function isISBN(isbn, options) {
|
|
13
|
+
(0, _assertString.default)(isbn);
|
|
14
|
+
|
|
15
|
+
// For backwards compatibility:
|
|
16
|
+
// isISBN(str [, version]), i.e. `options` could be used as argument for the legacy `version`
|
|
17
|
+
var version = String((options === null || options === void 0 ? void 0 : options.version) || options);
|
|
18
|
+
if (!(options !== null && options !== void 0 && options.version || options)) {
|
|
19
|
+
return isISBN(isbn, {
|
|
20
|
+
version: 10
|
|
21
|
+
}) || isISBN(isbn, {
|
|
22
|
+
version: 13
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
var sanitizedIsbn = isbn.replace(/[\s-]+/g, '');
|
|
26
|
+
var checksum = 0;
|
|
27
|
+
if (version === '10') {
|
|
28
|
+
if (!possibleIsbn10.test(sanitizedIsbn)) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
for (var i = 0; i < version - 1; i++) {
|
|
32
|
+
checksum += (i + 1) * sanitizedIsbn.charAt(i);
|
|
33
|
+
}
|
|
34
|
+
if (sanitizedIsbn.charAt(9) === 'X') {
|
|
35
|
+
checksum += 10 * 10;
|
|
36
|
+
} else {
|
|
37
|
+
checksum += 10 * sanitizedIsbn.charAt(9);
|
|
38
|
+
}
|
|
39
|
+
if (checksum % 11 === 0) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
} else if (version === '13') {
|
|
43
|
+
if (!possibleIsbn13.test(sanitizedIsbn)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
for (var _i = 0; _i < 12; _i++) {
|
|
47
|
+
checksum += factor[_i % 2] * sanitizedIsbn.charAt(_i);
|
|
48
|
+
}
|
|
49
|
+
if (sanitizedIsbn.charAt(12) - (10 - checksum % 10) % 10 === 0) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
module.exports = exports.default;
|
|
56
|
+
module.exports.default = exports.default;
|
package/lib/isISIN.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = isISIN;
|
|
7
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
var isin = /^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;
|
|
10
|
+
|
|
11
|
+
// this link details how the check digit is calculated:
|
|
12
|
+
// https://www.isin.org/isin-format/. it is a little bit
|
|
13
|
+
// odd in that it works with digits, not numbers. in order
|
|
14
|
+
// to make only one pass through the ISIN characters, the
|
|
15
|
+
// each alpha character is handled as 2 characters within
|
|
16
|
+
// the loop.
|
|
17
|
+
|
|
18
|
+
function isISIN(str) {
|
|
19
|
+
(0, _assertString.default)(str);
|
|
20
|
+
if (!isin.test(str)) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
var double = true;
|
|
24
|
+
var sum = 0;
|
|
25
|
+
// convert values
|
|
26
|
+
for (var i = str.length - 2; i >= 0; i--) {
|
|
27
|
+
if (str[i] >= 'A' && str[i] <= 'Z') {
|
|
28
|
+
var value = str[i].charCodeAt(0) - 55;
|
|
29
|
+
var lo = value % 10;
|
|
30
|
+
var hi = Math.trunc(value / 10);
|
|
31
|
+
// letters have two digits, so handle the low order
|
|
32
|
+
// and high order digits separately.
|
|
33
|
+
for (var _i = 0, _arr = [lo, hi]; _i < _arr.length; _i++) {
|
|
34
|
+
var digit = _arr[_i];
|
|
35
|
+
if (double) {
|
|
36
|
+
if (digit >= 5) {
|
|
37
|
+
sum += 1 + (digit - 5) * 2;
|
|
38
|
+
} else {
|
|
39
|
+
sum += digit * 2;
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
sum += digit;
|
|
43
|
+
}
|
|
44
|
+
double = !double;
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
var _digit = str[i].charCodeAt(0) - '0'.charCodeAt(0);
|
|
48
|
+
if (double) {
|
|
49
|
+
if (_digit >= 5) {
|
|
50
|
+
sum += 1 + (_digit - 5) * 2;
|
|
51
|
+
} else {
|
|
52
|
+
sum += _digit * 2;
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
sum += _digit;
|
|
56
|
+
}
|
|
57
|
+
double = !double;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
var check = Math.trunc((sum + 9) / 10) * 10 - sum;
|
|
61
|
+
return +str[str.length - 1] === check;
|
|
62
|
+
}
|
|
63
|
+
module.exports = exports.default;
|
|
64
|
+
module.exports.default = exports.default;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ScriptCodes = void 0;
|
|
7
|
+
exports.default = isISO15924;
|
|
8
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
// from https://www.unicode.org/iso15924/iso15924-codes.html
|
|
11
|
+
var validISO15924Codes = new Set(['Adlm', 'Afak', 'Aghb', 'Ahom', 'Arab', 'Aran', 'Armi', 'Armn', 'Avst', 'Bali', 'Bamu', 'Bass', 'Batk', 'Beng', 'Bhks', 'Blis', 'Bopo', 'Brah', 'Brai', 'Bugi', 'Buhd', 'Cakm', 'Cans', 'Cari', 'Cham', 'Cher', 'Chis', 'Chrs', 'Cirt', 'Copt', 'Cpmn', 'Cprt', 'Cyrl', 'Cyrs', 'Deva', 'Diak', 'Dogr', 'Dsrt', 'Dupl', 'Egyd', 'Egyh', 'Egyp', 'Elba', 'Elym', 'Ethi', 'Gara', 'Geok', 'Geor', 'Glag', 'Gong', 'Gonm', 'Goth', 'Gran', 'Grek', 'Gujr', 'Gukh', 'Guru', 'Hanb', 'Hang', 'Hani', 'Hano', 'Hans', 'Hant', 'Hatr', 'Hebr', 'Hira', 'Hluw', 'Hmng', 'Hmnp', 'Hrkt', 'Hung', 'Inds', 'Ital', 'Jamo', 'Java', 'Jpan', 'Jurc', 'Kali', 'Kana', 'Kawi', 'Khar', 'Khmr', 'Khoj', 'Kitl', 'Kits', 'Knda', 'Kore', 'Kpel', 'Krai', 'Kthi', 'Lana', 'Laoo', 'Latf', 'Latg', 'Latn', 'Leke', 'Lepc', 'Limb', 'Lina', 'Linb', 'Lisu', 'Loma', 'Lyci', 'Lydi', 'Mahj', 'Maka', 'Mand', 'Mani', 'Marc', 'Maya', 'Medf', 'Mend', 'Merc', 'Mero', 'Mlym', 'Modi', 'Mong', 'Moon', 'Mroo', 'Mtei', 'Mult', 'Mymr', 'Nagm', 'Nand', 'Narb', 'Nbat', 'Newa', 'Nkdb', 'Nkgb', 'Nkoo', 'Nshu', 'Ogam', 'Olck', 'Onao', 'Orkh', 'Orya', 'Osge', 'Osma', 'Ougr', 'Palm', 'Pauc', 'Pcun', 'Pelm', 'Perm', 'Phag', 'Phli', 'Phlp', 'Phlv', 'Phnx', 'Plrd', 'Piqd', 'Prti', 'Psin', 'Qaaa', 'Qaab', 'Qaac', 'Qaad', 'Qaae', 'Qaaf', 'Qaag', 'Qaah', 'Qaai', 'Qaaj', 'Qaak', 'Qaal', 'Qaam', 'Qaan', 'Qaao', 'Qaap', 'Qaaq', 'Qaar', 'Qaas', 'Qaat', 'Qaau', 'Qaav', 'Qaaw', 'Qaax', 'Qaay', 'Qaaz', 'Qaba', 'Qabb', 'Qabc', 'Qabd', 'Qabe', 'Qabf', 'Qabg', 'Qabh', 'Qabi', 'Qabj', 'Qabk', 'Qabl', 'Qabm', 'Qabn', 'Qabo', 'Qabp', 'Qabq', 'Qabr', 'Qabs', 'Qabt', 'Qabu', 'Qabv', 'Qabw', 'Qabx', 'Ranj', 'Rjng', 'Rohg', 'Roro', 'Runr', 'Samr', 'Sara', 'Sarb', 'Saur', 'Sgnw', 'Shaw', 'Shrd', 'Shui', 'Sidd', 'Sidt', 'Sind', 'Sinh', 'Sogd', 'Sogo', 'Sora', 'Soyo', 'Sund', 'Sunu', 'Sylo', 'Syrc', 'Syre', 'Syrj', 'Syrn', 'Tagb', 'Takr', 'Tale', 'Talu', 'Taml', 'Tang', 'Tavt', 'Tayo', 'Telu', 'Teng', 'Tfng', 'Tglg', 'Thaa', 'Thai', 'Tibt', 'Tirh', 'Tnsa', 'Todr', 'Tols', 'Toto', 'Tutg', 'Ugar', 'Vaii', 'Visp', 'Vith', 'Wara', 'Wcho', 'Wole', 'Xpeo', 'Xsux', 'Yezi', 'Yiii', 'Zanb', 'Zinh', 'Zmth', 'Zsye', 'Zsym', 'Zxxx', 'Zyyy', 'Zzzz']);
|
|
12
|
+
function isISO15924(str) {
|
|
13
|
+
(0, _assertString.default)(str);
|
|
14
|
+
return validISO15924Codes.has(str);
|
|
15
|
+
}
|
|
16
|
+
var ScriptCodes = exports.ScriptCodes = validISO15924Codes;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CountryCodes = void 0;
|
|
7
|
+
exports.default = isISO31661Alpha2;
|
|
8
|
+
var _assertString = _interopRequireDefault(require("./util/assertString"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
// from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
|
11
|
+
var validISO31661Alpha2CountriesCodes = new Set(['AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AO', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AW', 'AX', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BL', 'BM', 'BN', 'BO', 'BQ', 'BR', 'BS', 'BT', 'BV', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN', 'CO', 'CR', 'CU', 'CV', 'CW', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'EH', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'GA', 'GB', 'GD', 'GE', 'GF', 'GG', 'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GW', 'GY', 'HK', 'HM', 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IM', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT', 'JE', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR', 'KW', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'ME', 'MF', 'MG', 'MH', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NC', 'NE', 'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA', 'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PW', 'PY', 'QA', 'RE', 'RO', 'RS', 'RU', 'RW', 'SA', 'SB', 'SC', 'SD', 'SE', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'SS', 'ST', 'SV', 'SX', 'SY', 'SZ', 'TC', 'TD', 'TF', 'TG', 'TH', 'TJ', 'TK', 'TL', 'TM', 'TN', 'TO', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM', 'US', 'UY', 'UZ', 'VA', 'VC', 'VE', 'VG', 'VI', 'VN', 'VU', 'WF', 'WS', 'YE', 'YT', 'ZA', 'ZM', 'ZW']);
|
|
12
|
+
var alpha2CountryCode = /^[a-zA-Z]{2}$/;
|
|
13
|
+
function isISO31661Alpha2(str) {
|
|
14
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
15
|
+
(0, _assertString.default)(str);
|
|
16
|
+
var userAssignedCodes = options.userAssignedCodes;
|
|
17
|
+
var validUserAssignedCodes = (userAssignedCodes || []).reduce(function (accumulator, userAssignedCode) {
|
|
18
|
+
if (alpha2CountryCode.test(userAssignedCode)) {
|
|
19
|
+
accumulator.push(userAssignedCode.toUpperCase());
|
|
20
|
+
}
|
|
21
|
+
return accumulator;
|
|
22
|
+
}, []);
|
|
23
|
+
if (validUserAssignedCodes.includes(str.toUpperCase())) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
return validISO31661Alpha2CountriesCodes.has(str.toUpperCase());
|
|
27
|
+
}
|
|
28
|
+
var CountryCodes = exports.CountryCodes = validISO31661Alpha2CountriesCodes;
|