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.
Files changed (233) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +269 -0
  3. package/es/index.js +218 -0
  4. package/es/lib/alpha.js +151 -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 +10 -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 +15 -0
  16. package/es/lib/isBase58.js +8 -0
  17. package/es/lib/isBase64.js +23 -0
  18. package/es/lib/isBefore.js +10 -0
  19. package/es/lib/isBoolean.js +15 -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 +93 -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 +165 -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 +14 -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 +13 -0
  39. package/es/lib/isHexadecimal.js +6 -0
  40. package/es/lib/isIBAN.js +171 -0
  41. package/es/lib/isIMEI.js +40 -0
  42. package/es/lib/isIP.js +58 -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/isISO15924.js +9 -0
  47. package/es/lib/isISO31661Alpha2.js +21 -0
  48. package/es/lib/isISO31661Alpha3.js +20 -0
  49. package/es/lib/isISO31661Numeric.js +8 -0
  50. package/es/lib/isISO4217.js +9 -0
  51. package/es/lib/isISO6346.js +28 -0
  52. package/es/lib/isISO6391.js +6 -0
  53. package/es/lib/isISO8601.js +42 -0
  54. package/es/lib/isISRC.js +8 -0
  55. package/es/lib/isISSN.js +19 -0
  56. package/es/lib/isIdentityCard.js +407 -0
  57. package/es/lib/isIn.js +23 -0
  58. package/es/lib/isInt.js +19 -0
  59. package/es/lib/isJSON.js +26 -0
  60. package/es/lib/isJWT.js +15 -0
  61. package/es/lib/isLatLong.js +21 -0
  62. package/es/lib/isLength.js +27 -0
  63. package/es/lib/isLicensePlate.js +58 -0
  64. package/es/lib/isLocale.js +107 -0
  65. package/es/lib/isLowercase.js +5 -0
  66. package/es/lib/isLuhnNumber.js +25 -0
  67. package/es/lib/isMACAddress.js +36 -0
  68. package/es/lib/isMD5.js +6 -0
  69. package/es/lib/isMagnetURI.js +9 -0
  70. package/es/lib/isMailtoURI.js +75 -0
  71. package/es/lib/isMimeType.js +40 -0
  72. package/es/lib/isMobilePhone.js +212 -0
  73. package/es/lib/isMongoId.js +6 -0
  74. package/es/lib/isMultibyte.js +10 -0
  75. package/es/lib/isNumeric.js +10 -0
  76. package/es/lib/isOctal.js +6 -0
  77. package/es/lib/isPassportNumber.js +145 -0
  78. package/es/lib/isPort.js +8 -0
  79. package/es/lib/isPostalCode.js +100 -0
  80. package/es/lib/isRFC3339.js +21 -0
  81. package/es/lib/isRgbColor.js +34 -0
  82. package/es/lib/isSemVer.js +14 -0
  83. package/es/lib/isSlug.js +6 -0
  84. package/es/lib/isStrongPassword.js +90 -0
  85. package/es/lib/isSurrogatePair.js +6 -0
  86. package/es/lib/isTaxID.js +1407 -0
  87. package/es/lib/isTime.js +22 -0
  88. package/es/lib/isULID.js +5 -0
  89. package/es/lib/isURL.js +241 -0
  90. package/es/lib/isUUID.js +23 -0
  91. package/es/lib/isUppercase.js +5 -0
  92. package/es/lib/isVAT.js +264 -0
  93. package/es/lib/isVariableWidth.js +7 -0
  94. package/es/lib/isWhitelisted.js +10 -0
  95. package/es/lib/ltrim.js +7 -0
  96. package/es/lib/matches.js +8 -0
  97. package/es/lib/normalizeEmail.js +131 -0
  98. package/es/lib/rtrim.js +15 -0
  99. package/es/lib/stripLow.js +7 -0
  100. package/es/lib/toBoolean.js +8 -0
  101. package/es/lib/toDate.js +6 -0
  102. package/es/lib/toFloat.js +5 -0
  103. package/es/lib/toInt.js +5 -0
  104. package/es/lib/trim.js +5 -0
  105. package/es/lib/unescape.js +8 -0
  106. package/es/lib/util/algorithms.js +79 -0
  107. package/es/lib/util/assertString.js +4 -0
  108. package/es/lib/util/checkHost.js +12 -0
  109. package/es/lib/util/includesArray.js +6 -0
  110. package/es/lib/util/includesString.js +4 -0
  111. package/es/lib/util/merge.js +14 -0
  112. package/es/lib/util/multilineRegex.js +12 -0
  113. package/es/lib/util/nullUndefinedCheck.js +3 -0
  114. package/es/lib/util/toString.js +13 -0
  115. package/es/lib/util/typeOf.js +10 -0
  116. package/es/lib/whitelist.js +5 -0
  117. package/index.js +229 -0
  118. package/lib/alpha.js +157 -0
  119. package/lib/blacklist.js +14 -0
  120. package/lib/contains.js +24 -0
  121. package/lib/equals.js +14 -0
  122. package/lib/escape.js +14 -0
  123. package/lib/isAbaRouting.js +23 -0
  124. package/lib/isAfter.js +19 -0
  125. package/lib/isAlpha.js +31 -0
  126. package/lib/isAlphanumeric.js +31 -0
  127. package/lib/isAscii.js +18 -0
  128. package/lib/isBIC.js +24 -0
  129. package/lib/isBase32.js +24 -0
  130. package/lib/isBase58.js +16 -0
  131. package/lib/isBase64.js +32 -0
  132. package/lib/isBefore.js +19 -0
  133. package/lib/isBoolean.js +24 -0
  134. package/lib/isBtcAddress.js +16 -0
  135. package/lib/isByteLength.js +27 -0
  136. package/lib/isCreditCard.js +52 -0
  137. package/lib/isCurrency.js +83 -0
  138. package/lib/isDataURI.js +40 -0
  139. package/lib/isDate.js +102 -0
  140. package/lib/isDecimal.js +31 -0
  141. package/lib/isDivisibleBy.js +15 -0
  142. package/lib/isEAN.js +78 -0
  143. package/lib/isEmail.js +174 -0
  144. package/lib/isEmpty.js +19 -0
  145. package/lib/isEthereumAddress.js +15 -0
  146. package/lib/isFQDN.js +76 -0
  147. package/lib/isFloat.js +22 -0
  148. package/lib/isFullWidth.js +14 -0
  149. package/lib/isHSL.js +22 -0
  150. package/lib/isHalfWidth.js +14 -0
  151. package/lib/isHash.js +30 -0
  152. package/lib/isHexColor.js +22 -0
  153. package/lib/isHexadecimal.js +15 -0
  154. package/lib/isIBAN.js +178 -0
  155. package/lib/isIMEI.js +49 -0
  156. package/lib/isIP.js +67 -0
  157. package/lib/isIPRange.js +50 -0
  158. package/lib/isISBN.js +56 -0
  159. package/lib/isISIN.js +64 -0
  160. package/lib/isISO15924.js +16 -0
  161. package/lib/isISO31661Alpha2.js +28 -0
  162. package/lib/isISO31661Alpha3.js +28 -0
  163. package/lib/isISO31661Numeric.js +16 -0
  164. package/lib/isISO4217.js +16 -0
  165. package/lib/isISO6346.js +35 -0
  166. package/lib/isISO6391.js +15 -0
  167. package/lib/isISO8601.js +50 -0
  168. package/lib/isISRC.js +16 -0
  169. package/lib/isISSN.js +28 -0
  170. package/lib/isIdentityCard.js +416 -0
  171. package/lib/isIn.js +32 -0
  172. package/lib/isInt.js +28 -0
  173. package/lib/isJSON.js +35 -0
  174. package/lib/isJWT.js +24 -0
  175. package/lib/isLatLong.js +30 -0
  176. package/lib/isLength.js +35 -0
  177. package/lib/isLicensePlate.js +67 -0
  178. package/lib/isLocale.js +115 -0
  179. package/lib/isLowercase.js +14 -0
  180. package/lib/isLuhnNumber.js +34 -0
  181. package/lib/isMACAddress.js +45 -0
  182. package/lib/isMD5.js +15 -0
  183. package/lib/isMagnetURI.js +18 -0
  184. package/lib/isMailtoURI.js +84 -0
  185. package/lib/isMimeType.js +48 -0
  186. package/lib/isMobilePhone.js +219 -0
  187. package/lib/isMongoId.js +15 -0
  188. package/lib/isMultibyte.js +18 -0
  189. package/lib/isNumeric.js +19 -0
  190. package/lib/isOctal.js +15 -0
  191. package/lib/isPassportNumber.js +152 -0
  192. package/lib/isPort.js +17 -0
  193. package/lib/isPostalCode.js +107 -0
  194. package/lib/isRFC3339.js +29 -0
  195. package/lib/isRgbColor.js +42 -0
  196. package/lib/isSemVer.js +22 -0
  197. package/lib/isSlug.js +15 -0
  198. package/lib/isStrongPassword.js +99 -0
  199. package/lib/isSurrogatePair.js +15 -0
  200. package/lib/isTaxID.js +1417 -0
  201. package/lib/isTime.js +31 -0
  202. package/lib/isULID.js +14 -0
  203. package/lib/isURL.js +249 -0
  204. package/lib/isUUID.js +32 -0
  205. package/lib/isUppercase.js +14 -0
  206. package/lib/isVAT.js +274 -0
  207. package/lib/isVariableWidth.js +16 -0
  208. package/lib/isWhitelisted.js +19 -0
  209. package/lib/ltrim.js +16 -0
  210. package/lib/matches.js +17 -0
  211. package/lib/normalizeEmail.js +140 -0
  212. package/lib/rtrim.js +24 -0
  213. package/lib/stripLow.js +16 -0
  214. package/lib/toBoolean.js +17 -0
  215. package/lib/toDate.js +15 -0
  216. package/lib/toFloat.js +14 -0
  217. package/lib/toInt.js +14 -0
  218. package/lib/trim.js +14 -0
  219. package/lib/unescape.js +17 -0
  220. package/lib/util/algorithms.js +88 -0
  221. package/lib/util/assertString.js +12 -0
  222. package/lib/util/checkHost.js +20 -0
  223. package/lib/util/includesArray.js +14 -0
  224. package/lib/util/includesString.js +12 -0
  225. package/lib/util/merge.js +22 -0
  226. package/lib/util/multilineRegex.js +20 -0
  227. package/lib/util/nullUndefinedCheck.js +11 -0
  228. package/lib/util/toString.js +21 -0
  229. package/lib/util/typeOf.js +18 -0
  230. package/lib/whitelist.js +14 -0
  231. package/package.json +83 -0
  232. package/validator.js +5808 -0
  233. package/validator.min.js +23 -0
package/lib/matches.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = matches;
7
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ function matches(str, pattern, modifiers) {
10
+ (0, _assertString.default)(str);
11
+ if (Object.prototype.toString.call(pattern) !== '[object RegExp]') {
12
+ pattern = new RegExp(pattern, modifiers);
13
+ }
14
+ return !!str.match(pattern);
15
+ }
16
+ module.exports = exports.default;
17
+ module.exports.default = exports.default;
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = normalizeEmail;
7
+ var _merge = _interopRequireDefault(require("./util/merge"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ var default_normalize_email_options = {
10
+ // The following options apply to all email addresses
11
+ // Lowercases the local part of the email address.
12
+ // Please note this may violate RFC 5321 as per http://stackoverflow.com/a/9808332/192024).
13
+ // The domain is always lowercased, as per RFC 1035
14
+ all_lowercase: true,
15
+ // The following conversions are specific to GMail
16
+ // Lowercases the local part of the GMail address (known to be case-insensitive)
17
+ gmail_lowercase: true,
18
+ // Removes dots from the local part of the email address, as that's ignored by GMail
19
+ gmail_remove_dots: true,
20
+ // Removes the subaddress (e.g. "+foo") from the email address
21
+ gmail_remove_subaddress: true,
22
+ // Conversts the googlemail.com domain to gmail.com
23
+ gmail_convert_googlemaildotcom: true,
24
+ // The following conversions are specific to Outlook.com / Windows Live / Hotmail
25
+ // Lowercases the local part of the Outlook.com address (known to be case-insensitive)
26
+ outlookdotcom_lowercase: true,
27
+ // Removes the subaddress (e.g. "+foo") from the email address
28
+ outlookdotcom_remove_subaddress: true,
29
+ // The following conversions are specific to Yahoo
30
+ // Lowercases the local part of the Yahoo address (known to be case-insensitive)
31
+ yahoo_lowercase: true,
32
+ // Removes the subaddress (e.g. "-foo") from the email address
33
+ yahoo_remove_subaddress: true,
34
+ // The following conversions are specific to Yandex
35
+ // Lowercases the local part of the Yandex address (known to be case-insensitive)
36
+ yandex_lowercase: true,
37
+ // all yandex domains are equal, this explicitly sets the domain to 'yandex.ru'
38
+ yandex_convert_yandexru: true,
39
+ // The following conversions are specific to iCloud
40
+ // Lowercases the local part of the iCloud address (known to be case-insensitive)
41
+ icloud_lowercase: true,
42
+ // Removes the subaddress (e.g. "+foo") from the email address
43
+ icloud_remove_subaddress: true
44
+ };
45
+
46
+ // List of domains used by iCloud
47
+ var icloud_domains = ['icloud.com', 'me.com'];
48
+
49
+ // List of domains used by Outlook.com and its predecessors
50
+ // This list is likely incomplete.
51
+ // Partial reference:
52
+ // https://blogs.office.com/2013/04/17/outlook-com-gets-two-step-verification-sign-in-by-alias-and-new-international-domains/
53
+ var outlookdotcom_domains = ['hotmail.at', 'hotmail.be', 'hotmail.ca', 'hotmail.cl', 'hotmail.co.il', 'hotmail.co.nz', 'hotmail.co.th', 'hotmail.co.uk', 'hotmail.com', 'hotmail.com.ar', 'hotmail.com.au', 'hotmail.com.br', 'hotmail.com.gr', 'hotmail.com.mx', 'hotmail.com.pe', 'hotmail.com.tr', 'hotmail.com.vn', 'hotmail.cz', 'hotmail.de', 'hotmail.dk', 'hotmail.es', 'hotmail.fr', 'hotmail.hu', 'hotmail.id', 'hotmail.ie', 'hotmail.in', 'hotmail.it', 'hotmail.jp', 'hotmail.kr', 'hotmail.lv', 'hotmail.my', 'hotmail.ph', 'hotmail.pt', 'hotmail.sa', 'hotmail.sg', 'hotmail.sk', 'live.be', 'live.co.uk', 'live.com', 'live.com.ar', 'live.com.mx', 'live.de', 'live.es', 'live.eu', 'live.fr', 'live.it', 'live.nl', 'msn.com', 'outlook.at', 'outlook.be', 'outlook.cl', 'outlook.co.il', 'outlook.co.nz', 'outlook.co.th', 'outlook.com', 'outlook.com.ar', 'outlook.com.au', 'outlook.com.br', 'outlook.com.gr', 'outlook.com.pe', 'outlook.com.tr', 'outlook.com.vn', 'outlook.cz', 'outlook.de', 'outlook.dk', 'outlook.es', 'outlook.fr', 'outlook.hu', 'outlook.id', 'outlook.ie', 'outlook.in', 'outlook.it', 'outlook.jp', 'outlook.kr', 'outlook.lv', 'outlook.my', 'outlook.ph', 'outlook.pt', 'outlook.sa', 'outlook.sg', 'outlook.sk', 'passport.com'];
54
+
55
+ // List of domains used by Yahoo Mail
56
+ // This list is likely incomplete
57
+ var yahoo_domains = ['rocketmail.com', 'yahoo.ca', 'yahoo.co.uk', 'yahoo.com', 'yahoo.de', 'yahoo.fr', 'yahoo.in', 'yahoo.it', 'ymail.com'];
58
+
59
+ // List of domains used by yandex.ru
60
+ var yandex_domains = ['yandex.ru', 'yandex.ua', 'yandex.kz', 'yandex.com', 'yandex.by', 'ya.ru'];
61
+
62
+ // replace single dots, but not multiple consecutive dots
63
+ function dotsReplacer(match) {
64
+ if (match.length > 1) {
65
+ return match;
66
+ }
67
+ return '';
68
+ }
69
+ function normalizeEmail(email, options) {
70
+ options = (0, _merge.default)(options, default_normalize_email_options);
71
+ var raw_parts = email.split('@');
72
+ var domain = raw_parts.pop();
73
+ var user = raw_parts.join('@');
74
+ var parts = [user, domain];
75
+
76
+ // The domain is always lowercased, as it's case-insensitive per RFC 1035
77
+ parts[1] = parts[1].toLowerCase();
78
+ if (parts[1] === 'gmail.com' || parts[1] === 'googlemail.com') {
79
+ // Address is GMail
80
+ if (options.gmail_remove_subaddress) {
81
+ parts[0] = parts[0].split('+')[0];
82
+ }
83
+ if (options.gmail_remove_dots) {
84
+ // this does not replace consecutive dots like example..email@gmail.com
85
+ parts[0] = parts[0].replace(/\.+/g, dotsReplacer);
86
+ }
87
+ if (!parts[0].length) {
88
+ return false;
89
+ }
90
+ if (options.all_lowercase || options.gmail_lowercase) {
91
+ parts[0] = parts[0].toLowerCase();
92
+ }
93
+ parts[1] = options.gmail_convert_googlemaildotcom ? 'gmail.com' : parts[1];
94
+ } else if (icloud_domains.indexOf(parts[1]) >= 0) {
95
+ // Address is iCloud
96
+ if (options.icloud_remove_subaddress) {
97
+ parts[0] = parts[0].split('+')[0];
98
+ }
99
+ if (!parts[0].length) {
100
+ return false;
101
+ }
102
+ if (options.all_lowercase || options.icloud_lowercase) {
103
+ parts[0] = parts[0].toLowerCase();
104
+ }
105
+ } else if (outlookdotcom_domains.indexOf(parts[1]) >= 0) {
106
+ // Address is Outlook.com
107
+ if (options.outlookdotcom_remove_subaddress) {
108
+ parts[0] = parts[0].split('+')[0];
109
+ }
110
+ if (!parts[0].length) {
111
+ return false;
112
+ }
113
+ if (options.all_lowercase || options.outlookdotcom_lowercase) {
114
+ parts[0] = parts[0].toLowerCase();
115
+ }
116
+ } else if (yahoo_domains.indexOf(parts[1]) >= 0) {
117
+ // Address is Yahoo
118
+ if (options.yahoo_remove_subaddress) {
119
+ var components = parts[0].split('-');
120
+ parts[0] = components.length > 1 ? components.slice(0, -1).join('-') : components[0];
121
+ }
122
+ if (!parts[0].length) {
123
+ return false;
124
+ }
125
+ if (options.all_lowercase || options.yahoo_lowercase) {
126
+ parts[0] = parts[0].toLowerCase();
127
+ }
128
+ } else if (yandex_domains.indexOf(parts[1]) >= 0) {
129
+ if (options.all_lowercase || options.yandex_lowercase) {
130
+ parts[0] = parts[0].toLowerCase();
131
+ }
132
+ parts[1] = options.yandex_convert_yandexru ? 'yandex.ru' : parts[1];
133
+ } else if (options.all_lowercase) {
134
+ // Any other address
135
+ parts[0] = parts[0].toLowerCase();
136
+ }
137
+ return parts.join('@');
138
+ }
139
+ module.exports = exports.default;
140
+ module.exports.default = exports.default;
package/lib/rtrim.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = rtrim;
7
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ function rtrim(str, chars) {
10
+ (0, _assertString.default)(str);
11
+ if (chars) {
12
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
13
+ var pattern = new RegExp("[".concat(chars.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), "]+$"), 'g');
14
+ return str.replace(pattern, '');
15
+ }
16
+ // Use a faster and more safe than regex trim method https://blog.stevenlevithan.com/archives/faster-trim-javascript
17
+ var strIndex = str.length - 1;
18
+ while (/\s/.test(str.charAt(strIndex))) {
19
+ strIndex -= 1;
20
+ }
21
+ return str.slice(0, strIndex + 1);
22
+ }
23
+ module.exports = exports.default;
24
+ 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 = stripLow;
7
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
8
+ var _blacklist = _interopRequireDefault(require("./blacklist"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ function stripLow(str, keep_new_lines) {
11
+ (0, _assertString.default)(str);
12
+ var chars = keep_new_lines ? '\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F' : '\\x00-\\x1F\\x7F';
13
+ return (0, _blacklist.default)(str, chars);
14
+ }
15
+ module.exports = exports.default;
16
+ module.exports.default = exports.default;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = toBoolean;
7
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ function toBoolean(str, strict) {
10
+ (0, _assertString.default)(str);
11
+ if (strict) {
12
+ return str === '1' || /^true$/i.test(str);
13
+ }
14
+ return str !== '0' && !/^false$/i.test(str) && str !== '';
15
+ }
16
+ module.exports = exports.default;
17
+ module.exports.default = exports.default;
package/lib/toDate.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = toDate;
7
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ function toDate(date) {
10
+ (0, _assertString.default)(date);
11
+ date = Date.parse(date);
12
+ return !isNaN(date) ? new Date(date) : null;
13
+ }
14
+ module.exports = exports.default;
15
+ module.exports.default = exports.default;
package/lib/toFloat.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = toFloat;
7
+ var _isFloat = _interopRequireDefault(require("./isFloat"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ function toFloat(str) {
10
+ if (!(0, _isFloat.default)(str)) return NaN;
11
+ return parseFloat(str);
12
+ }
13
+ module.exports = exports.default;
14
+ module.exports.default = exports.default;
package/lib/toInt.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = toInt;
7
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ function toInt(str, radix) {
10
+ (0, _assertString.default)(str);
11
+ return parseInt(str, radix || 10);
12
+ }
13
+ module.exports = exports.default;
14
+ module.exports.default = exports.default;
package/lib/trim.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = trim;
7
+ var _rtrim = _interopRequireDefault(require("./rtrim"));
8
+ var _ltrim = _interopRequireDefault(require("./ltrim"));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ function trim(str, chars) {
11
+ return (0, _rtrim.default)((0, _ltrim.default)(str, chars), chars);
12
+ }
13
+ module.exports = exports.default;
14
+ module.exports.default = exports.default;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = unescape;
7
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ function unescape(str) {
10
+ (0, _assertString.default)(str);
11
+ return str.replace(/&quot;/g, '"').replace(/&#x27;/g, "'").replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&#x2F;/g, '/').replace(/&#x5C;/g, '\\').replace(/&#96;/g, '`').replace(/&amp;/g, '&');
12
+ // &amp; replacement has to be the last one to prevent
13
+ // bugs with intermediate strings containing escape sequences
14
+ // See: https://github.com/validatorjs/validator.js/issues/1827
15
+ }
16
+ module.exports = exports.default;
17
+ module.exports.default = exports.default;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.iso7064Check = iso7064Check;
7
+ exports.luhnCheck = luhnCheck;
8
+ exports.reverseMultiplyAndSum = reverseMultiplyAndSum;
9
+ exports.verhoeffCheck = verhoeffCheck;
10
+ /**
11
+ * Algorithmic validation functions
12
+ * May be used as is or implemented in the workflow of other validators.
13
+ */
14
+
15
+ /*
16
+ * ISO 7064 validation function
17
+ * Called with a string of numbers (incl. check digit)
18
+ * to validate according to ISO 7064 (MOD 11, 10).
19
+ */
20
+ function iso7064Check(str) {
21
+ var checkvalue = 10;
22
+ for (var i = 0; i < str.length - 1; i++) {
23
+ checkvalue = (parseInt(str[i], 10) + checkvalue) % 10 === 0 ? 10 * 2 % 11 : (parseInt(str[i], 10) + checkvalue) % 10 * 2 % 11;
24
+ }
25
+ checkvalue = checkvalue === 1 ? 0 : 11 - checkvalue;
26
+ return checkvalue === parseInt(str[10], 10);
27
+ }
28
+
29
+ /*
30
+ * Luhn (mod 10) validation function
31
+ * Called with a string of numbers (incl. check digit)
32
+ * to validate according to the Luhn algorithm.
33
+ */
34
+ function luhnCheck(str) {
35
+ var checksum = 0;
36
+ var second = false;
37
+ for (var i = str.length - 1; i >= 0; i--) {
38
+ if (second) {
39
+ var product = parseInt(str[i], 10) * 2;
40
+ if (product > 9) {
41
+ // sum digits of product and add to checksum
42
+ checksum += product.toString().split('').map(function (a) {
43
+ return parseInt(a, 10);
44
+ }).reduce(function (a, b) {
45
+ return a + b;
46
+ }, 0);
47
+ } else {
48
+ checksum += product;
49
+ }
50
+ } else {
51
+ checksum += parseInt(str[i], 10);
52
+ }
53
+ second = !second;
54
+ }
55
+ return checksum % 10 === 0;
56
+ }
57
+
58
+ /*
59
+ * Reverse TIN multiplication and summation helper function
60
+ * Called with an array of single-digit integers and a base multiplier
61
+ * to calculate the sum of the digits multiplied in reverse.
62
+ * Normally used in variations of MOD 11 algorithmic checks.
63
+ */
64
+ function reverseMultiplyAndSum(digits, base) {
65
+ var total = 0;
66
+ for (var i = 0; i < digits.length; i++) {
67
+ total += digits[i] * (base - i);
68
+ }
69
+ return total;
70
+ }
71
+
72
+ /*
73
+ * Verhoeff validation helper function
74
+ * Called with a string of numbers
75
+ * to validate according to the Verhoeff algorithm.
76
+ */
77
+ function verhoeffCheck(str) {
78
+ var d_table = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 0, 6, 7, 8, 9, 5], [2, 3, 4, 0, 1, 7, 8, 9, 5, 6], [3, 4, 0, 1, 2, 8, 9, 5, 6, 7], [4, 0, 1, 2, 3, 9, 5, 6, 7, 8], [5, 9, 8, 7, 6, 0, 4, 3, 2, 1], [6, 5, 9, 8, 7, 1, 0, 4, 3, 2], [7, 6, 5, 9, 8, 2, 1, 0, 4, 3], [8, 7, 6, 5, 9, 3, 2, 1, 0, 4], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]];
79
+ var p_table = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 5, 7, 6, 2, 8, 3, 0, 9, 4], [5, 8, 0, 3, 7, 9, 6, 1, 4, 2], [8, 9, 1, 6, 0, 4, 3, 5, 2, 7], [9, 4, 5, 3, 1, 2, 6, 8, 7, 0], [4, 2, 8, 6, 5, 7, 3, 9, 0, 1], [2, 7, 9, 3, 8, 0, 6, 4, 1, 5], [7, 0, 4, 6, 9, 1, 3, 2, 5, 8]];
80
+
81
+ // Copy (to prevent replacement) and reverse
82
+ var str_copy = str.split('').reverse().join('');
83
+ var checksum = 0;
84
+ for (var i = 0; i < str_copy.length; i++) {
85
+ checksum = d_table[checksum][p_table[i % 8][parseInt(str_copy[i], 10)]];
86
+ }
87
+ return checksum === 0;
88
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = assertString;
7
+ function assertString(input) {
8
+ if (input === undefined || input === null) throw new TypeError("Expected a string but received a ".concat(input));
9
+ if (input.constructor.name !== 'String') throw new TypeError("Expected a string but received a ".concat(input.constructor.name));
10
+ }
11
+ module.exports = exports.default;
12
+ module.exports.default = exports.default;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = checkHost;
7
+ function isRegExp(obj) {
8
+ return Object.prototype.toString.call(obj) === '[object RegExp]';
9
+ }
10
+ function checkHost(host, matches) {
11
+ for (var i = 0; i < matches.length; i++) {
12
+ var match = matches[i];
13
+ if (host === match || isRegExp(match) && match.test(host)) {
14
+ return true;
15
+ }
16
+ }
17
+ return false;
18
+ }
19
+ module.exports = exports.default;
20
+ 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 = void 0;
7
+ var includes = function includes(arr, val) {
8
+ return arr.some(function (arrVal) {
9
+ return val === arrVal;
10
+ });
11
+ };
12
+ var _default = exports.default = includes;
13
+ module.exports = exports.default;
14
+ module.exports.default = exports.default;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var includes = function includes(str, val) {
8
+ return str.indexOf(val) !== -1;
9
+ };
10
+ var _default = exports.default = includes;
11
+ module.exports = exports.default;
12
+ 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 = merge;
7
+ 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); }
8
+ function merge() {
9
+ var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10
+ var defaults = arguments.length > 1 ? arguments[1] : undefined;
11
+ if (_typeof(obj) !== 'object' || obj === null) {
12
+ obj = {};
13
+ }
14
+ for (var key in defaults) {
15
+ if (typeof obj[key] === 'undefined') {
16
+ obj[key] = defaults[key];
17
+ }
18
+ }
19
+ return obj;
20
+ }
21
+ module.exports = exports.default;
22
+ module.exports.default = exports.default;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = multilineRegexp;
7
+ /**
8
+ * Build RegExp object from an array
9
+ * of multiple/multi-line regexp parts
10
+ *
11
+ * @param {string[]} parts
12
+ * @param {string} flags
13
+ * @return {object} - RegExp object
14
+ */
15
+ function multilineRegexp(parts, flags) {
16
+ var regexpAsStringLiteral = parts.join('');
17
+ return new RegExp(regexpAsStringLiteral, flags);
18
+ }
19
+ module.exports = exports.default;
20
+ module.exports.default = exports.default;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isNullOrUndefined;
7
+ function isNullOrUndefined(value) {
8
+ return value === null || value === undefined;
9
+ }
10
+ module.exports = exports.default;
11
+ module.exports.default = exports.default;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = toString;
7
+ 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); }
8
+ function toString(input) {
9
+ if (_typeof(input) === 'object' && input !== null) {
10
+ if (typeof input.toString === 'function') {
11
+ input = input.toString();
12
+ } else {
13
+ input = '[object Object]';
14
+ }
15
+ } else if (input === null || typeof input === 'undefined' || isNaN(input) && !input.length) {
16
+ input = '';
17
+ }
18
+ return String(input);
19
+ }
20
+ module.exports = exports.default;
21
+ 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 = typeOf;
7
+ /**
8
+ * Better way to handle type checking
9
+ * null, {}, array and date are objects, which confuses
10
+ */
11
+ function typeOf(input) {
12
+ var rawObject = Object.prototype.toString.call(input).toLowerCase();
13
+ var typeOfRegex = /\[object (.*)]/g;
14
+ var type = typeOfRegex.exec(rawObject)[1];
15
+ return type;
16
+ }
17
+ module.exports = exports.default;
18
+ 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 = whitelist;
7
+ var _assertString = _interopRequireDefault(require("./util/assertString"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ function whitelist(str, chars) {
10
+ (0, _assertString.default)(str);
11
+ return str.replace(new RegExp("[^".concat(chars, "]+"), 'g'), '');
12
+ }
13
+ module.exports = exports.default;
14
+ module.exports.default = exports.default;
package/package.json ADDED
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "validator-string",
3
+ "description": "String validation and sanitization",
4
+ "version": "13.15.36",
5
+ "sideEffects": false,
6
+ "homepage": "https://github.com/validatorjs/validator.js",
7
+ "files": [
8
+ "index.js",
9
+ "es",
10
+ "lib",
11
+ "README.md",
12
+ "LICENSE",
13
+ "validator.js",
14
+ "validator.min.js"
15
+ ],
16
+ "keywords": [
17
+ "validator",
18
+ "validation",
19
+ "validate",
20
+ "sanitization",
21
+ "sanitize",
22
+ "sanitisation",
23
+ "sanitise",
24
+ "assert"
25
+ ],
26
+ "author": "Chris O'Hara <cohara87@gmail.com>",
27
+ "contributors": [
28
+ {
29
+ "name": "Anthony Nandaa",
30
+ "url": "https://github.com/profnandaa"
31
+ }
32
+ ],
33
+ "main": "index.js",
34
+ "bugs": {
35
+ "url": "https://github.com/validatorjs/validator.js/issues"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/validatorjs/validator.js.git"
40
+ },
41
+ "devDependencies": {
42
+ "@babel/cli": "^7.0.0",
43
+ "@babel/core": "^7.0.0",
44
+ "@babel/preset-env": "^7.0.0",
45
+ "@babel/register": "^7.0.0",
46
+ "babel-eslint": "^10.0.1",
47
+ "babel-plugin-add-module-exports": "^1.0.0",
48
+ "eslint": "^4.19.1",
49
+ "eslint-config-airbnb-base": "^12.1.0",
50
+ "eslint-plugin-import": "^2.11.0",
51
+ "mocha": "^6.2.3",
52
+ "npm-run-all": "^4.1.5",
53
+ "nyc": "^14.1.0",
54
+ "rimraf": "^3.0.0",
55
+ "rollup": "^0.47.0",
56
+ "rollup-plugin-babel": "^4.0.1",
57
+ "timezone-mock": "^1.3.6",
58
+ "uglify-js": "^3.0.19"
59
+ },
60
+ "scripts": {
61
+ "lint": "eslint src test",
62
+ "lint:fix": "eslint --fix src test",
63
+ "clean:node": "rimraf index.js lib",
64
+ "clean:es": "rimraf es",
65
+ "clean:browser": "rimraf validator*.js",
66
+ "clean": "run-p clean:*",
67
+ "minify": "uglifyjs validator.js -o validator.min.js --compress --mangle --comments /Copyright/",
68
+ "build:browser": "node --require @babel/register build-browser && npm run minify",
69
+ "build:es": "babel src -d es --env-name=es",
70
+ "build:node": "babel src -d .",
71
+ "build": "run-p build:*",
72
+ "pretest": "npm run build && npm run lint",
73
+ "postinstall": "node index.js",
74
+ "test": "nyc --reporter=cobertura --reporter=text-summary mocha --require @babel/register --reporter dot --recursive"
75
+ },
76
+ "engines": {
77
+ "node": ">= 0.10"
78
+ },
79
+ "license": "MIT",
80
+ "directories": {
81
+ "lib": "lib"
82
+ }
83
+ }