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
@@ -0,0 +1,406 @@
1
+ import assertString from './util/assertString';
2
+ import isInt from './isInt';
3
+ var validators = {
4
+ PL: function PL(str) {
5
+ assertString(str);
6
+ var weightOfDigits = {
7
+ 1: 1,
8
+ 2: 3,
9
+ 3: 7,
10
+ 4: 9,
11
+ 5: 1,
12
+ 6: 3,
13
+ 7: 7,
14
+ 8: 9,
15
+ 9: 1,
16
+ 10: 3,
17
+ 11: 0
18
+ };
19
+ if (str != null && str.length === 11 && isInt(str, {
20
+ allow_leading_zeroes: true
21
+ })) {
22
+ var digits = str.split('').slice(0, -1);
23
+ var sum = digits.reduce(function (acc, digit, index) {
24
+ return acc + Number(digit) * weightOfDigits[index + 1];
25
+ }, 0);
26
+ var modulo = sum % 10;
27
+ var lastDigit = Number(str.charAt(str.length - 1));
28
+ if (modulo === 0 && lastDigit === 0 || lastDigit === 10 - modulo) {
29
+ return true;
30
+ }
31
+ }
32
+ return false;
33
+ },
34
+ ES: function ES(str) {
35
+ assertString(str);
36
+ var DNI = /^[0-9X-Z][0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKE]$/;
37
+ var charsValue = {
38
+ X: 0,
39
+ Y: 1,
40
+ Z: 2
41
+ };
42
+ 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'];
43
+
44
+ // sanitize user input
45
+ var sanitized = str.trim().toUpperCase();
46
+
47
+ // validate the data structure
48
+ if (!DNI.test(sanitized)) {
49
+ return false;
50
+ }
51
+
52
+ // validate the control digit
53
+ var number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, function (_char) {
54
+ return charsValue[_char];
55
+ });
56
+ return sanitized.endsWith(controlDigits[number % 23]);
57
+ },
58
+ FI: function FI(str) {
59
+ // https://dvv.fi/en/personal-identity-code#:~:text=control%20character%20for%20a-,personal,-identity%20code%20calculated
60
+ assertString(str);
61
+ if (str.length !== 11) {
62
+ return false;
63
+ }
64
+ if (!str.match(/^\d{6}[\-A\+]\d{3}[0-9ABCDEFHJKLMNPRSTUVWXY]{1}$/)) {
65
+ return false;
66
+ }
67
+ var checkDigits = '0123456789ABCDEFHJKLMNPRSTUVWXY';
68
+ var idAsNumber = parseInt(str.slice(0, 6), 10) * 1000 + parseInt(str.slice(7, 10), 10);
69
+ var remainder = idAsNumber % 31;
70
+ var checkDigit = checkDigits[remainder];
71
+ return checkDigit === str.slice(10, 11);
72
+ },
73
+ IN: function IN(str) {
74
+ var DNI = /^[1-9]\d{3}\s?\d{4}\s?\d{4}$/;
75
+
76
+ // multiplication table
77
+ 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]];
78
+
79
+ // permutation table
80
+ 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]];
81
+
82
+ // sanitize user input
83
+ var sanitized = str.trim();
84
+
85
+ // validate the data structure
86
+ if (!DNI.test(sanitized)) {
87
+ return false;
88
+ }
89
+ var c = 0;
90
+ var invertedArray = sanitized.replace(/\s/g, '').split('').map(Number).reverse();
91
+ invertedArray.forEach(function (val, i) {
92
+ c = d[c][p[i % 8][val]];
93
+ });
94
+ return c === 0;
95
+ },
96
+ IR: function IR(str) {
97
+ if (!str.match(/^\d{10}$/)) return false;
98
+ str = "0000".concat(str).slice(str.length - 6);
99
+ if (parseInt(str.slice(3, 9), 10) === 0) return false;
100
+ var lastNumber = parseInt(str.slice(9, 10), 10);
101
+ var sum = 0;
102
+ for (var i = 0; i < 9; i++) {
103
+ sum += parseInt(str.slice(i, i + 1), 10) * (10 - i);
104
+ }
105
+ sum %= 11;
106
+ return sum < 2 && lastNumber === sum || sum >= 2 && lastNumber === 11 - sum;
107
+ },
108
+ IT: function IT(str) {
109
+ if (str.length !== 9) return false;
110
+ if (str === 'CA00000AA') return false; // https://it.wikipedia.org/wiki/Carta_d%27identit%C3%A0_elettronica_italiana
111
+ return str.search(/C[A-Z]\d{5}[A-Z]{2}/i) > -1;
112
+ },
113
+ NO: function NO(str) {
114
+ var sanitized = str.trim();
115
+ if (isNaN(Number(sanitized))) return false;
116
+ if (sanitized.length !== 11) return false;
117
+ if (sanitized === '00000000000') return false;
118
+
119
+ // https://no.wikipedia.org/wiki/F%C3%B8dselsnummer
120
+ var f = sanitized.split('').map(Number);
121
+ 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;
122
+ 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;
123
+ if (k1 !== f[9] || k2 !== f[10]) return false;
124
+ return true;
125
+ },
126
+ TH: function TH(str) {
127
+ if (!str.match(/^[1-8]\d{12}$/)) return false;
128
+
129
+ // validate check digit
130
+ var sum = 0;
131
+ for (var i = 0; i < 12; i++) {
132
+ sum += parseInt(str[i], 10) * (13 - i);
133
+ }
134
+ return str[12] === ((11 - sum % 11) % 10).toString();
135
+ },
136
+ LK: function LK(str) {
137
+ var old_nic = /^[1-9]\d{8}[vx]$/i;
138
+ var new_nic = /^[1-9]\d{11}$/i;
139
+ if (str.length === 10 && old_nic.test(str)) return true;else if (str.length === 12 && new_nic.test(str)) return true;
140
+ return false;
141
+ },
142
+ 'he-IL': function heIL(str) {
143
+ var DNI = /^\d{9}$/;
144
+
145
+ // sanitize user input
146
+ var sanitized = str.trim();
147
+
148
+ // validate the data structure
149
+ if (!DNI.test(sanitized)) {
150
+ return false;
151
+ }
152
+ var id = sanitized;
153
+ var sum = 0,
154
+ incNum;
155
+ for (var i = 0; i < id.length; i++) {
156
+ incNum = Number(id[i]) * (i % 2 + 1); // Multiply number by 1 or 2
157
+ sum += incNum > 9 ? incNum - 9 : incNum; // Sum the digits up and add to total
158
+ }
159
+ return sum % 10 === 0;
160
+ },
161
+ 'ar-LY': function arLY(str) {
162
+ // Libya National Identity Number NIN is 12 digits, the first digit is either 1 or 2
163
+ var NIN = /^(1|2)\d{11}$/;
164
+
165
+ // sanitize user input
166
+ var sanitized = str.trim();
167
+
168
+ // validate the data structure
169
+ if (!NIN.test(sanitized)) {
170
+ return false;
171
+ }
172
+ return true;
173
+ },
174
+ 'ar-TN': function arTN(str) {
175
+ var DNI = /^\d{8}$/;
176
+
177
+ // sanitize user input
178
+ var sanitized = str.trim();
179
+
180
+ // validate the data structure
181
+ if (!DNI.test(sanitized)) {
182
+ return false;
183
+ }
184
+ return true;
185
+ },
186
+ 'zh-CN': function zhCN(str) {
187
+ var provincesAndCities = ['11',
188
+ // 北京
189
+ '12',
190
+ // 天津
191
+ '13',
192
+ // 河北
193
+ '14',
194
+ // 山西
195
+ '15',
196
+ // 内蒙古
197
+ '21',
198
+ // 辽宁
199
+ '22',
200
+ // 吉林
201
+ '23',
202
+ // 黑龙江
203
+ '31',
204
+ // 上海
205
+ '32',
206
+ // 江苏
207
+ '33',
208
+ // 浙江
209
+ '34',
210
+ // 安徽
211
+ '35',
212
+ // 福建
213
+ '36',
214
+ // 江西
215
+ '37',
216
+ // 山东
217
+ '41',
218
+ // 河南
219
+ '42',
220
+ // 湖北
221
+ '43',
222
+ // 湖南
223
+ '44',
224
+ // 广东
225
+ '45',
226
+ // 广西
227
+ '46',
228
+ // 海南
229
+ '50',
230
+ // 重庆
231
+ '51',
232
+ // 四川
233
+ '52',
234
+ // 贵州
235
+ '53',
236
+ // 云南
237
+ '54',
238
+ // 西藏
239
+ '61',
240
+ // 陕西
241
+ '62',
242
+ // 甘肃
243
+ '63',
244
+ // 青海
245
+ '64',
246
+ // 宁夏
247
+ '65',
248
+ // 新疆
249
+ '71',
250
+ // 台湾
251
+ '81',
252
+ // 香港
253
+ '82',
254
+ // 澳门
255
+ '91' // 国外
256
+ ];
257
+ var powers = ['7', '9', '10', '5', '8', '4', '2', '1', '6', '3', '7', '9', '10', '5', '8', '4', '2'];
258
+ var parityBit = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
259
+ var checkAddressCode = function checkAddressCode(addressCode) {
260
+ return provincesAndCities.includes(addressCode);
261
+ };
262
+ var checkBirthDayCode = function checkBirthDayCode(birDayCode) {
263
+ var yyyy = parseInt(birDayCode.substring(0, 4), 10);
264
+ var mm = parseInt(birDayCode.substring(4, 6), 10);
265
+ var dd = parseInt(birDayCode.substring(6), 10);
266
+ var xdata = new Date(yyyy, mm - 1, dd);
267
+ if (xdata > new Date()) {
268
+ return false;
269
+ // eslint-disable-next-line max-len
270
+ } else if (xdata.getFullYear() === yyyy && xdata.getMonth() === mm - 1 && xdata.getDate() === dd) {
271
+ return true;
272
+ }
273
+ return false;
274
+ };
275
+ var getParityBit = function getParityBit(idCardNo) {
276
+ var id17 = idCardNo.substring(0, 17);
277
+ var power = 0;
278
+ for (var i = 0; i < 17; i++) {
279
+ power += parseInt(id17.charAt(i), 10) * parseInt(powers[i], 10);
280
+ }
281
+ var mod = power % 11;
282
+ return parityBit[mod];
283
+ };
284
+ var checkParityBit = function checkParityBit(idCardNo) {
285
+ return getParityBit(idCardNo) === idCardNo.charAt(17).toUpperCase();
286
+ };
287
+ var check15IdCardNo = function check15IdCardNo(idCardNo) {
288
+ 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);
289
+ if (!check) return false;
290
+ var addressCode = idCardNo.substring(0, 2);
291
+ check = checkAddressCode(addressCode);
292
+ if (!check) return false;
293
+ var birDayCode = "19".concat(idCardNo.substring(6, 12));
294
+ check = checkBirthDayCode(birDayCode);
295
+ if (!check) return false;
296
+ return true;
297
+ };
298
+ var check18IdCardNo = function check18IdCardNo(idCardNo) {
299
+ 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);
300
+ if (!check) return false;
301
+ var addressCode = idCardNo.substring(0, 2);
302
+ check = checkAddressCode(addressCode);
303
+ if (!check) return false;
304
+ var birDayCode = idCardNo.substring(6, 14);
305
+ check = checkBirthDayCode(birDayCode);
306
+ if (!check) return false;
307
+ return checkParityBit(idCardNo);
308
+ };
309
+ var checkIdCardNo = function checkIdCardNo(idCardNo) {
310
+ var check = /^\d{15}|(\d{17}(\d|x|X))$/.test(idCardNo);
311
+ if (!check) return false;
312
+ if (idCardNo.length === 15) {
313
+ return check15IdCardNo(idCardNo);
314
+ }
315
+ return check18IdCardNo(idCardNo);
316
+ };
317
+ return checkIdCardNo(str);
318
+ },
319
+ 'zh-HK': function zhHK(str) {
320
+ // sanitize user input
321
+ str = str.trim();
322
+
323
+ // HKID number starts with 1 or 2 letters, followed by 6 digits,
324
+ // then a checksum contained in square / round brackets or nothing
325
+ var regexHKID = /^[A-Z]{1,2}[0-9]{6}((\([0-9A]\))|(\[[0-9A]\])|([0-9A]))$/;
326
+ var regexIsDigit = /^[0-9]$/;
327
+
328
+ // convert the user input to all uppercase and apply regex
329
+ str = str.toUpperCase();
330
+ if (!regexHKID.test(str)) return false;
331
+ str = str.replace(/\[|\]|\(|\)/g, '');
332
+ if (str.length === 8) str = "3".concat(str);
333
+ var checkSumVal = 0;
334
+ for (var i = 0; i <= 7; i++) {
335
+ var convertedChar = void 0;
336
+ if (!regexIsDigit.test(str[i])) convertedChar = (str[i].charCodeAt(0) - 55) % 11;else convertedChar = str[i];
337
+ checkSumVal += convertedChar * (9 - i);
338
+ }
339
+ checkSumVal %= 11;
340
+ var checkSumConverted;
341
+ if (checkSumVal === 0) checkSumConverted = '0';else if (checkSumVal === 1) checkSumConverted = 'A';else checkSumConverted = String(11 - checkSumVal);
342
+ if (checkSumConverted === str[str.length - 1]) return true;
343
+ return false;
344
+ },
345
+ 'zh-TW': function zhTW(str) {
346
+ var ALPHABET_CODES = {
347
+ A: 10,
348
+ B: 11,
349
+ C: 12,
350
+ D: 13,
351
+ E: 14,
352
+ F: 15,
353
+ G: 16,
354
+ H: 17,
355
+ I: 34,
356
+ J: 18,
357
+ K: 19,
358
+ L: 20,
359
+ M: 21,
360
+ N: 22,
361
+ O: 35,
362
+ P: 23,
363
+ Q: 24,
364
+ R: 25,
365
+ S: 26,
366
+ T: 27,
367
+ U: 28,
368
+ V: 29,
369
+ W: 32,
370
+ X: 30,
371
+ Y: 31,
372
+ Z: 33
373
+ };
374
+ var sanitized = str.trim().toUpperCase();
375
+ if (!/^[A-Z][0-9]{9}$/.test(sanitized)) return false;
376
+ return Array.from(sanitized).reduce(function (sum, number, index) {
377
+ if (index === 0) {
378
+ var code = ALPHABET_CODES[number];
379
+ return code % 10 * 9 + Math.floor(code / 10);
380
+ }
381
+ if (index === 9) {
382
+ return (10 - sum % 10 - Number(number)) % 10 === 0;
383
+ }
384
+ return sum + Number(number) * (9 - index);
385
+ }, 0);
386
+ }
387
+ };
388
+ export default function isIdentityCard(str, locale) {
389
+ assertString(str);
390
+ if (locale in validators) {
391
+ return validators[locale](str);
392
+ } else if (locale === 'any') {
393
+ for (var key in validators) {
394
+ // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
395
+ // istanbul ignore else
396
+ if (validators.hasOwnProperty(key)) {
397
+ var validator = validators[key];
398
+ if (validator(str)) {
399
+ return true;
400
+ }
401
+ }
402
+ }
403
+ return false;
404
+ }
405
+ throw new Error("Invalid locale '".concat(locale, "'"));
406
+ }
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,18 @@
1
+ import assertString from './util/assertString';
2
+ var _int = /^(?:[-+]?(?:0|[1-9][0-9]*))$/;
3
+ var intLeadingZeroes = /^[-+]?[0-9]+$/;
4
+ export default function isInt(str, options) {
5
+ assertString(str);
6
+ options = options || {};
7
+
8
+ // Get the regex to use for testing, based on whether
9
+ // leading zeroes are allowed or not.
10
+ var regex = options.allow_leading_zeroes === false ? _int : intLeadingZeroes;
11
+
12
+ // Check min/max/lt/gt
13
+ var minCheckPassed = !options.hasOwnProperty('min') || str >= options.min;
14
+ var maxCheckPassed = !options.hasOwnProperty('max') || str <= options.max;
15
+ var ltCheckPassed = !options.hasOwnProperty('lt') || str < options.lt;
16
+ var gtCheckPassed = !options.hasOwnProperty('gt') || str > options.gt;
17
+ return regex.test(str) && minCheckPassed && maxCheckPassed && ltCheckPassed && gtCheckPassed;
18
+ }
@@ -0,0 +1,19 @@
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 merge from './util/merge';
4
+ var default_json_options = {
5
+ allow_primitives: false
6
+ };
7
+ export default function isJSON(str, options) {
8
+ assertString(str);
9
+ try {
10
+ options = merge(options, default_json_options);
11
+ var primitives = [];
12
+ if (options.allow_primitives) {
13
+ primitives = [null, false, true];
14
+ }
15
+ var obj = JSON.parse(str);
16
+ return primitives.includes(obj) || !!obj && _typeof(obj) === 'object';
17
+ } catch (e) {/* ignore */}
18
+ return false;
19
+ }
@@ -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,20 @@
1
+ import assertString from './util/assertString';
2
+ import merge from './util/merge';
3
+ var lat = /^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/;
4
+ var _long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/;
5
+ var latDMS = /^(([1-8]?\d)\D+([1-5]?\d|60)\D+([1-5]?\d|60)(\.\d+)?|90\D+0\D+0)\D+[NSns]?$/i;
6
+ 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;
7
+ var defaultLatLongOptions = {
8
+ checkDMS: false
9
+ };
10
+ export default function isLatLong(str, options) {
11
+ assertString(str);
12
+ options = merge(options, defaultLatLongOptions);
13
+ if (!str.includes(',')) return false;
14
+ var pair = str.split(',');
15
+ if (pair[0].startsWith('(') && !pair[1].endsWith(')') || pair[1].endsWith(')') && !pair[0].startsWith('(')) return false;
16
+ if (options.checkDMS) {
17
+ return latDMS.test(pair[0]) && longDMS.test(pair[1]);
18
+ }
19
+ return lat.test(pair[0]) && _long.test(pair[1]);
20
+ }
@@ -0,0 +1,21 @@
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)/g) || [];
18
+ var surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || [];
19
+ var len = str.length - presentationSequences.length - surrogatePairs.length;
20
+ return len >= min && (typeof max === 'undefined' || len <= max);
21
+ }
@@ -0,0 +1,55 @@
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|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|SLZ|SMÜ|SOB|SOG|SOK|SÖM|SON|SPB|SPN|SRB|SRO|STA|STB|STD|STE|STL|SUL|SÜW|SWA|SZB|TBB|TDO|TET|TIR|TÖL|TUT|UEM|UER|UFF|USI|VAI|VEC|VER|VIB|VIE|VIT|VOH|WAF|WAK|WAN|WAR|WAT|WBS|WDA|WEL|WEN|WER|WES|WHV|WIL|WIS|WIT|WIZ|WLG|WMS|WND|WOB|WOH|WOL|WOR|WOS|WRN|WSF|WST|WSW|WTL|WTM|WUG|WÜM|WUN|WUR|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
+ 'es-AR': function esAR(str) {
16
+ return /^(([A-Z]{2} ?[0-9]{3} ?[A-Z]{2})|([A-Z]{3} ?[0-9]{3}))$/.test(str);
17
+ },
18
+ 'fi-FI': function fiFI(str) {
19
+ return /^(?=.{4,7})(([A-Z]{1,3}|[0-9]{1,3})[\s-]?([A-Z]{1,3}|[0-9]{1,5}))$/.test(str);
20
+ },
21
+ 'hu-HU': function huHU(str) {
22
+ 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);
23
+ },
24
+ 'pt-BR': function ptBR(str) {
25
+ return /^[A-Z]{3}[ -]?[0-9][A-Z][0-9]{2}|[A-Z]{3}[ -]?[0-9]{4}$/.test(str);
26
+ },
27
+ 'pt-PT': function ptPT(str) {
28
+ return /^([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})[ -·]?([A-Z]{2}|[0-9]{2})$/.test(str);
29
+ },
30
+ 'sq-AL': function sqAL(str) {
31
+ return /^[A-Z]{2}[- ]?((\d{3}[- ]?(([A-Z]{2})|T))|(R[- ]?\d{3}))$/.test(str);
32
+ },
33
+ 'sv-SE': function svSE(str) {
34
+ return /^[A-HJ-PR-UW-Z]{3} ?[\d]{2}[A-HJ-PR-UW-Z1-9]$|(^[A-ZÅÄÖ ]{2,7}$)/.test(str.trim());
35
+ },
36
+ 'en-PK': function enPK(str) {
37
+ 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());
38
+ }
39
+ };
40
+ export default function isLicensePlate(str, locale) {
41
+ assertString(str);
42
+ if (locale in validators) {
43
+ return validators[locale](str);
44
+ } else if (locale === 'any') {
45
+ for (var key in validators) {
46
+ /* eslint guard-for-in: 0 */
47
+ var validator = validators[key];
48
+ if (validator(str)) {
49
+ return true;
50
+ }
51
+ }
52
+ return false;
53
+ }
54
+ throw new Error("Invalid locale '".concat(locale, "'"));
55
+ }