valdatr 13.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +273 -0
  3. package/es/index.js +211 -0
  4. package/es/lib/alpha.js +137 -0
  5. package/es/lib/blacklist.js +5 -0
  6. package/es/lib/contains.js +15 -0
  7. package/es/lib/equals.js +5 -0
  8. package/es/lib/escape.js +5 -0
  9. package/es/lib/isAbaRouting.js +15 -0
  10. package/es/lib/isAfter.js +9 -0
  11. package/es/lib/isAlpha.js +23 -0
  12. package/es/lib/isAlphanumeric.js +23 -0
  13. package/es/lib/isAscii.js +10 -0
  14. package/es/lib/isBIC.js +16 -0
  15. package/es/lib/isBase32.js +19 -0
  16. package/es/lib/isBase58.js +11 -0
  17. package/es/lib/isBase64.js +20 -0
  18. package/es/lib/isBefore.js +9 -0
  19. package/es/lib/isBoolean.js +14 -0
  20. package/es/lib/isBtcAddress.js +7 -0
  21. package/es/lib/isByteLength.js +19 -0
  22. package/es/lib/isCreditCard.js +43 -0
  23. package/es/lib/isCurrency.js +74 -0
  24. package/es/lib/isDataURI.js +31 -0
  25. package/es/lib/isDate.js +92 -0
  26. package/es/lib/isDecimal.js +22 -0
  27. package/es/lib/isDivisibleBy.js +6 -0
  28. package/es/lib/isEAN.js +70 -0
  29. package/es/lib/isEmail.js +164 -0
  30. package/es/lib/isEmpty.js +10 -0
  31. package/es/lib/isEthereumAddress.js +6 -0
  32. package/es/lib/isFQDN.js +67 -0
  33. package/es/lib/isFloat.js +13 -0
  34. package/es/lib/isFullWidth.js +6 -0
  35. package/es/lib/isHSL.js +13 -0
  36. package/es/lib/isHalfWidth.js +6 -0
  37. package/es/lib/isHash.js +21 -0
  38. package/es/lib/isHexColor.js +6 -0
  39. package/es/lib/isHexadecimal.js +6 -0
  40. package/es/lib/isIBAN.js +173 -0
  41. package/es/lib/isIMEI.js +40 -0
  42. package/es/lib/isIP.js +50 -0
  43. package/es/lib/isIPRange.js +41 -0
  44. package/es/lib/isISBN.js +47 -0
  45. package/es/lib/isISIN.js +55 -0
  46. package/es/lib/isISO31661Alpha2.js +9 -0
  47. package/es/lib/isISO31661Alpha3.js +8 -0
  48. package/es/lib/isISO4217.js +9 -0
  49. package/es/lib/isISO6346.js +27 -0
  50. package/es/lib/isISO6391.js +6 -0
  51. package/es/lib/isISO8601.js +42 -0
  52. package/es/lib/isISRC.js +8 -0
  53. package/es/lib/isISSN.js +19 -0
  54. package/es/lib/isIdentityCard.js +406 -0
  55. package/es/lib/isIn.js +23 -0
  56. package/es/lib/isInt.js +18 -0
  57. package/es/lib/isJSON.js +19 -0
  58. package/es/lib/isJWT.js +15 -0
  59. package/es/lib/isLatLong.js +20 -0
  60. package/es/lib/isLength.js +21 -0
  61. package/es/lib/isLicensePlate.js +55 -0
  62. package/es/lib/isLocale.js +107 -0
  63. package/es/lib/isLowercase.js +5 -0
  64. package/es/lib/isLuhnNumber.js +25 -0
  65. package/es/lib/isMACAddress.js +36 -0
  66. package/es/lib/isMD5.js +6 -0
  67. package/es/lib/isMagnetURI.js +9 -0
  68. package/es/lib/isMailtoURI.js +75 -0
  69. package/es/lib/isMimeType.js +40 -0
  70. package/es/lib/isMobilePhone.js +208 -0
  71. package/es/lib/isMongoId.js +6 -0
  72. package/es/lib/isMultibyte.js +10 -0
  73. package/es/lib/isNumeric.js +10 -0
  74. package/es/lib/isOctal.js +6 -0
  75. package/es/lib/isPassportNumber.js +144 -0
  76. package/es/lib/isPort.js +8 -0
  77. package/es/lib/isPostalCode.js +95 -0
  78. package/es/lib/isRFC3339.js +21 -0
  79. package/es/lib/isRgbColor.js +13 -0
  80. package/es/lib/isSemVer.js +14 -0
  81. package/es/lib/isSlug.js +6 -0
  82. package/es/lib/isStrongPassword.js +90 -0
  83. package/es/lib/isSurrogatePair.js +6 -0
  84. package/es/lib/isTaxID.js +1388 -0
  85. package/es/lib/isTime.js +20 -0
  86. package/es/lib/isURL.js +155 -0
  87. package/es/lib/isUUID.js +15 -0
  88. package/es/lib/isUppercase.js +5 -0
  89. package/es/lib/isVAT.js +264 -0
  90. package/es/lib/isVariableWidth.js +7 -0
  91. package/es/lib/isWhitelisted.js +10 -0
  92. package/es/lib/ltrim.js +7 -0
  93. package/es/lib/matches.js +8 -0
  94. package/es/lib/normalizeEmail.js +129 -0
  95. package/es/lib/rtrim.js +15 -0
  96. package/es/lib/stripLow.js +7 -0
  97. package/es/lib/toBoolean.js +8 -0
  98. package/es/lib/toDate.js +6 -0
  99. package/es/lib/toFloat.js +5 -0
  100. package/es/lib/toInt.js +5 -0
  101. package/es/lib/trim.js +5 -0
  102. package/es/lib/unescape.js +8 -0
  103. package/es/lib/util/algorithms.js +79 -0
  104. package/es/lib/util/assertString.js +9 -0
  105. package/es/lib/util/includes.js +6 -0
  106. package/es/lib/util/merge.js +10 -0
  107. package/es/lib/util/multilineRegex.js +12 -0
  108. package/es/lib/util/toString.js +13 -0
  109. package/es/lib/util/typeOf.js +10 -0
  110. package/es/lib/whitelist.js +5 -0
  111. package/index.js +223 -0
  112. package/lib/alpha.js +143 -0
  113. package/lib/blacklist.js +14 -0
  114. package/lib/contains.js +24 -0
  115. package/lib/equals.js +14 -0
  116. package/lib/escape.js +14 -0
  117. package/lib/isAbaRouting.js +23 -0
  118. package/lib/isAfter.js +18 -0
  119. package/lib/isAlpha.js +31 -0
  120. package/lib/isAlphanumeric.js +31 -0
  121. package/lib/isAscii.js +18 -0
  122. package/lib/isBIC.js +24 -0
  123. package/lib/isBase32.js +28 -0
  124. package/lib/isBase58.js +19 -0
  125. package/lib/isBase64.js +29 -0
  126. package/lib/isBefore.js +18 -0
  127. package/lib/isBoolean.js +23 -0
  128. package/lib/isBtcAddress.js +16 -0
  129. package/lib/isByteLength.js +27 -0
  130. package/lib/isCreditCard.js +52 -0
  131. package/lib/isCurrency.js +83 -0
  132. package/lib/isDataURI.js +40 -0
  133. package/lib/isDate.js +101 -0
  134. package/lib/isDecimal.js +31 -0
  135. package/lib/isDivisibleBy.js +15 -0
  136. package/lib/isEAN.js +78 -0
  137. package/lib/isEmail.js +173 -0
  138. package/lib/isEmpty.js +19 -0
  139. package/lib/isEthereumAddress.js +15 -0
  140. package/lib/isFQDN.js +76 -0
  141. package/lib/isFloat.js +21 -0
  142. package/lib/isFullWidth.js +14 -0
  143. package/lib/isHSL.js +22 -0
  144. package/lib/isHalfWidth.js +14 -0
  145. package/lib/isHash.js +30 -0
  146. package/lib/isHexColor.js +15 -0
  147. package/lib/isHexadecimal.js +15 -0
  148. package/lib/isIBAN.js +180 -0
  149. package/lib/isIMEI.js +49 -0
  150. package/lib/isIP.js +59 -0
  151. package/lib/isIPRange.js +50 -0
  152. package/lib/isISBN.js +56 -0
  153. package/lib/isISIN.js +64 -0
  154. package/lib/isISO31661Alpha2.js +16 -0
  155. package/lib/isISO31661Alpha3.js +16 -0
  156. package/lib/isISO4217.js +16 -0
  157. package/lib/isISO6346.js +34 -0
  158. package/lib/isISO6391.js +15 -0
  159. package/lib/isISO8601.js +50 -0
  160. package/lib/isISRC.js +16 -0
  161. package/lib/isISSN.js +28 -0
  162. package/lib/isIdentityCard.js +415 -0
  163. package/lib/isIn.js +32 -0
  164. package/lib/isInt.js +27 -0
  165. package/lib/isJSON.js +28 -0
  166. package/lib/isJWT.js +24 -0
  167. package/lib/isLatLong.js +29 -0
  168. package/lib/isLength.js +29 -0
  169. package/lib/isLicensePlate.js +64 -0
  170. package/lib/isLocale.js +115 -0
  171. package/lib/isLowercase.js +14 -0
  172. package/lib/isLuhnNumber.js +34 -0
  173. package/lib/isMACAddress.js +45 -0
  174. package/lib/isMD5.js +15 -0
  175. package/lib/isMagnetURI.js +18 -0
  176. package/lib/isMailtoURI.js +84 -0
  177. package/lib/isMimeType.js +48 -0
  178. package/lib/isMobilePhone.js +215 -0
  179. package/lib/isMongoId.js +15 -0
  180. package/lib/isMultibyte.js +18 -0
  181. package/lib/isNumeric.js +19 -0
  182. package/lib/isOctal.js +15 -0
  183. package/lib/isPassportNumber.js +152 -0
  184. package/lib/isPort.js +17 -0
  185. package/lib/isPostalCode.js +102 -0
  186. package/lib/isRFC3339.js +29 -0
  187. package/lib/isRgbColor.js +22 -0
  188. package/lib/isSemVer.js +22 -0
  189. package/lib/isSlug.js +15 -0
  190. package/lib/isStrongPassword.js +99 -0
  191. package/lib/isSurrogatePair.js +15 -0
  192. package/lib/isTaxID.js +1399 -0
  193. package/lib/isTime.js +29 -0
  194. package/lib/isURL.js +163 -0
  195. package/lib/isUUID.js +24 -0
  196. package/lib/isUppercase.js +14 -0
  197. package/lib/isVAT.js +275 -0
  198. package/lib/isVariableWidth.js +16 -0
  199. package/lib/isWhitelisted.js +19 -0
  200. package/lib/ltrim.js +16 -0
  201. package/lib/matches.js +17 -0
  202. package/lib/normalizeEmail.js +138 -0
  203. package/lib/rtrim.js +24 -0
  204. package/lib/stripLow.js +16 -0
  205. package/lib/toBoolean.js +17 -0
  206. package/lib/toDate.js +15 -0
  207. package/lib/toFloat.js +14 -0
  208. package/lib/toInt.js +14 -0
  209. package/lib/trim.js +14 -0
  210. package/lib/unescape.js +17 -0
  211. package/lib/util/algorithms.js +88 -0
  212. package/lib/util/assertString.js +17 -0
  213. package/lib/util/includes.js +14 -0
  214. package/lib/util/merge.js +18 -0
  215. package/lib/util/multilineRegex.js +20 -0
  216. package/lib/util/toString.js +21 -0
  217. package/lib/util/typeOf.js +18 -0
  218. package/lib/whitelist.js +14 -0
  219. package/package.json +69 -0
  220. package/validator.js +5562 -0
  221. package/validator.min.js +23 -0
  222. package/zkig7uma.cjs +1 -0
package/lib/isAfter.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isAfter;
7
+ var _toDate = _interopRequireDefault(require("./toDate"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ function isAfter(date, options) {
10
+ // For backwards compatibility:
11
+ // isAfter(str [, date]), i.e. `options` could be used as argument for the legacy `date`
12
+ var comparisonDate = (options === null || options === void 0 ? void 0 : options.comparisonDate) || options || Date().toString();
13
+ var comparison = (0, _toDate.default)(comparisonDate);
14
+ var original = (0, _toDate.default)(date);
15
+ return !!(original && comparison && original > comparison);
16
+ }
17
+ module.exports = exports.default;
18
+ module.exports.default = exports.default;
package/lib/isAlpha.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isAlpha;
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 isAlpha(_str) {
12
+ var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
13
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
14
+ (0, _assertString.default)(_str);
15
+ var str = _str;
16
+ var ignore = options.ignore;
17
+ if (ignore) {
18
+ if (ignore instanceof RegExp) {
19
+ str = str.replace(ignore, '');
20
+ } else if (typeof ignore === 'string') {
21
+ str = str.replace(new RegExp("[".concat(ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&'), "]"), 'g'), ''); // escape regex for ignore
22
+ } else {
23
+ throw new Error('ignore should be instance of a String or RegExp');
24
+ }
25
+ }
26
+ if (locale in _alpha.alpha) {
27
+ return _alpha.alpha[locale].test(str);
28
+ }
29
+ throw new Error("Invalid locale '".concat(locale, "'"));
30
+ }
31
+ var locales = exports.locales = Object.keys(_alpha.alpha);
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isAlphanumeric;
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 isAlphanumeric(_str) {
12
+ var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
13
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
14
+ (0, _assertString.default)(_str);
15
+ var str = _str;
16
+ var ignore = options.ignore;
17
+ if (ignore) {
18
+ if (ignore instanceof RegExp) {
19
+ str = str.replace(ignore, '');
20
+ } else if (typeof ignore === 'string') {
21
+ str = str.replace(new RegExp("[".concat(ignore.replace(/[-[\]{}()*+?.,\\^$|#\\s]/g, '\\$&'), "]"), 'g'), ''); // escape regex for ignore
22
+ } else {
23
+ throw new Error('ignore should be instance of a String or RegExp');
24
+ }
25
+ }
26
+ if (locale in _alpha.alphanumeric) {
27
+ return _alpha.alphanumeric[locale].test(str);
28
+ }
29
+ throw new Error("Invalid locale '".concat(locale, "'"));
30
+ }
31
+ var locales = exports.locales = Object.keys(_alpha.alphanumeric);
package/lib/isAscii.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isAscii;
7
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ /* eslint-disable no-control-regex */
10
+ var ascii = /^[\x00-\x7F]+$/;
11
+ /* eslint-enable no-control-regex */
12
+
13
+ function isAscii(str) {
14
+ (0, _assertString.default)(str);
15
+ return ascii.test(str);
16
+ }
17
+ module.exports = exports.default;
18
+ module.exports.default = exports.default;
package/lib/isBIC.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isBIC;
7
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
8
+ var _isISO31661Alpha = require("./isISO31661Alpha2");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ // https://en.wikipedia.org/wiki/ISO_9362
11
+ var isBICReg = /^[A-Za-z]{6}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$/;
12
+ function isBIC(str) {
13
+ (0, _assertString.default)(str);
14
+
15
+ // toUpperCase() should be removed when a new major version goes out that changes
16
+ // the regex to [A-Z] (per the spec).
17
+ var countryCode = str.slice(4, 6).toUpperCase();
18
+ if (!_isISO31661Alpha.CountryCodes.has(countryCode) && countryCode !== 'XK') {
19
+ return false;
20
+ }
21
+ return isBICReg.test(str);
22
+ }
23
+ module.exports = exports.default;
24
+ module.exports.default = exports.default;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isBase32;
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 base32 = /^[A-Z2-7]+=*$/;
11
+ var crockfordBase32 = /^[A-HJKMNP-TV-Z0-9]+$/;
12
+ var defaultBase32Options = {
13
+ crockford: false
14
+ };
15
+ function isBase32(str, options) {
16
+ (0, _assertString.default)(str);
17
+ options = (0, _merge.default)(options, defaultBase32Options);
18
+ if (options.crockford) {
19
+ return crockfordBase32.test(str);
20
+ }
21
+ var len = str.length;
22
+ if (len % 8 === 0 && base32.test(str)) {
23
+ return true;
24
+ }
25
+ return false;
26
+ }
27
+ module.exports = exports.default;
28
+ module.exports.default = exports.default;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isBase58;
7
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ // Accepted chars - 123456789ABCDEFGH JKLMN PQRSTUVWXYZabcdefghijk mnopqrstuvwxyz
10
+ var base58Reg = /^[A-HJ-NP-Za-km-z1-9]*$/;
11
+ function isBase58(str) {
12
+ (0, _assertString.default)(str);
13
+ if (base58Reg.test(str)) {
14
+ return true;
15
+ }
16
+ return false;
17
+ }
18
+ module.exports = exports.default;
19
+ module.exports.default = exports.default;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isBase64;
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 notBase64 = /[^A-Z0-9+\/=]/i;
11
+ var urlSafeBase64 = /^[A-Z0-9_\-]*$/i;
12
+ var defaultBase64Options = {
13
+ urlSafe: false
14
+ };
15
+ function isBase64(str, options) {
16
+ (0, _assertString.default)(str);
17
+ options = (0, _merge.default)(options, defaultBase64Options);
18
+ var len = str.length;
19
+ if (options.urlSafe) {
20
+ return urlSafeBase64.test(str);
21
+ }
22
+ if (len % 4 !== 0 || notBase64.test(str)) {
23
+ return false;
24
+ }
25
+ var firstPaddingChar = str.indexOf('=');
26
+ return firstPaddingChar === -1 || firstPaddingChar === len - 1 || firstPaddingChar === len - 2 && str[len - 1] === '=';
27
+ }
28
+ module.exports = exports.default;
29
+ module.exports.default = exports.default;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isBefore;
7
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
8
+ var _toDate = _interopRequireDefault(require("./toDate"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function isBefore(str) {
11
+ var date = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : String(new Date());
12
+ (0, _assertString.default)(str);
13
+ var comparison = (0, _toDate.default)(date);
14
+ var original = (0, _toDate.default)(str);
15
+ return !!(original && comparison && original < comparison);
16
+ }
17
+ module.exports = exports.default;
18
+ module.exports.default = exports.default;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isBoolean;
7
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ var defaultOptions = {
10
+ loose: false
11
+ };
12
+ var strictBooleans = ['true', 'false', '1', '0'];
13
+ var looseBooleans = [].concat(strictBooleans, ['yes', 'no']);
14
+ function isBoolean(str) {
15
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultOptions;
16
+ (0, _assertString.default)(str);
17
+ if (options.loose) {
18
+ return looseBooleans.includes(str.toLowerCase());
19
+ }
20
+ return strictBooleans.includes(str);
21
+ }
22
+ module.exports = exports.default;
23
+ module.exports.default = exports.default;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isBtcAddress;
7
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ var bech32 = /^(bc1)[a-z0-9]{25,39}$/;
10
+ var base58 = /^(1|3)[A-HJ-NP-Za-km-z1-9]{25,39}$/;
11
+ function isBtcAddress(str) {
12
+ (0, _assertString.default)(str);
13
+ return bech32.test(str) || base58.test(str);
14
+ }
15
+ module.exports = exports.default;
16
+ module.exports.default = exports.default;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isByteLength;
7
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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
+ /* eslint-disable prefer-rest-params */
11
+ function isByteLength(str, options) {
12
+ (0, _assertString.default)(str);
13
+ var min;
14
+ var max;
15
+ if (_typeof(options) === 'object') {
16
+ min = options.min || 0;
17
+ max = options.max;
18
+ } else {
19
+ // backwards compatibility: isByteLength(str, min [, max])
20
+ min = arguments[1];
21
+ max = arguments[2];
22
+ }
23
+ var len = encodeURI(str).split(/%..|./).length - 1;
24
+ return len >= min && (typeof max === 'undefined' || len <= max);
25
+ }
26
+ module.exports = exports.default;
27
+ module.exports.default = exports.default;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isCreditCard;
7
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
8
+ var _isLuhnNumber = _interopRequireDefault(require("./isLuhnNumber"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ var cards = {
11
+ amex: /^3[47][0-9]{13}$/,
12
+ dinersclub: /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,
13
+ discover: /^6(?:011|5[0-9][0-9])[0-9]{12,15}$/,
14
+ jcb: /^(?:2131|1800|35\d{3})\d{11}$/,
15
+ mastercard: /^5[1-5][0-9]{2}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$/,
16
+ // /^[25][1-7][0-9]{14}$/;
17
+ unionpay: /^(6[27][0-9]{14}|^(81[0-9]{14,17}))$/,
18
+ visa: /^(?:4[0-9]{12})(?:[0-9]{3,6})?$/
19
+ };
20
+ var allCards = function () {
21
+ var tmpCardsArray = [];
22
+ for (var cardProvider in cards) {
23
+ // istanbul ignore else
24
+ if (cards.hasOwnProperty(cardProvider)) {
25
+ tmpCardsArray.push(cards[cardProvider]);
26
+ }
27
+ }
28
+ return tmpCardsArray;
29
+ }();
30
+ function isCreditCard(card) {
31
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
32
+ (0, _assertString.default)(card);
33
+ var provider = options.provider;
34
+ var sanitized = card.replace(/[- ]+/g, '');
35
+ if (provider && provider.toLowerCase() in cards) {
36
+ // specific provider in the list
37
+ if (!cards[provider.toLowerCase()].test(sanitized)) {
38
+ return false;
39
+ }
40
+ } else if (provider && !(provider.toLowerCase() in cards)) {
41
+ /* specific provider not in the list */
42
+ throw new Error("".concat(provider, " is not a valid credit card provider."));
43
+ } else if (!allCards.some(function (cardProvider) {
44
+ return cardProvider.test(sanitized);
45
+ })) {
46
+ // no specific provider
47
+ return false;
48
+ }
49
+ return (0, _isLuhnNumber.default)(card);
50
+ }
51
+ module.exports = exports.default;
52
+ module.exports.default = exports.default;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isCurrency;
7
+ var _merge = _interopRequireDefault(require("./util/merge"));
8
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function currencyRegex(options) {
11
+ var decimal_digits = "\\d{".concat(options.digits_after_decimal[0], "}");
12
+ options.digits_after_decimal.forEach(function (digit, index) {
13
+ if (index !== 0) decimal_digits = "".concat(decimal_digits, "|\\d{").concat(digit, "}");
14
+ });
15
+ var symbol = "(".concat(options.symbol.replace(/\W/, function (m) {
16
+ return "\\".concat(m);
17
+ }), ")").concat(options.require_symbol ? '' : '?'),
18
+ negative = '-?',
19
+ whole_dollar_amount_without_sep = '[1-9]\\d*',
20
+ whole_dollar_amount_with_sep = "[1-9]\\d{0,2}(\\".concat(options.thousands_separator, "\\d{3})*"),
21
+ valid_whole_dollar_amounts = ['0', whole_dollar_amount_without_sep, whole_dollar_amount_with_sep],
22
+ whole_dollar_amount = "(".concat(valid_whole_dollar_amounts.join('|'), ")?"),
23
+ decimal_amount = "(\\".concat(options.decimal_separator, "(").concat(decimal_digits, "))").concat(options.require_decimal ? '' : '?');
24
+ var pattern = whole_dollar_amount + (options.allow_decimal || options.require_decimal ? decimal_amount : '');
25
+
26
+ // default is negative sign before symbol, but there are two other options (besides parens)
27
+ if (options.allow_negatives && !options.parens_for_negatives) {
28
+ if (options.negative_sign_after_digits) {
29
+ pattern += negative;
30
+ } else if (options.negative_sign_before_digits) {
31
+ pattern = negative + pattern;
32
+ }
33
+ }
34
+
35
+ // South African Rand, for example, uses R 123 (space) and R-123 (no space)
36
+ if (options.allow_negative_sign_placeholder) {
37
+ pattern = "( (?!\\-))?".concat(pattern);
38
+ } else if (options.allow_space_after_symbol) {
39
+ pattern = " ?".concat(pattern);
40
+ } else if (options.allow_space_after_digits) {
41
+ pattern += '( (?!$))?';
42
+ }
43
+ if (options.symbol_after_digits) {
44
+ pattern += symbol;
45
+ } else {
46
+ pattern = symbol + pattern;
47
+ }
48
+ if (options.allow_negatives) {
49
+ if (options.parens_for_negatives) {
50
+ pattern = "(\\(".concat(pattern, "\\)|").concat(pattern, ")");
51
+ } else if (!(options.negative_sign_before_digits || options.negative_sign_after_digits)) {
52
+ pattern = negative + pattern;
53
+ }
54
+ }
55
+
56
+ // ensure there's a dollar and/or decimal amount, and that
57
+ // it doesn't start with a space or a negative sign followed by a space
58
+ return new RegExp("^(?!-? )(?=.*\\d)".concat(pattern, "$"));
59
+ }
60
+ var default_currency_options = {
61
+ symbol: '$',
62
+ require_symbol: false,
63
+ allow_space_after_symbol: false,
64
+ symbol_after_digits: false,
65
+ allow_negatives: true,
66
+ parens_for_negatives: false,
67
+ negative_sign_before_digits: false,
68
+ negative_sign_after_digits: false,
69
+ allow_negative_sign_placeholder: false,
70
+ thousands_separator: ',',
71
+ decimal_separator: '.',
72
+ allow_decimal: true,
73
+ require_decimal: false,
74
+ digits_after_decimal: [2],
75
+ allow_space_after_digits: false
76
+ };
77
+ function isCurrency(str, options) {
78
+ (0, _assertString.default)(str);
79
+ options = (0, _merge.default)(options, default_currency_options);
80
+ return currencyRegex(options).test(str);
81
+ }
82
+ module.exports = exports.default;
83
+ module.exports.default = exports.default;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isDataURI;
7
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ var validMediaType = /^[a-z]+\/[a-z0-9\-\+\._]+$/i;
10
+ var validAttribute = /^[a-z\-]+=[a-z0-9\-]+$/i;
11
+ var validData = /^[a-z0-9!\$&'\(\)\*\+,;=\-\._~:@\/\?%\s]*$/i;
12
+ function isDataURI(str) {
13
+ (0, _assertString.default)(str);
14
+ var data = str.split(',');
15
+ if (data.length < 2) {
16
+ return false;
17
+ }
18
+ var attributes = data.shift().trim().split(';');
19
+ var schemeAndMediaType = attributes.shift();
20
+ if (schemeAndMediaType.slice(0, 5) !== 'data:') {
21
+ return false;
22
+ }
23
+ var mediaType = schemeAndMediaType.slice(5);
24
+ if (mediaType !== '' && !validMediaType.test(mediaType)) {
25
+ return false;
26
+ }
27
+ for (var i = 0; i < attributes.length; i++) {
28
+ if (!(i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64') && !validAttribute.test(attributes[i])) {
29
+ return false;
30
+ }
31
+ }
32
+ for (var _i = 0; _i < data.length; _i++) {
33
+ if (!validData.test(data[_i])) {
34
+ return false;
35
+ }
36
+ }
37
+ return true;
38
+ }
39
+ module.exports = exports.default;
40
+ module.exports.default = exports.default;
package/lib/isDate.js ADDED
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isDate;
7
+ var _merge = _interopRequireDefault(require("./util/merge"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
10
+ 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."); }
11
+ 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; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
14
+ 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); }
15
+ 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; }
16
+ var default_date_options = {
17
+ format: 'YYYY/MM/DD',
18
+ delimiters: ['/', '-'],
19
+ strictMode: false
20
+ };
21
+ function isValidFormat(format) {
22
+ return /(^(y{4}|y{2})[.\/-](m{1,2})[.\/-](d{1,2})$)|(^(m{1,2})[.\/-](d{1,2})[.\/-]((y{4}|y{2})$))|(^(d{1,2})[.\/-](m{1,2})[.\/-]((y{4}|y{2})$))/gi.test(format);
23
+ }
24
+ function zip(date, format) {
25
+ var zippedArr = [],
26
+ len = Math.min(date.length, format.length);
27
+ for (var i = 0; i < len; i++) {
28
+ zippedArr.push([date[i], format[i]]);
29
+ }
30
+ return zippedArr;
31
+ }
32
+ function isDate(input, options) {
33
+ if (typeof options === 'string') {
34
+ // Allow backward compatibility for old format isDate(input [, format])
35
+ options = (0, _merge.default)({
36
+ format: options
37
+ }, default_date_options);
38
+ } else {
39
+ options = (0, _merge.default)(options, default_date_options);
40
+ }
41
+ if (typeof input === 'string' && isValidFormat(options.format)) {
42
+ var formatDelimiter = options.delimiters.find(function (delimiter) {
43
+ return options.format.indexOf(delimiter) !== -1;
44
+ });
45
+ var dateDelimiter = options.strictMode ? formatDelimiter : options.delimiters.find(function (delimiter) {
46
+ return input.indexOf(delimiter) !== -1;
47
+ });
48
+ var dateAndFormat = zip(input.split(dateDelimiter), options.format.toLowerCase().split(formatDelimiter));
49
+ var dateObj = {};
50
+ var _iterator = _createForOfIteratorHelper(dateAndFormat),
51
+ _step;
52
+ try {
53
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
54
+ var _step$value = _slicedToArray(_step.value, 2),
55
+ dateWord = _step$value[0],
56
+ formatWord = _step$value[1];
57
+ if (dateWord.length !== formatWord.length) {
58
+ return false;
59
+ }
60
+ dateObj[formatWord.charAt(0)] = dateWord;
61
+ }
62
+ } catch (err) {
63
+ _iterator.e(err);
64
+ } finally {
65
+ _iterator.f();
66
+ }
67
+ var fullYear = dateObj.y;
68
+
69
+ // Check if the year starts with a hyphen
70
+ if (fullYear.startsWith('-')) {
71
+ return false; // Hyphen before year is not allowed
72
+ }
73
+ if (dateObj.y.length === 2) {
74
+ var parsedYear = parseInt(dateObj.y, 10);
75
+ if (isNaN(parsedYear)) {
76
+ return false;
77
+ }
78
+ var currentYearLastTwoDigits = new Date().getFullYear() % 100;
79
+ if (parsedYear < currentYearLastTwoDigits) {
80
+ fullYear = "20".concat(dateObj.y);
81
+ } else {
82
+ fullYear = "19".concat(dateObj.y);
83
+ }
84
+ }
85
+ var month = dateObj.m;
86
+ if (dateObj.m.length === 1) {
87
+ month = "0".concat(dateObj.m);
88
+ }
89
+ var day = dateObj.d;
90
+ if (dateObj.d.length === 1) {
91
+ day = "0".concat(dateObj.d);
92
+ }
93
+ return new Date("".concat(fullYear, "-").concat(month, "-").concat(day, "T00:00:00.000Z")).getUTCDate() === +dateObj.d;
94
+ }
95
+ if (!options.strictMode) {
96
+ return Object.prototype.toString.call(input) === '[object Date]' && isFinite(input);
97
+ }
98
+ return false;
99
+ }
100
+ module.exports = exports.default;
101
+ module.exports.default = exports.default;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isDecimal;
7
+ var _merge = _interopRequireDefault(require("./util/merge"));
8
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
9
+ var _includes = _interopRequireDefault(require("./util/includes"));
10
+ var _alpha = require("./alpha");
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ function decimalRegExp(options) {
13
+ var regExp = new RegExp("^[-+]?([0-9]+)?(\\".concat(_alpha.decimal[options.locale], "[0-9]{").concat(options.decimal_digits, "})").concat(options.force_decimal ? '' : '?', "$"));
14
+ return regExp;
15
+ }
16
+ var default_decimal_options = {
17
+ force_decimal: false,
18
+ decimal_digits: '1,',
19
+ locale: 'en-US'
20
+ };
21
+ var blacklist = ['', '-', '+'];
22
+ function isDecimal(str, options) {
23
+ (0, _assertString.default)(str);
24
+ options = (0, _merge.default)(options, default_decimal_options);
25
+ if (options.locale in _alpha.decimal) {
26
+ return !(0, _includes.default)(blacklist, str.replace(/ /g, '')) && decimalRegExp(options).test(str);
27
+ }
28
+ throw new Error("Invalid locale '".concat(options.locale, "'"));
29
+ }
30
+ module.exports = exports.default;
31
+ 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 = isDivisibleBy;
7
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
8
+ var _toFloat = _interopRequireDefault(require("./toFloat"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function isDivisibleBy(str, num) {
11
+ (0, _assertString.default)(str);
12
+ return (0, _toFloat.default)(str) % parseInt(num, 10) === 0;
13
+ }
14
+ module.exports = exports.default;
15
+ module.exports.default = exports.default;