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
@@ -0,0 +1,407 @@
1
+ import assertString from './util/assertString';
2
+ import includes from './util/includesArray';
3
+ import isInt from './isInt';
4
+ var validators = {
5
+ PL: function PL(str) {
6
+ assertString(str);
7
+ var weightOfDigits = {
8
+ 1: 1,
9
+ 2: 3,
10
+ 3: 7,
11
+ 4: 9,
12
+ 5: 1,
13
+ 6: 3,
14
+ 7: 7,
15
+ 8: 9,
16
+ 9: 1,
17
+ 10: 3,
18
+ 11: 0
19
+ };
20
+ if (str != null && str.length === 11 && isInt(str, {
21
+ allow_leading_zeroes: true
22
+ })) {
23
+ var digits = str.split('').slice(0, -1);
24
+ var sum = digits.reduce(function (acc, digit, index) {
25
+ return acc + Number(digit) * weightOfDigits[index + 1];
26
+ }, 0);
27
+ var modulo = sum % 10;
28
+ var lastDigit = Number(str.charAt(str.length - 1));
29
+ if (modulo === 0 && lastDigit === 0 || lastDigit === 10 - modulo) {
30
+ return true;
31
+ }
32
+ }
33
+ return false;
34
+ },
35
+ ES: function ES(str) {
36
+ assertString(str);
37
+ var DNI = /^[0-9X-Z][0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKE]$/;
38
+ var charsValue = {
39
+ X: 0,
40
+ Y: 1,
41
+ Z: 2
42
+ };
43
+ var controlDigits = ['T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', 'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', 'Q', 'V', 'H', 'L', 'C', 'K', 'E'];
44
+
45
+ // sanitize user input
46
+ var sanitized = str.trim().toUpperCase();
47
+
48
+ // validate the data structure
49
+ if (!DNI.test(sanitized)) {
50
+ return false;
51
+ }
52
+
53
+ // validate the control digit
54
+ var number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, function (_char) {
55
+ return charsValue[_char];
56
+ });
57
+ return sanitized.endsWith(controlDigits[number % 23]);
58
+ },
59
+ FI: function FI(str) {
60
+ // https://dvv.fi/en/personal-identity-code#:~:text=control%20character%20for%20a-,personal,-identity%20code%20calculated
61
+ assertString(str);
62
+ if (str.length !== 11) {
63
+ return false;
64
+ }
65
+ if (!str.match(/^\d{6}[\-A\+]\d{3}[0-9ABCDEFHJKLMNPRSTUVWXY]{1}$/)) {
66
+ return false;
67
+ }
68
+ var checkDigits = '0123456789ABCDEFHJKLMNPRSTUVWXY';
69
+ var idAsNumber = parseInt(str.slice(0, 6), 10) * 1000 + parseInt(str.slice(7, 10), 10);
70
+ var remainder = idAsNumber % 31;
71
+ var checkDigit = checkDigits[remainder];
72
+ return checkDigit === str.slice(10, 11);
73
+ },
74
+ IN: function IN(str) {
75
+ var DNI = /^[1-9]\d{3}\s?\d{4}\s?\d{4}$/;
76
+
77
+ // multiplication table
78
+ var d = [[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
+
80
+ // permutation table
81
+ var p = [[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]];
82
+
83
+ // sanitize user input
84
+ var sanitized = str.trim();
85
+
86
+ // validate the data structure
87
+ if (!DNI.test(sanitized)) {
88
+ return false;
89
+ }
90
+ var c = 0;
91
+ var invertedArray = sanitized.replace(/\s/g, '').split('').map(Number).reverse();
92
+ invertedArray.forEach(function (val, i) {
93
+ c = d[c][p[i % 8][val]];
94
+ });
95
+ return c === 0;
96
+ },
97
+ IR: function IR(str) {
98
+ if (!str.match(/^\d{10}$/)) return false;
99
+ str = "0000".concat(str).slice(str.length - 6);
100
+ if (parseInt(str.slice(3, 9), 10) === 0) return false;
101
+ var lastNumber = parseInt(str.slice(9, 10), 10);
102
+ var sum = 0;
103
+ for (var i = 0; i < 9; i++) {
104
+ sum += parseInt(str.slice(i, i + 1), 10) * (10 - i);
105
+ }
106
+ sum %= 11;
107
+ return sum < 2 && lastNumber === sum || sum >= 2 && lastNumber === 11 - sum;
108
+ },
109
+ IT: function IT(str) {
110
+ if (str.length !== 9) return false;
111
+ if (str === 'CA00000AA') return false; // https://it.wikipedia.org/wiki/Carta_d%27identit%C3%A0_elettronica_italiana
112
+ return str.search(/C[A-Z]\d{5}[A-Z]{2}/i) > -1;
113
+ },
114
+ NO: function NO(str) {
115
+ var sanitized = str.trim();
116
+ if (isNaN(Number(sanitized))) return false;
117
+ if (sanitized.length !== 11) return false;
118
+ if (sanitized === '00000000000') return false;
119
+
120
+ // https://no.wikipedia.org/wiki/F%C3%B8dselsnummer
121
+ var f = sanitized.split('').map(Number);
122
+ var k1 = (11 - (3 * f[0] + 7 * f[1] + 6 * f[2] + 1 * f[3] + 8 * f[4] + 9 * f[5] + 4 * f[6] + 5 * f[7] + 2 * f[8]) % 11) % 11;
123
+ var k2 = (11 - (5 * f[0] + 4 * f[1] + 3 * f[2] + 2 * f[3] + 7 * f[4] + 6 * f[5] + 5 * f[6] + 4 * f[7] + 3 * f[8] + 2 * k1) % 11) % 11;
124
+ if (k1 !== f[9] || k2 !== f[10]) return false;
125
+ return true;
126
+ },
127
+ TH: function TH(str) {
128
+ if (!str.match(/^[1-8]\d{12}$/)) return false;
129
+
130
+ // validate check digit
131
+ var sum = 0;
132
+ for (var i = 0; i < 12; i++) {
133
+ sum += parseInt(str[i], 10) * (13 - i);
134
+ }
135
+ return str[12] === ((11 - sum % 11) % 10).toString();
136
+ },
137
+ LK: function LK(str) {
138
+ var old_nic = /^[1-9]\d{8}[vx]$/i;
139
+ var new_nic = /^[1-9]\d{11}$/i;
140
+ if (str.length === 10 && old_nic.test(str)) return true;else if (str.length === 12 && new_nic.test(str)) return true;
141
+ return false;
142
+ },
143
+ 'he-IL': function heIL(str) {
144
+ var DNI = /^\d{9}$/;
145
+
146
+ // sanitize user input
147
+ var sanitized = str.trim();
148
+
149
+ // validate the data structure
150
+ if (!DNI.test(sanitized)) {
151
+ return false;
152
+ }
153
+ var id = sanitized;
154
+ var sum = 0,
155
+ incNum;
156
+ for (var i = 0; i < id.length; i++) {
157
+ incNum = Number(id[i]) * (i % 2 + 1); // Multiply number by 1 or 2
158
+ sum += incNum > 9 ? incNum - 9 : incNum; // Sum the digits up and add to total
159
+ }
160
+ return sum % 10 === 0;
161
+ },
162
+ 'ar-LY': function arLY(str) {
163
+ // Libya National Identity Number NIN is 12 digits, the first digit is either 1 or 2
164
+ var NIN = /^(1|2)\d{11}$/;
165
+
166
+ // sanitize user input
167
+ var sanitized = str.trim();
168
+ return NIN.test(sanitized);
169
+ },
170
+ 'ar-TN': function arTN(str) {
171
+ var DNI = /^\d{8}$/;
172
+
173
+ // sanitize user input
174
+ var sanitized = str.trim();
175
+ return DNI.test(sanitized);
176
+ },
177
+ 'zh-CN': function zhCN(str) {
178
+ var provincesAndCities = ['11',
179
+ // 北京
180
+ '12',
181
+ // 天津
182
+ '13',
183
+ // 河北
184
+ '14',
185
+ // 山西
186
+ '15',
187
+ // 内蒙古
188
+ '21',
189
+ // 辽宁
190
+ '22',
191
+ // 吉林
192
+ '23',
193
+ // 黑龙江
194
+ '31',
195
+ // 上海
196
+ '32',
197
+ // 江苏
198
+ '33',
199
+ // 浙江
200
+ '34',
201
+ // 安徽
202
+ '35',
203
+ // 福建
204
+ '36',
205
+ // 江西
206
+ '37',
207
+ // 山东
208
+ '41',
209
+ // 河南
210
+ '42',
211
+ // 湖北
212
+ '43',
213
+ // 湖南
214
+ '44',
215
+ // 广东
216
+ '45',
217
+ // 广西
218
+ '46',
219
+ // 海南
220
+ '50',
221
+ // 重庆
222
+ '51',
223
+ // 四川
224
+ '52',
225
+ // 贵州
226
+ '53',
227
+ // 云南
228
+ '54',
229
+ // 西藏
230
+ '61',
231
+ // 陕西
232
+ '62',
233
+ // 甘肃
234
+ '63',
235
+ // 青海
236
+ '64',
237
+ // 宁夏
238
+ '65',
239
+ // 新疆
240
+ '71',
241
+ // 台湾
242
+ '81',
243
+ // 香港
244
+ '82',
245
+ // 澳门
246
+ '91' // 国外
247
+ ];
248
+ var powers = ['7', '9', '10', '5', '8', '4', '2', '1', '6', '3', '7', '9', '10', '5', '8', '4', '2'];
249
+ var parityBit = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
250
+ var checkAddressCode = function checkAddressCode(addressCode) {
251
+ return includes(provincesAndCities, addressCode);
252
+ };
253
+ var checkBirthDayCode = function checkBirthDayCode(birDayCode) {
254
+ var yyyy = parseInt(birDayCode.substring(0, 4), 10);
255
+ var mm = parseInt(birDayCode.substring(4, 6), 10);
256
+ var dd = parseInt(birDayCode.substring(6), 10);
257
+ var xdata = new Date(yyyy, mm - 1, dd);
258
+ if (xdata > new Date()) {
259
+ return false;
260
+ // eslint-disable-next-line max-len
261
+ } else if (xdata.getFullYear() === yyyy && xdata.getMonth() === mm - 1 && xdata.getDate() === dd) {
262
+ return true;
263
+ }
264
+ return false;
265
+ };
266
+ var getParityBit = function getParityBit(idCardNo) {
267
+ var id17 = idCardNo.substring(0, 17);
268
+ var power = 0;
269
+ for (var i = 0; i < 17; i++) {
270
+ power += parseInt(id17.charAt(i), 10) * parseInt(powers[i], 10);
271
+ }
272
+ var mod = power % 11;
273
+ return parityBit[mod];
274
+ };
275
+ var checkParityBit = function checkParityBit(idCardNo) {
276
+ return getParityBit(idCardNo) === idCardNo.charAt(17).toUpperCase();
277
+ };
278
+ var check15IdCardNo = function check15IdCardNo(idCardNo) {
279
+ var check = /^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(idCardNo);
280
+ if (!check) return false;
281
+ var addressCode = idCardNo.substring(0, 2);
282
+ check = checkAddressCode(addressCode);
283
+ if (!check) return false;
284
+ var birDayCode = "19".concat(idCardNo.substring(6, 12));
285
+ check = checkBirthDayCode(birDayCode);
286
+ if (!check) return false;
287
+ return true;
288
+ };
289
+ var check18IdCardNo = function check18IdCardNo(idCardNo) {
290
+ var check = /^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(idCardNo);
291
+ if (!check) return false;
292
+ var addressCode = idCardNo.substring(0, 2);
293
+ check = checkAddressCode(addressCode);
294
+ if (!check) return false;
295
+ var birDayCode = idCardNo.substring(6, 14);
296
+ check = checkBirthDayCode(birDayCode);
297
+ if (!check) return false;
298
+ return checkParityBit(idCardNo);
299
+ };
300
+ var checkIdCardNo = function checkIdCardNo(idCardNo) {
301
+ var check = /^\d{15}|(\d{17}(\d|x|X))$/.test(idCardNo);
302
+ if (!check) return false;
303
+ if (idCardNo.length === 15) {
304
+ return check15IdCardNo(idCardNo);
305
+ }
306
+ return check18IdCardNo(idCardNo);
307
+ };
308
+ return checkIdCardNo(str);
309
+ },
310
+ 'zh-HK': function zhHK(str) {
311
+ // sanitize user input
312
+ str = str.trim();
313
+
314
+ // HKID number starts with 1 or 2 letters, followed by 6 digits,
315
+ // then a checksum contained in square / round brackets or nothing
316
+ var regexHKID = /^[A-Z]{1,2}[0-9]{6}((\([0-9A]\))|(\[[0-9A]\])|([0-9A]))$/;
317
+ var regexIsDigit = /^[0-9]$/;
318
+
319
+ // convert the user input to all uppercase and apply regex
320
+ str = str.toUpperCase();
321
+ if (!regexHKID.test(str)) return false;
322
+ str = str.replace(/\[|\]|\(|\)/g, '');
323
+ if (str.length === 8) str = "3".concat(str);
324
+ var checkSumVal = 0;
325
+ for (var i = 0; i <= 7; i++) {
326
+ var convertedChar = void 0;
327
+ if (!regexIsDigit.test(str[i])) convertedChar = (str[i].charCodeAt(0) - 55) % 11;else convertedChar = str[i];
328
+ checkSumVal += convertedChar * (9 - i);
329
+ }
330
+ checkSumVal %= 11;
331
+ var checkSumConverted;
332
+ if (checkSumVal === 0) checkSumConverted = '0';else if (checkSumVal === 1) checkSumConverted = 'A';else checkSumConverted = String(11 - checkSumVal);
333
+ if (checkSumConverted === str[str.length - 1]) return true;
334
+ return false;
335
+ },
336
+ 'zh-TW': function zhTW(str) {
337
+ var ALPHABET_CODES = {
338
+ A: 10,
339
+ B: 11,
340
+ C: 12,
341
+ D: 13,
342
+ E: 14,
343
+ F: 15,
344
+ G: 16,
345
+ H: 17,
346
+ I: 34,
347
+ J: 18,
348
+ K: 19,
349
+ L: 20,
350
+ M: 21,
351
+ N: 22,
352
+ O: 35,
353
+ P: 23,
354
+ Q: 24,
355
+ R: 25,
356
+ S: 26,
357
+ T: 27,
358
+ U: 28,
359
+ V: 29,
360
+ W: 32,
361
+ X: 30,
362
+ Y: 31,
363
+ Z: 33
364
+ };
365
+ var sanitized = str.trim().toUpperCase();
366
+ if (!/^[A-Z][0-9]{9}$/.test(sanitized)) return false;
367
+ return Array.from(sanitized).reduce(function (sum, number, index) {
368
+ if (index === 0) {
369
+ var code = ALPHABET_CODES[number];
370
+ return code % 10 * 9 + Math.floor(code / 10);
371
+ }
372
+ if (index === 9) {
373
+ return (10 - sum % 10 - Number(number)) % 10 === 0;
374
+ }
375
+ return sum + Number(number) * (9 - index);
376
+ }, 0);
377
+ },
378
+ PK: function PK(str) {
379
+ // Pakistani National Identity Number CNIC is 13 digits
380
+ var CNIC = /^[1-7][0-9]{4}-[0-9]{7}-[1-9]$/;
381
+
382
+ // sanitize user input
383
+ var sanitized = str.trim();
384
+
385
+ // validate the data structure
386
+ return CNIC.test(sanitized);
387
+ }
388
+ };
389
+ export default function isIdentityCard(str, locale) {
390
+ assertString(str);
391
+ if (locale in validators) {
392
+ return validators[locale](str);
393
+ } else if (locale === 'any') {
394
+ for (var key in validators) {
395
+ // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
396
+ // istanbul ignore else
397
+ if (validators.hasOwnProperty(key)) {
398
+ var validator = validators[key];
399
+ if (validator(str)) {
400
+ return true;
401
+ }
402
+ }
403
+ }
404
+ return false;
405
+ }
406
+ throw new Error("Invalid locale '".concat(locale, "'"));
407
+ }
package/es/lib/isIn.js ADDED
@@ -0,0 +1,23 @@
1
+ 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); }
2
+ import assertString from './util/assertString';
3
+ import toString from './util/toString';
4
+ export default function isIn(str, options) {
5
+ assertString(str);
6
+ var i;
7
+ if (Object.prototype.toString.call(options) === '[object Array]') {
8
+ var array = [];
9
+ for (i in options) {
10
+ // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
11
+ // istanbul ignore else
12
+ if ({}.hasOwnProperty.call(options, i)) {
13
+ array[i] = toString(options[i]);
14
+ }
15
+ }
16
+ return array.indexOf(str) >= 0;
17
+ } else if (_typeof(options) === 'object') {
18
+ return options.hasOwnProperty(str);
19
+ } else if (options && typeof options.indexOf === 'function') {
20
+ return options.indexOf(str) >= 0;
21
+ }
22
+ return false;
23
+ }
@@ -0,0 +1,19 @@
1
+ import assertString from './util/assertString';
2
+ import isNullOrUndefined from './util/nullUndefinedCheck';
3
+ var _int = /^(?:[-+]?(?:0|[1-9][0-9]*))$/;
4
+ var intLeadingZeroes = /^[-+]?[0-9]+$/;
5
+ export default function isInt(str, options) {
6
+ assertString(str);
7
+ options = options || {};
8
+
9
+ // Get the regex to use for testing, based on whether
10
+ // leading zeroes are allowed or not.
11
+ var regex = options.allow_leading_zeroes === false ? _int : intLeadingZeroes;
12
+
13
+ // Check min/max/lt/gt
14
+ var minCheckPassed = !options.hasOwnProperty('min') || isNullOrUndefined(options.min) || str >= options.min;
15
+ var maxCheckPassed = !options.hasOwnProperty('max') || isNullOrUndefined(options.max) || str <= options.max;
16
+ var ltCheckPassed = !options.hasOwnProperty('lt') || isNullOrUndefined(options.lt) || str < options.lt;
17
+ var gtCheckPassed = !options.hasOwnProperty('gt') || isNullOrUndefined(options.gt) || str > options.gt;
18
+ return regex.test(str) && minCheckPassed && maxCheckPassed && ltCheckPassed && gtCheckPassed;
19
+ }
@@ -0,0 +1,26 @@
1
+ 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); }
2
+ import assertString from './util/assertString';
3
+ import includes from './util/includesArray';
4
+ import merge from './util/merge';
5
+ var default_json_options = {
6
+ allow_primitives: false,
7
+ allow_any_value: false
8
+ };
9
+ export default function isJSON(str, options) {
10
+ assertString(str);
11
+ try {
12
+ options = merge(options, default_json_options);
13
+ var obj = JSON.parse(str);
14
+
15
+ // When allow_any_value is true, accept anything that JSON.parse successfully parses
16
+ if (options.allow_any_value) {
17
+ return true;
18
+ }
19
+ var primitives = [];
20
+ if (options.allow_primitives) {
21
+ primitives = [null, false, true];
22
+ }
23
+ return includes(primitives, obj) || !!obj && _typeof(obj) === 'object';
24
+ } catch (e) {/* ignore */}
25
+ return false;
26
+ }
@@ -0,0 +1,15 @@
1
+ import assertString from './util/assertString';
2
+ import isBase64 from './isBase64';
3
+ export default function isJWT(str) {
4
+ assertString(str);
5
+ var dotSplit = str.split('.');
6
+ var len = dotSplit.length;
7
+ if (len !== 3) {
8
+ return false;
9
+ }
10
+ return dotSplit.reduce(function (acc, currElem) {
11
+ return acc && isBase64(currElem, {
12
+ urlSafe: true
13
+ });
14
+ }, true);
15
+ }
@@ -0,0 +1,21 @@
1
+ import assertString from './util/assertString';
2
+ import merge from './util/merge';
3
+ import includes from './util/includesString';
4
+ var lat = /^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/;
5
+ var _long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/;
6
+ var latDMS = /^(([1-8]?\d)\D+([1-5]?\d|60)\D+([1-5]?\d|60)(\.\d+)?|90\D+0\D+0)\D+[NSns]?$/i;
7
+ var longDMS = /^\s*([1-7]?\d{1,2}\D+([1-5]?\d|60)\D+([1-5]?\d|60)(\.\d+)?|180\D+0\D+0)\D+[EWew]?$/i;
8
+ var defaultLatLongOptions = {
9
+ checkDMS: false
10
+ };
11
+ export default function isLatLong(str, options) {
12
+ assertString(str);
13
+ options = merge(options, defaultLatLongOptions);
14
+ if (!includes(str, ',')) return false;
15
+ var pair = str.split(',');
16
+ if (pair[0].startsWith('(') && !pair[1].endsWith(')') || pair[1].endsWith(')') && !pair[0].startsWith('(')) return false;
17
+ if (options.checkDMS) {
18
+ return latDMS.test(pair[0]) && longDMS.test(pair[1]);
19
+ }
20
+ return lat.test(pair[0]) && _long.test(pair[1]);
21
+ }
@@ -0,0 +1,27 @@
1
+ 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); }
2
+ import assertString from './util/assertString';
3
+
4
+ /* eslint-disable prefer-rest-params */
5
+ export default function isLength(str, options) {
6
+ assertString(str);
7
+ var min;
8
+ var max;
9
+ if (_typeof(options) === 'object') {
10
+ min = options.min || 0;
11
+ max = options.max;
12
+ } else {
13
+ // backwards compatibility: isLength(str, min [, max])
14
+ min = arguments[1] || 0;
15
+ max = arguments[2];
16
+ }
17
+ var presentationSequences = str.match(/[^\uFE0F\uFE0E][\uFE0F\uFE0E]/g) || [];
18
+ var surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || [];
19
+ var len = str.length - presentationSequences.length - surrogatePairs.length;
20
+ var isInsideRange = len >= min && (typeof max === 'undefined' || len <= max);
21
+ if (isInsideRange && Array.isArray(options === null || options === void 0 ? void 0 : options.discreteLengths)) {
22
+ return options.discreteLengths.some(function (discreteLen) {
23
+ return discreteLen === len;
24
+ });
25
+ }
26
+ return isInsideRange;
27
+ }
@@ -0,0 +1,58 @@
1
+ import assertString from './util/assertString';
2
+ var validators = {
3
+ 'cs-CZ': function csCZ(str) {
4
+ return /^(([ABCDEFHIJKLMNPRSTUVXYZ]|[0-9])-?){5,8}$/.test(str);
5
+ },
6
+ 'de-DE': function deDE(str) {
7
+ return /^((A|AA|AB|AC|AE|AH|AK|AM|AN|AÖ|AP|AS|AT|AU|AW|AZ|B|BA|BB|BC|BE|BF|BH|BI|BK|BL|BM|BN|BO|BÖ|BS|BT|BZ|C|CA|CB|CE|CO|CR|CW|D|DA|DD|DE|DH|DI|DL|DM|DN|DO|DU|DW|DZ|E|EA|EB|ED|EE|EF|EG|EH|EI|EL|EM|EN|ER|ES|EU|EW|F|FB|FD|FF|FG|FI|FL|FN|FO|FR|FS|FT|FÜ|FW|FZ|G|GA|GC|GD|GE|GF|GG|GI|GK|GL|GM|GN|GÖ|GP|GR|GS|GT|GÜ|GV|GW|GZ|H|HA|HB|HC|HD|HE|HF|HG|HH|HI|HK|HL|HM|HN|HO|HP|HR|HS|HU|HV|HX|HY|HZ|IK|IL|IN|IZ|J|JE|JL|K|KA|KB|KC|KE|KF|KG|KH|KI|KK|KL|KM|KN|KO|KR|KS|KT|KU|KW|KY|L|LA|LB|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|WZL|ZEL|ZIG)[- ]?(([A-Z][- ]?\d{1,4})|([A-Z]{2}[- ]?\d{1,3})))[- ]?(E|H)?$/.test(str);
8
+ },
9
+ 'de-LI': function deLI(str) {
10
+ return /^FL[- ]?\d{1,5}[UZ]?$/.test(str);
11
+ },
12
+ 'en-IN': function enIN(str) {
13
+ return /^[A-Z]{2}[ -]?[0-9]{1,2}(?:[ -]?[A-Z])(?:[ -]?[A-Z]*)?[ -]?[0-9]{4}$/.test(str);
14
+ },
15
+ 'en-SG': function enSG(str) {
16
+ return /^[A-Z]{3}[ -]?[\d]{4}[ -]?[A-Z]{1}$/.test(str);
17
+ },
18
+ 'es-AR': function esAR(str) {
19
+ return /^(([A-Z]{2} ?[0-9]{3} ?[A-Z]{2})|([A-Z]{3} ?[0-9]{3}))$/.test(str);
20
+ },
21
+ 'fi-FI': function fiFI(str) {
22
+ return /^(?=.{4,7})(([A-Z]{1,3}|[0-9]{1,3})[\s-]?([A-Z]{1,3}|[0-9]{1,5}))$/.test(str);
23
+ },
24
+ 'hu-HU': function huHU(str) {
25
+ return /^((((?!AAA)(([A-NPRSTVZWXY]{1})([A-PR-Z]{1})([A-HJ-NPR-Z]))|(A[ABC]I)|A[ABC]O|A[A-W]Q|BPI|BPO|UCO|UDO|XAO)-(?!000)\d{3})|(M\d{6})|((CK|DT|CD|HC|H[ABEFIKLMNPRSTVX]|MA|OT|R[A-Z]) \d{2}-\d{2})|(CD \d{3}-\d{3})|(C-(C|X) \d{4})|(X-(A|B|C) \d{4})|(([EPVZ]-\d{5}))|(S A[A-Z]{2} \d{2})|(SP \d{2}-\d{2}))$/.test(str);
26
+ },
27
+ 'pt-BR': function ptBR(str) {
28
+ return /^[A-Z]{3}[ -]?[0-9][A-Z][0-9]{2}|[A-Z]{3}[ -]?[0-9]{4}$/.test(str);
29
+ },
30
+ 'pt-PT': function ptPT(str) {
31
+ return /^(([A-Z]{2}[ -·]?[0-9]{2}[ -·]?[0-9]{2})|([0-9]{2}[ -·]?[A-Z]{2}[ -·]?[0-9]{2})|([0-9]{2}[ -·]?[0-9]{2}[ -·]?[A-Z]{2})|([A-Z]{2}[ -·]?[0-9]{2}[ -·]?[A-Z]{2}))$/.test(str);
32
+ },
33
+ 'sq-AL': function sqAL(str) {
34
+ return /^[A-Z]{2}[- ]?((\d{3}[- ]?(([A-Z]{2})|T))|(R[- ]?\d{3}))$/.test(str);
35
+ },
36
+ 'sv-SE': function svSE(str) {
37
+ return /^[A-HJ-PR-UW-Z]{3} ?[\d]{2}[A-HJ-PR-UW-Z1-9]$|(^[A-ZÅÄÖ ]{2,7}$)/.test(str.trim());
38
+ },
39
+ 'en-PK': function enPK(str) {
40
+ return /(^[A-Z]{2}((\s|-){0,1})[0-9]{3,4}((\s|-)[0-9]{2}){0,1}$)|(^[A-Z]{3}((\s|-){0,1})[0-9]{3,4}((\s|-)[0-9]{2}){0,1}$)|(^[A-Z]{4}((\s|-){0,1})[0-9]{3,4}((\s|-)[0-9]{2}){0,1}$)|(^[A-Z]((\s|-){0,1})[0-9]{4}((\s|-)[0-9]{2}){0,1}$)/.test(str.trim());
41
+ }
42
+ };
43
+ export default function isLicensePlate(str, locale) {
44
+ assertString(str);
45
+ if (locale in validators) {
46
+ return validators[locale](str);
47
+ } else if (locale === 'any') {
48
+ for (var key in validators) {
49
+ /* eslint guard-for-in: 0 */
50
+ var validator = validators[key];
51
+ if (validator(str)) {
52
+ return true;
53
+ }
54
+ }
55
+ return false;
56
+ }
57
+ throw new Error("Invalid locale '".concat(locale, "'"));
58
+ }