n4s 2.2.0-rc.1 → 4.0.0-dev-e266d9

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 (83) hide show
  1. package/CHANGELOG.md +129 -0
  2. package/LICENSE +1 -2
  3. package/README.md +10 -4
  4. package/compose/package.json +7 -0
  5. package/compounds/package.json +7 -0
  6. package/dist/cjs/compose.development.js +139 -0
  7. package/dist/cjs/compose.js +7 -0
  8. package/dist/cjs/compose.production.js +1 -0
  9. package/dist/cjs/compounds.development.js +132 -0
  10. package/dist/cjs/compounds.js +7 -0
  11. package/dist/cjs/compounds.production.js +1 -0
  12. package/dist/cjs/n4s.development.js +602 -0
  13. package/dist/cjs/n4s.js +7 -0
  14. package/dist/cjs/n4s.production.js +1 -0
  15. package/dist/cjs/package.json +1 -0
  16. package/dist/cjs/schema.development.js +144 -0
  17. package/dist/cjs/schema.js +7 -0
  18. package/dist/cjs/schema.production.js +1 -0
  19. package/dist/es/compose.development.js +137 -0
  20. package/dist/es/compose.production.js +1 -0
  21. package/dist/es/compounds.development.js +130 -0
  22. package/dist/es/compounds.production.js +1 -0
  23. package/dist/es/n4s.development.js +597 -0
  24. package/dist/es/n4s.production.js +1 -0
  25. package/dist/es/package.json +1 -0
  26. package/dist/es/schema.development.js +140 -0
  27. package/dist/es/schema.production.js +1 -0
  28. package/dist/umd/compose.development.js +143 -0
  29. package/dist/umd/compose.production.js +1 -0
  30. package/dist/umd/compounds.development.js +136 -0
  31. package/dist/umd/compounds.production.js +1 -0
  32. package/dist/umd/n4s.development.js +606 -0
  33. package/dist/umd/n4s.production.js +1 -0
  34. package/dist/umd/schema.development.js +148 -0
  35. package/dist/umd/schema.production.js +1 -0
  36. package/docs/README.md +10 -4
  37. package/docs/_sidebar.md +2 -2
  38. package/docs/external.md +27 -0
  39. package/docs/rules.md +74 -0
  40. package/package.json +126 -67
  41. package/schema/package.json +7 -0
  42. package/tsconfig.json +8 -0
  43. package/types/compose.d.ts +134 -0
  44. package/types/compounds.d.ts +146 -0
  45. package/types/n4s.d.ts +167 -0
  46. package/types/schema.d.ts +151 -0
  47. package/config/rollup/enforce.js +0 -13
  48. package/config/rollup/enforceExtended.js +0 -10
  49. package/config/rollup/ensure.js +0 -10
  50. package/config/rollup/rollup.config.js +0 -5
  51. package/docs/business_rules.md +0 -80
  52. package/docs/custom.md +0 -54
  53. package/docs/ensure.md +0 -40
  54. package/enforceExtended.cjs.development.js +0 -1949
  55. package/enforceExtended.cjs.production.js +0 -1949
  56. package/enforceExtended.cjs.production.min.js +0 -1
  57. package/enforceExtended.umd.development.js +0 -1955
  58. package/enforceExtended.umd.production.js +0 -1972
  59. package/enforceExtended.umd.production.min.js +0 -1
  60. package/ensure.cjs.development.js +0 -418
  61. package/ensure.cjs.production.js +0 -418
  62. package/ensure.cjs.production.min.js +0 -1
  63. package/ensure.umd.development.js +0 -424
  64. package/ensure.umd.production.js +0 -444
  65. package/ensure.umd.production.min.js +0 -1
  66. package/esm/enforceExtended.mjs.development.js +0 -1947
  67. package/esm/enforceExtended.mjs.production.js +0 -1947
  68. package/esm/enforceExtended.mjs.production.min.js +0 -1
  69. package/esm/ensure.mjs.development.js +0 -416
  70. package/esm/ensure.mjs.production.js +0 -416
  71. package/esm/ensure.mjs.production.min.js +0 -1
  72. package/esm/n4s.mjs.development.js +0 -394
  73. package/esm/n4s.mjs.production.js +0 -394
  74. package/esm/n4s.mjs.production.min.js +0 -1
  75. package/esm/package.json +0 -1
  76. package/jest.config.js +0 -3
  77. package/n4s.cjs.development.js +0 -396
  78. package/n4s.cjs.production.js +0 -396
  79. package/n4s.cjs.production.min.js +0 -1
  80. package/n4s.umd.development.js +0 -402
  81. package/n4s.umd.index.js +0 -7
  82. package/n4s.umd.production.js +0 -419
  83. package/n4s.umd.production.min.js +0 -1
@@ -1,1947 +0,0 @@
1
- function _extends() {
2
- _extends = Object.assign || function (target) {
3
- for (var i = 1; i < arguments.length; i++) {
4
- var source = arguments[i];
5
-
6
- for (var key in source) {
7
- if (Object.prototype.hasOwnProperty.call(source, key)) {
8
- target[key] = source[key];
9
- }
10
- }
11
- }
12
-
13
- return target;
14
- };
15
-
16
- return _extends.apply(this, arguments);
17
- }
18
-
19
- function throwError(message) {
20
- throw new Error(`[${"enforceExtended"}]: ${message}`);
21
- }
22
-
23
- const isRule = (rulesObject, name) => {
24
- const ruleExists = Object.prototype.hasOwnProperty.call(rulesObject, name) && typeof rulesObject[name] === 'function';
25
-
26
- if (!ruleExists) {
27
- throwError(`Rule "${name}" was not found in rules object. Make sure you typed it correctly.`);
28
- }
29
-
30
- return ruleExists;
31
- };
32
-
33
- const GLOBAL_OBJECT = Function('return this')();
34
-
35
- const proxySupported = () => typeof GLOBAL_OBJECT.Proxy === 'function';
36
-
37
- function bindNot(fn) {
38
- return function () {
39
- return !fn.apply(this, arguments);
40
- };
41
- }
42
-
43
- function endsWith(value, arg1) {
44
- return typeof value === 'string' && typeof arg1 === 'string' && value.endsWith(arg1);
45
- }
46
- const doesNotEndWith = bindNot(endsWith);
47
-
48
- function equals(value, arg1) {
49
- return value === arg1;
50
- }
51
- const notEquals = bindNot(equals);
52
-
53
- function isNumeric(value) {
54
- const result = !isNaN(parseFloat(value)) && !isNaN(Number(value)) && isFinite(value);
55
- return Boolean(result);
56
- }
57
- const isNotNumeric = bindNot(isNumeric);
58
-
59
- function greaterThan(value, arg1) {
60
- return isNumeric(value) && isNumeric(arg1) && Number(value) > Number(arg1);
61
- }
62
-
63
- function greaterThanOrEquals(value, arg1) {
64
- return isNumeric(value) && isNumeric(arg1) && Number(value) >= Number(arg1);
65
- }
66
-
67
- function inside(value, arg1) {
68
- if (Array.isArray(arg1) && ['string', 'number', 'boolean'].indexOf(typeof value) !== -1) {
69
- return arg1.indexOf(value) !== -1;
70
- } // both value and arg1 are strings
71
-
72
-
73
- if (typeof arg1 === 'string' && typeof value === 'string') {
74
- return arg1.indexOf(value) !== -1;
75
- }
76
-
77
- return false;
78
- }
79
- const notInside = bindNot(inside);
80
-
81
- function isArray(value) {
82
- return Boolean(Array.isArray(value));
83
- }
84
- const isNotArray = bindNot(isArray);
85
-
86
- function lessThanOrEquals(value, arg1) {
87
- return isNumeric(value) && isNumeric(arg1) && Number(value) <= Number(arg1);
88
- }
89
-
90
- function isBetween(value, min, max) {
91
- return greaterThanOrEquals(value, min) && lessThanOrEquals(value, max);
92
- }
93
- const isNotBetween = bindNot(isBetween);
94
-
95
- function isEmpty(value) {
96
- if (!value) {
97
- return true;
98
- } else if (isNumeric(value)) {
99
- return value === 0;
100
- } else if (Object.prototype.hasOwnProperty.call(value, 'length')) {
101
- return value.length === 0;
102
- } else if (typeof value === 'object') {
103
- return Object.keys(value).length === 0;
104
- } else {
105
- return true;
106
- }
107
- }
108
- const isNotEmpty = bindNot(isEmpty);
109
-
110
- /**
111
- * Validates that a given value is an even number
112
- * @param {Number|String} value Value to be validated
113
- * @return {Boolean}
114
- */
115
-
116
- const isEven = value => {
117
- if (!isNumeric(value)) {
118
- return false;
119
- }
120
-
121
- return value % 2 === 0;
122
- };
123
-
124
- function isNaN$1(value) {
125
- return Number.isNaN(value);
126
- }
127
- const isNotNaN = bindNot(isNaN$1);
128
-
129
- function isNegative(value) {
130
- if (isNumeric(value)) {
131
- return Number(value) < 0;
132
- }
133
-
134
- return false;
135
- }
136
- const isPositive = bindNot(isNegative);
137
-
138
- function isNull(value) {
139
- return value === null;
140
- }
141
- const isNotNull = bindNot(isNull);
142
-
143
- function isNumber(value) {
144
- return Boolean(typeof value === 'number');
145
- }
146
- const isNotNumber = bindNot(isNumber);
147
-
148
- /**
149
- * Validates that a given value is an odd number
150
- * @param {Number|String} value Value to be validated
151
- * @return {Boolean}
152
- */
153
-
154
- const isOdd = value => {
155
- if (!isNumeric(value)) {
156
- return false;
157
- }
158
-
159
- return value % 2 !== 0;
160
- };
161
-
162
- function isString(value) {
163
- return Boolean(typeof value === 'string');
164
- }
165
- const isNotString = bindNot(isString);
166
-
167
- function isTruthy(value) {
168
- return !!value;
169
- }
170
- const isFalsy = bindNot(isTruthy);
171
-
172
- function isUndefined(value) {
173
- return value === undefined;
174
- }
175
- const isNotUndefined = bindNot(isUndefined);
176
-
177
- function lengthEquals(value, arg1) {
178
- return value.length === arg1;
179
- }
180
- const lengthNotEquals = bindNot(lengthEquals);
181
-
182
- function lessThan(value, arg1) {
183
- return isNumeric(value) && isNumeric(arg1) && Number(value) < Number(arg1);
184
- }
185
-
186
- function longerThan(value, arg1) {
187
- return value.length > arg1;
188
- }
189
-
190
- function longerThanOrEquals(value, arg1) {
191
- return value.length >= arg1;
192
- }
193
-
194
- function matches(value, regex) {
195
- if (regex instanceof RegExp) {
196
- return regex.test(value);
197
- } else if (typeof regex === 'string') {
198
- return new RegExp(regex).test(value);
199
- } else {
200
- return false;
201
- }
202
- }
203
- const notMatches = bindNot(matches);
204
-
205
- function numberEquals(value, arg1) {
206
- return isNumeric(value) && isNumeric(arg1) && Number(value) === Number(arg1);
207
- }
208
- const numberNotEquals = bindNot(numberEquals);
209
-
210
- function shorterThan(value, arg1) {
211
- return value.length < arg1;
212
- }
213
-
214
- function shorterThanOrEquals(value, arg1) {
215
- return value.length <= arg1;
216
- }
217
-
218
- function startsWith(value, arg1) {
219
- return typeof value === 'string' && typeof arg1 === 'string' && value.startsWith(arg1);
220
- }
221
- const doesNotStartWith = bindNot(startsWith);
222
-
223
- var rules = {
224
- doesNotEndWith,
225
- doesNotStartWith,
226
- endsWith,
227
- equals,
228
- greaterThan,
229
- greaterThanOrEquals,
230
- gt: greaterThan,
231
- gte: greaterThanOrEquals,
232
- inside,
233
- isArray,
234
- isBetween,
235
- isEmpty,
236
- isEven,
237
- isFalsy,
238
- isNaN: isNaN$1,
239
- isNegative,
240
- isNotArray,
241
- isNotBetween,
242
- isNotEmpty,
243
- isNotNaN,
244
- isNotNull,
245
- isNotNumber,
246
- isNotNumeric,
247
- isNotString,
248
- isNotUndefined,
249
- isNull,
250
- isNumber,
251
- isNumeric,
252
- isOdd,
253
- isPositive,
254
- isString,
255
- isTruthy,
256
- isUndefined,
257
- lengthEquals,
258
- lengthNotEquals,
259
- lessThan,
260
- lessThanOrEquals,
261
- longerThan,
262
- longerThanOrEquals,
263
- lt: lessThan,
264
- lte: lessThanOrEquals,
265
- matches,
266
- notEquals,
267
- notInside,
268
- notMatches,
269
- numberEquals,
270
- numberNotEquals,
271
- shorterThan,
272
- shorterThanOrEquals,
273
- startsWith
274
- };
275
-
276
- function validateResult(result, rule) {
277
- if (typeof result !== 'boolean' && (!result || typeof result.pass !== 'boolean')) {
278
- throwError(`${rule.name} wrong return value for the rule please check that the return is valid`);
279
- }
280
- } // for easier testing and mocking
281
-
282
- function getDefaultResult(value, rule) {
283
- return {
284
- message: formatResultMessage(rule, `invalid ${typeof value} value`)
285
- };
286
- }
287
- function formatResultMessage(rule, msg) {
288
- return `[${"enforceExtended"}]/${rule.name} ${msg}`;
289
- }
290
- /**
291
- * Transform the result of a rule into a standard format
292
- * @param {string} interfaceName to be used in the messages
293
- * @param {*} result of the rule
294
- * @param {Object} options
295
- * @param {function} options.rule
296
- * @param {*} options.value
297
- * @returns {Object} result
298
- * @returns {string} result.message
299
- * @returns {boolean} result.pass indicates if the test passes or not
300
- */
301
-
302
- function transformResult(result, {
303
- rule,
304
- value
305
- }) {
306
- const defaultResult = getDefaultResult(value, rule);
307
- validateResult(result, rule);
308
-
309
- if (typeof result === 'boolean') {
310
- return _extends({}, defaultResult, {
311
- pass: result
312
- });
313
- } else {
314
- const formattedResult = {
315
- pass: result.pass
316
- };
317
-
318
- if (result.message) {
319
- formattedResult.message = formatResultMessage(rule, typeof result.message === 'function' ? result.message() : result.message);
320
- }
321
-
322
- return _extends({}, defaultResult, formattedResult);
323
- }
324
- }
325
-
326
- /**
327
- * Run a single rule against enforced value (e.g. `isNumber()`)
328
- *
329
- * @param {Function} rule - rule to run
330
- * @param {Any} value
331
- * @param {Array} args list of arguments sent from consumer
332
- * @throws
333
- */
334
-
335
- function runner(rule, value, ...args) {
336
- if (typeof rule !== 'function') {
337
- return;
338
- }
339
-
340
- const ruleResult = rule(value, ...args);
341
- const result = transformResult(ruleResult, {
342
- rule,
343
- value
344
- });
345
-
346
- if (!result.pass) {
347
- throw new Error(result.message);
348
- }
349
- }
350
-
351
- const rulesObject = _extends({}, rules);
352
-
353
- let enforce, rulesList;
354
-
355
- if (proxySupported()) {
356
- enforce = value => {
357
- const proxy = new Proxy(rulesObject, {
358
- get: (rules, fnName) => {
359
- if (!isRule(rules, fnName)) {
360
- return;
361
- }
362
-
363
- return (...args) => {
364
- runner(rules[fnName], value, ...args);
365
- return proxy;
366
- };
367
- }
368
- });
369
- return proxy;
370
- };
371
- } else {
372
- rulesList = Object.keys(rulesObject);
373
-
374
- enforce = value => rulesList.reduce((allRules, fnName) => Object.assign(allRules, _extends({}, isRule(rulesObject, fnName) && {
375
- [fnName]: (...args) => {
376
- runner(rulesObject[fnName], value, ...args);
377
- return allRules;
378
- }
379
- })), {});
380
- }
381
-
382
- enforce.extend = customRules => {
383
- Object.assign(rulesObject, customRules);
384
-
385
- if (!proxySupported()) {
386
- rulesList = Object.keys(rulesObject);
387
- }
388
-
389
- return enforce;
390
- };
391
-
392
- var enforce$1 = enforce;
393
-
394
- function _typeof(obj) {
395
- "@babel/helpers - typeof";
396
-
397
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
398
- _typeof = function _typeof(obj) {
399
- return typeof obj;
400
- };
401
- } else {
402
- _typeof = function _typeof(obj) {
403
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
404
- };
405
- }
406
-
407
- return _typeof(obj);
408
- }
409
-
410
- function assertString(input) {
411
- var isString = typeof input === 'string' || input instanceof String;
412
-
413
- if (!isString) {
414
- var invalidType;
415
-
416
- if (input === null) {
417
- invalidType = 'null';
418
- } else {
419
- invalidType = _typeof(input);
420
-
421
- if (invalidType === 'object' && input.constructor && input.constructor.hasOwnProperty('name')) {
422
- invalidType = input.constructor.name;
423
- } else {
424
- invalidType = "a ".concat(invalidType);
425
- }
426
- }
427
-
428
- throw new TypeError("Expected string but received ".concat(invalidType, "."));
429
- }
430
- }
431
-
432
- var alphanumeric = {
433
- 'en-US': /^[0-9A-Z]+$/i,
434
- 'bg-BG': /^[0-9А-Я]+$/i,
435
- 'cs-CZ': /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
436
- 'da-DK': /^[0-9A-ZÆØÅ]+$/i,
437
- 'de-DE': /^[0-9A-ZÄÖÜß]+$/i,
438
- 'el-GR': /^[0-9Α-ω]+$/i,
439
- 'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
440
- 'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
441
- 'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i,
442
- 'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
443
- 'nb-NO': /^[0-9A-ZÆØÅ]+$/i,
444
- 'nl-NL': /^[0-9A-ZÁÉËÏÓÖÜÚ]+$/i,
445
- 'nn-NO': /^[0-9A-ZÆØÅ]+$/i,
446
- 'pl-PL': /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
447
- 'pt-PT': /^[0-9A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i,
448
- 'ru-RU': /^[0-9А-ЯЁ]+$/i,
449
- 'sl-SI': /^[0-9A-ZČĆĐŠŽ]+$/i,
450
- 'sk-SK': /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i,
451
- 'sr-RS@latin': /^[0-9A-ZČĆŽŠĐ]+$/i,
452
- 'sr-RS': /^[0-9А-ЯЂЈЉЊЋЏ]+$/i,
453
- 'sv-SE': /^[0-9A-ZÅÄÖ]+$/i,
454
- 'tr-TR': /^[0-9A-ZÇĞİıÖŞÜ]+$/i,
455
- 'uk-UA': /^[0-9А-ЩЬЮЯЄIЇҐі]+$/i,
456
- 'ku-IQ': /^[٠١٢٣٤٥٦٧٨٩0-9ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
457
- 'vi-VN': /^[0-9A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i,
458
- ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
459
- he: /^[0-9א-ת]+$/,
460
- fa: /^['0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰']+$/i
461
- };
462
- var englishLocales = ['AU', 'GB', 'HK', 'IN', 'NZ', 'ZA', 'ZM'];
463
-
464
- for (var locale, i = 0; i < englishLocales.length; i++) {
465
- locale = "en-".concat(englishLocales[i]);
466
- alphanumeric[locale] = alphanumeric['en-US'];
467
- } // Source: http://www.localeplanet.com/java/
468
-
469
-
470
- var arabicLocales = ['AE', 'BH', 'DZ', 'EG', 'IQ', 'JO', 'KW', 'LB', 'LY', 'MA', 'QM', 'QA', 'SA', 'SD', 'SY', 'TN', 'YE'];
471
-
472
- for (var _locale, _i = 0; _i < arabicLocales.length; _i++) {
473
- _locale = "ar-".concat(arabicLocales[_i]);
474
- alphanumeric[_locale] = alphanumeric.ar;
475
- }
476
-
477
- var farsiLocales = ['IR', 'AF'];
478
-
479
- for (var _locale2, _i2 = 0; _i2 < farsiLocales.length; _i2++) {
480
- _locale2 = "fa-".concat(farsiLocales[_i2]);
481
- alphanumeric[_locale2] = alphanumeric.fa;
482
- } // Source: https://en.wikipedia.org/wiki/Decimal_mark
483
- alphanumeric['pt-BR'] = alphanumeric['pt-PT'];
484
- alphanumeric['pl-Pl'] = alphanumeric['pl-PL'];
485
-
486
- function isAlphanumeric(str) {
487
- var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
488
- assertString(str);
489
-
490
- if (locale in alphanumeric) {
491
- return alphanumeric[locale].test(str);
492
- }
493
-
494
- throw new Error("Invalid locale '".concat(locale, "'"));
495
- }
496
- var locales = Object.keys(alphanumeric);
497
-
498
- /* eslint-disable max-len */
499
-
500
- var creditCard = /^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14})$/;
501
- /* eslint-enable max-len */
502
-
503
- function isCreditCard(str) {
504
- assertString(str);
505
- var sanitized = str.replace(/[- ]+/g, '');
506
-
507
- if (!creditCard.test(sanitized)) {
508
- return false;
509
- }
510
-
511
- var sum = 0;
512
- var digit;
513
- var tmpNum;
514
- var shouldDouble;
515
-
516
- for (var i = sanitized.length - 1; i >= 0; i--) {
517
- digit = sanitized.substring(i, i + 1);
518
- tmpNum = parseInt(digit, 10);
519
-
520
- if (shouldDouble) {
521
- tmpNum *= 2;
522
-
523
- if (tmpNum >= 10) {
524
- sum += tmpNum % 10 + 1;
525
- } else {
526
- sum += tmpNum;
527
- }
528
- } else {
529
- sum += tmpNum;
530
- }
531
-
532
- shouldDouble = !shouldDouble;
533
- }
534
-
535
- return !!(sum % 10 === 0 ? sanitized : false);
536
- }
537
-
538
- function merge() {
539
- var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
540
- var defaults = arguments.length > 1 ? arguments[1] : undefined;
541
-
542
- for (var key in defaults) {
543
- if (typeof obj[key] === 'undefined') {
544
- obj[key] = defaults[key];
545
- }
546
- }
547
-
548
- return obj;
549
- }
550
-
551
- function currencyRegex(options) {
552
- var decimal_digits = "\\d{".concat(options.digits_after_decimal[0], "}");
553
- options.digits_after_decimal.forEach(function (digit, index) {
554
- if (index !== 0) decimal_digits = "".concat(decimal_digits, "|\\d{").concat(digit, "}");
555
- });
556
- var symbol = "(".concat(options.symbol.replace(/\W/, function (m) {
557
- return "\\".concat(m);
558
- }), ")").concat(options.require_symbol ? '' : '?'),
559
- negative = '-?',
560
- whole_dollar_amount_without_sep = '[1-9]\\d*',
561
- whole_dollar_amount_with_sep = "[1-9]\\d{0,2}(\\".concat(options.thousands_separator, "\\d{3})*"),
562
- valid_whole_dollar_amounts = ['0', whole_dollar_amount_without_sep, whole_dollar_amount_with_sep],
563
- whole_dollar_amount = "(".concat(valid_whole_dollar_amounts.join('|'), ")?"),
564
- decimal_amount = "(\\".concat(options.decimal_separator, "(").concat(decimal_digits, "))").concat(options.require_decimal ? '' : '?');
565
- var pattern = whole_dollar_amount + (options.allow_decimal || options.require_decimal ? decimal_amount : ''); // default is negative sign before symbol, but there are two other options (besides parens)
566
-
567
- if (options.allow_negatives && !options.parens_for_negatives) {
568
- if (options.negative_sign_after_digits) {
569
- pattern += negative;
570
- } else if (options.negative_sign_before_digits) {
571
- pattern = negative + pattern;
572
- }
573
- } // South African Rand, for example, uses R 123 (space) and R-123 (no space)
574
-
575
-
576
- if (options.allow_negative_sign_placeholder) {
577
- pattern = "( (?!\\-))?".concat(pattern);
578
- } else if (options.allow_space_after_symbol) {
579
- pattern = " ?".concat(pattern);
580
- } else if (options.allow_space_after_digits) {
581
- pattern += '( (?!$))?';
582
- }
583
-
584
- if (options.symbol_after_digits) {
585
- pattern += symbol;
586
- } else {
587
- pattern = symbol + pattern;
588
- }
589
-
590
- if (options.allow_negatives) {
591
- if (options.parens_for_negatives) {
592
- pattern = "(\\(".concat(pattern, "\\)|").concat(pattern, ")");
593
- } else if (!(options.negative_sign_before_digits || options.negative_sign_after_digits)) {
594
- pattern = negative + pattern;
595
- }
596
- } // ensure there's a dollar and/or decimal amount, and that
597
- // it doesn't start with a space or a negative sign followed by a space
598
-
599
-
600
- return new RegExp("^(?!-? )(?=.*\\d)".concat(pattern, "$"));
601
- }
602
-
603
- var default_currency_options = {
604
- symbol: '$',
605
- require_symbol: false,
606
- allow_space_after_symbol: false,
607
- symbol_after_digits: false,
608
- allow_negatives: true,
609
- parens_for_negatives: false,
610
- negative_sign_before_digits: false,
611
- negative_sign_after_digits: false,
612
- allow_negative_sign_placeholder: false,
613
- thousands_separator: ',',
614
- decimal_separator: '.',
615
- allow_decimal: true,
616
- require_decimal: false,
617
- digits_after_decimal: [2],
618
- allow_space_after_digits: false
619
- };
620
- function isCurrency(str, options) {
621
- assertString(str);
622
- options = merge(options, default_currency_options);
623
- return currencyRegex(options).test(str);
624
- }
625
-
626
- function _typeof$1(obj) {
627
- "@babel/helpers - typeof";
628
-
629
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
630
- _typeof$1 = function _typeof(obj) {
631
- return typeof obj;
632
- };
633
- } else {
634
- _typeof$1 = function _typeof(obj) {
635
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
636
- };
637
- }
638
-
639
- return _typeof$1(obj);
640
- }
641
- /* eslint-disable prefer-rest-params */
642
-
643
- function isByteLength(str, options) {
644
- assertString(str);
645
- var min;
646
- var max;
647
-
648
- if (_typeof$1(options) === 'object') {
649
- min = options.min || 0;
650
- max = options.max;
651
- } else {
652
- // backwards compatibility: isByteLength(str, min [, max])
653
- min = arguments[1];
654
- max = arguments[2];
655
- }
656
-
657
- var len = encodeURI(str).split(/%..|./).length - 1;
658
- return len >= min && (typeof max === 'undefined' || len <= max);
659
- }
660
-
661
- var default_fqdn_options = {
662
- require_tld: true,
663
- allow_underscores: false,
664
- allow_trailing_dot: false
665
- };
666
- function isFQDN(str, options) {
667
- assertString(str);
668
- options = merge(options, default_fqdn_options);
669
- /* Remove the optional trailing dot before checking validity */
670
-
671
- if (options.allow_trailing_dot && str[str.length - 1] === '.') {
672
- str = str.substring(0, str.length - 1);
673
- }
674
-
675
- var parts = str.split('.');
676
-
677
- for (var i = 0; i < parts.length; i++) {
678
- if (parts[i].length > 63) {
679
- return false;
680
- }
681
- }
682
-
683
- if (options.require_tld) {
684
- var tld = parts.pop();
685
-
686
- if (!parts.length || !/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
687
- return false;
688
- } // disallow spaces && special characers
689
-
690
-
691
- if (/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20\u00A9\uFFFD]/.test(tld)) {
692
- return false;
693
- }
694
- }
695
-
696
- for (var part, _i = 0; _i < parts.length; _i++) {
697
- part = parts[_i];
698
-
699
- if (options.allow_underscores) {
700
- part = part.replace(/_/g, '');
701
- }
702
-
703
- if (!/^[a-z\u00a1-\uffff0-9-]+$/i.test(part)) {
704
- return false;
705
- } // disallow full-width chars
706
-
707
-
708
- if (/[\uff01-\uff5e]/.test(part)) {
709
- return false;
710
- }
711
-
712
- if (part[0] === '-' || part[part.length - 1] === '-') {
713
- return false;
714
- }
715
- }
716
-
717
- return true;
718
- }
719
-
720
- /**
721
- 11.3. Examples
722
-
723
- The following addresses
724
-
725
- fe80::1234 (on the 1st link of the node)
726
- ff02::5678 (on the 5th link of the node)
727
- ff08::9abc (on the 10th organization of the node)
728
-
729
- would be represented as follows:
730
-
731
- fe80::1234%1
732
- ff02::5678%5
733
- ff08::9abc%10
734
-
735
- (Here we assume a natural translation from a zone index to the
736
- <zone_id> part, where the Nth zone of any scope is translated into
737
- "N".)
738
-
739
- If we use interface names as <zone_id>, those addresses could also be
740
- represented as follows:
741
-
742
- fe80::1234%ne0
743
- ff02::5678%pvc1.3
744
- ff08::9abc%interface10
745
-
746
- where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs
747
- to the 5th link, and "interface10" belongs to the 10th organization.
748
- * * */
749
-
750
- var ipv4Maybe = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
751
- var ipv6Block = /^[0-9A-F]{1,4}$/i;
752
- function isIP(str) {
753
- var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
754
- assertString(str);
755
- version = String(version);
756
-
757
- if (!version) {
758
- return isIP(str, 4) || isIP(str, 6);
759
- } else if (version === '4') {
760
- if (!ipv4Maybe.test(str)) {
761
- return false;
762
- }
763
-
764
- var parts = str.split('.').sort(function (a, b) {
765
- return a - b;
766
- });
767
- return parts[3] <= 255;
768
- } else if (version === '6') {
769
- var addressAndZone = [str]; // ipv6 addresses could have scoped architecture
770
- // according to https://tools.ietf.org/html/rfc4007#section-11
771
-
772
- if (str.includes('%')) {
773
- addressAndZone = str.split('%');
774
-
775
- if (addressAndZone.length !== 2) {
776
- // it must be just two parts
777
- return false;
778
- }
779
-
780
- if (!addressAndZone[0].includes(':')) {
781
- // the first part must be the address
782
- return false;
783
- }
784
-
785
- if (addressAndZone[1] === '') {
786
- // the second part must not be empty
787
- return false;
788
- }
789
- }
790
-
791
- var blocks = addressAndZone[0].split(':');
792
- var foundOmissionBlock = false; // marker to indicate ::
793
- // At least some OS accept the last 32 bits of an IPv6 address
794
- // (i.e. 2 of the blocks) in IPv4 notation, and RFC 3493 says
795
- // that '::ffff:a.b.c.d' is valid for IPv4-mapped IPv6 addresses,
796
- // and '::a.b.c.d' is deprecated, but also valid.
797
-
798
- var foundIPv4TransitionBlock = isIP(blocks[blocks.length - 1], 4);
799
- var expectedNumberOfBlocks = foundIPv4TransitionBlock ? 7 : 8;
800
-
801
- if (blocks.length > expectedNumberOfBlocks) {
802
- return false;
803
- } // initial or final ::
804
-
805
-
806
- if (str === '::') {
807
- return true;
808
- } else if (str.substr(0, 2) === '::') {
809
- blocks.shift();
810
- blocks.shift();
811
- foundOmissionBlock = true;
812
- } else if (str.substr(str.length - 2) === '::') {
813
- blocks.pop();
814
- blocks.pop();
815
- foundOmissionBlock = true;
816
- }
817
-
818
- for (var i = 0; i < blocks.length; ++i) {
819
- // test for a :: which can not be at the string start/end
820
- // since those cases have been handled above
821
- if (blocks[i] === '' && i > 0 && i < blocks.length - 1) {
822
- if (foundOmissionBlock) {
823
- return false; // multiple :: in address
824
- }
825
-
826
- foundOmissionBlock = true;
827
- } else if (foundIPv4TransitionBlock && i === blocks.length - 1) ; else if (!ipv6Block.test(blocks[i])) {
828
- return false;
829
- }
830
- }
831
-
832
- if (foundOmissionBlock) {
833
- return blocks.length >= 1;
834
- }
835
-
836
- return blocks.length === expectedNumberOfBlocks;
837
- }
838
-
839
- return false;
840
- }
841
-
842
- function _slicedToArray(arr, i) {
843
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
844
- }
845
-
846
- function _nonIterableRest() {
847
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
848
- }
849
-
850
- function _unsupportedIterableToArray(o, minLen) {
851
- if (!o) return;
852
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
853
- var n = Object.prototype.toString.call(o).slice(8, -1);
854
- if (n === "Object" && o.constructor) n = o.constructor.name;
855
- if (n === "Map" || n === "Set") return Array.from(o);
856
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
857
- }
858
-
859
- function _arrayLikeToArray(arr, len) {
860
- if (len == null || len > arr.length) len = arr.length;
861
-
862
- for (var i = 0, arr2 = new Array(len); i < len; i++) {
863
- arr2[i] = arr[i];
864
- }
865
-
866
- return arr2;
867
- }
868
-
869
- function _iterableToArrayLimit(arr, i) {
870
- if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
871
- var _arr = [];
872
- var _n = true;
873
- var _d = false;
874
- var _e = undefined;
875
-
876
- try {
877
- for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
878
- _arr.push(_s.value);
879
-
880
- if (i && _arr.length === i) break;
881
- }
882
- } catch (err) {
883
- _d = true;
884
- _e = err;
885
- } finally {
886
- try {
887
- if (!_n && _i["return"] != null) _i["return"]();
888
- } finally {
889
- if (_d) throw _e;
890
- }
891
- }
892
-
893
- return _arr;
894
- }
895
-
896
- function _arrayWithHoles(arr) {
897
- if (Array.isArray(arr)) return arr;
898
- }
899
- var default_email_options = {
900
- allow_display_name: false,
901
- require_display_name: false,
902
- allow_utf8_local_part: true,
903
- require_tld: true
904
- };
905
- /* eslint-disable max-len */
906
-
907
- /* eslint-disable no-control-regex */
908
-
909
- var splitNameAddress = /^([^\x00-\x1F\x7F-\x9F\cX]+)<(.+)>$/i;
910
- var emailUserPart = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i;
911
- var gmailUserPart = /^[a-z\d]+$/;
912
- var quotedEmailUser = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i;
913
- var emailUserUtf8Part = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i;
914
- var quotedEmailUserUtf8 = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i;
915
- var defaultMaxEmailLength = 254;
916
- /* eslint-enable max-len */
917
-
918
- /* eslint-enable no-control-regex */
919
-
920
- /**
921
- * Validate display name according to the RFC2822: https://tools.ietf.org/html/rfc2822#appendix-A.1.2
922
- * @param {String} display_name
923
- */
924
-
925
- function validateDisplayName(display_name) {
926
- var trim_quotes = display_name.match(/^"(.+)"$/i);
927
- var display_name_without_quotes = trim_quotes ? trim_quotes[1] : display_name; // display name with only spaces is not valid
928
-
929
- if (!display_name_without_quotes.trim()) {
930
- return false;
931
- } // check whether display name contains illegal character
932
-
933
-
934
- var contains_illegal = /[\.";<>]/.test(display_name_without_quotes);
935
-
936
- if (contains_illegal) {
937
- // if contains illegal characters,
938
- // must to be enclosed in double-quotes, otherwise it's not a valid display name
939
- if (!trim_quotes) {
940
- return false;
941
- } // the quotes in display name must start with character symbol \
942
-
943
-
944
- var all_start_with_back_slash = display_name_without_quotes.split('"').length === display_name_without_quotes.split('\\"').length;
945
-
946
- if (!all_start_with_back_slash) {
947
- return false;
948
- }
949
- }
950
-
951
- return true;
952
- }
953
-
954
- function isEmail(str, options) {
955
- assertString(str);
956
- options = merge(options, default_email_options);
957
-
958
- if (options.require_display_name || options.allow_display_name) {
959
- var display_email = str.match(splitNameAddress);
960
-
961
- if (display_email) {
962
- var display_name;
963
-
964
- var _display_email = _slicedToArray(display_email, 3);
965
-
966
- display_name = _display_email[1];
967
- str = _display_email[2]; // sometimes need to trim the last space to get the display name
968
- // because there may be a space between display name and email address
969
- // eg. myname <address@gmail.com>
970
- // the display name is `myname` instead of `myname `, so need to trim the last space
971
-
972
- if (display_name.endsWith(' ')) {
973
- display_name = display_name.substr(0, display_name.length - 1);
974
- }
975
-
976
- if (!validateDisplayName(display_name)) {
977
- return false;
978
- }
979
- } else if (options.require_display_name) {
980
- return false;
981
- }
982
- }
983
-
984
- if (!options.ignore_max_length && str.length > defaultMaxEmailLength) {
985
- return false;
986
- }
987
-
988
- var parts = str.split('@');
989
- var domain = parts.pop();
990
- var user = parts.join('@');
991
- var lower_domain = domain.toLowerCase();
992
-
993
- if (options.domain_specific_validation && (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com')) {
994
- /*
995
- Previously we removed dots for gmail addresses before validating.
996
- This was removed because it allows `multiple..dots@gmail.com`
997
- to be reported as valid, but it is not.
998
- Gmail only normalizes single dots, removing them from here is pointless,
999
- should be done in normalizeEmail
1000
- */
1001
- user = user.toLowerCase(); // Removing sub-address from username before gmail validation
1002
-
1003
- var username = user.split('+')[0]; // Dots are not included in gmail length restriction
1004
-
1005
- if (!isByteLength(username.replace('.', ''), {
1006
- min: 6,
1007
- max: 30
1008
- })) {
1009
- return false;
1010
- }
1011
-
1012
- var _user_parts = username.split('.');
1013
-
1014
- for (var i = 0; i < _user_parts.length; i++) {
1015
- if (!gmailUserPart.test(_user_parts[i])) {
1016
- return false;
1017
- }
1018
- }
1019
- }
1020
-
1021
- if (!isByteLength(user, {
1022
- max: 64
1023
- }) || !isByteLength(domain, {
1024
- max: 254
1025
- })) {
1026
- return false;
1027
- }
1028
-
1029
- if (!isFQDN(domain, {
1030
- require_tld: options.require_tld
1031
- })) {
1032
- if (!options.allow_ip_domain) {
1033
- return false;
1034
- }
1035
-
1036
- if (!isIP(domain)) {
1037
- if (!domain.startsWith('[') || !domain.endsWith(']')) {
1038
- return false;
1039
- }
1040
-
1041
- var noBracketdomain = domain.substr(1, domain.length - 2);
1042
-
1043
- if (noBracketdomain.length === 0 || !isIP(noBracketdomain)) {
1044
- return false;
1045
- }
1046
- }
1047
- }
1048
-
1049
- if (user[0] === '"') {
1050
- user = user.slice(1, user.length - 1);
1051
- return options.allow_utf8_local_part ? quotedEmailUserUtf8.test(user) : quotedEmailUser.test(user);
1052
- }
1053
-
1054
- var pattern = options.allow_utf8_local_part ? emailUserUtf8Part : emailUserPart;
1055
- var user_parts = user.split('.');
1056
-
1057
- for (var _i2 = 0; _i2 < user_parts.length; _i2++) {
1058
- if (!pattern.test(user_parts[_i2])) {
1059
- return false;
1060
- }
1061
- }
1062
-
1063
- return true;
1064
- }
1065
-
1066
- var validators = {
1067
- ES: function ES(str) {
1068
- assertString(str);
1069
- var DNI = /^[0-9X-Z][0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKE]$/;
1070
- var charsValue = {
1071
- X: 0,
1072
- Y: 1,
1073
- Z: 2
1074
- };
1075
- 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']; // sanitize user input
1076
-
1077
- var sanitized = str.trim().toUpperCase(); // validate the data structure
1078
-
1079
- if (!DNI.test(sanitized)) {
1080
- return false;
1081
- } // validate the control digit
1082
-
1083
-
1084
- var number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, function (_char) {
1085
- return charsValue[_char];
1086
- });
1087
- return sanitized.endsWith(controlDigits[number % 23]);
1088
- },
1089
- IN: function IN(str) {
1090
- var DNI = /^[1-9]\d{3}\s?\d{4}\s?\d{4}$/; // multiplication table
1091
-
1092
- 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]]; // permutation table
1093
-
1094
- 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]]; // sanitize user input
1095
-
1096
- var sanitized = str.trim(); // validate the data structure
1097
-
1098
- if (!DNI.test(sanitized)) {
1099
- return false;
1100
- }
1101
-
1102
- var c = 0;
1103
- var invertedArray = sanitized.replace(/\s/g, '').split('').map(Number).reverse();
1104
- invertedArray.forEach(function (val, i) {
1105
- c = d[c][p[i % 8][val]];
1106
- });
1107
- return c === 0;
1108
- },
1109
- IT: function IT(str) {
1110
- if (str.length !== 9) return false;
1111
- if (str === 'CA00000AA') return false; // https://it.wikipedia.org/wiki/Carta_d%27identit%C3%A0_elettronica_italiana
1112
-
1113
- return str.search(/C[A-Z][0-9]{5}[A-Z]{2}/i) > -1;
1114
- },
1115
- NO: function NO(str) {
1116
- var sanitized = str.trim();
1117
- if (isNaN(Number(sanitized))) return false;
1118
- if (sanitized.length !== 11) return false;
1119
- if (sanitized === '00000000000') return false; // https://no.wikipedia.org/wiki/F%C3%B8dselsnummer
1120
-
1121
- var f = sanitized.split('').map(Number);
1122
- 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;
1123
- 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;
1124
- if (k1 !== f[9] || k2 !== f[10]) return false;
1125
- return true;
1126
- },
1127
- 'he-IL': function heIL(str) {
1128
- var DNI = /^\d{9}$/; // sanitize user input
1129
-
1130
- var sanitized = str.trim(); // validate the data structure
1131
-
1132
- if (!DNI.test(sanitized)) {
1133
- return false;
1134
- }
1135
-
1136
- var id = sanitized;
1137
- var sum = 0,
1138
- incNum;
1139
-
1140
- for (var i = 0; i < id.length; i++) {
1141
- incNum = Number(id[i]) * (i % 2 + 1); // Multiply number by 1 or 2
1142
-
1143
- sum += incNum > 9 ? incNum - 9 : incNum; // Sum the digits up and add to total
1144
- }
1145
-
1146
- return sum % 10 === 0;
1147
- },
1148
- 'ar-TN': function arTN(str) {
1149
- var DNI = /^\d{8}$/; // sanitize user input
1150
-
1151
- var sanitized = str.trim(); // validate the data structure
1152
-
1153
- if (!DNI.test(sanitized)) {
1154
- return false;
1155
- }
1156
-
1157
- return true;
1158
- },
1159
- 'zh-CN': function zhCN(str) {
1160
- var provincesAndCities = ['11', // 北京
1161
- '12', // 天津
1162
- '13', // 河北
1163
- '14', // 山西
1164
- '15', // 内蒙古
1165
- '21', // 辽宁
1166
- '22', // 吉林
1167
- '23', // 黑龙江
1168
- '31', // 上海
1169
- '32', // 江苏
1170
- '33', // 浙江
1171
- '34', // 安徽
1172
- '35', // 福建
1173
- '36', // 江西
1174
- '37', // 山东
1175
- '41', // 河南
1176
- '42', // 湖北
1177
- '43', // 湖南
1178
- '44', // 广东
1179
- '45', // 广西
1180
- '46', // 海南
1181
- '50', // 重庆
1182
- '51', // 四川
1183
- '52', // 贵州
1184
- '53', // 云南
1185
- '54', // 西藏
1186
- '61', // 陕西
1187
- '62', // 甘肃
1188
- '63', // 青海
1189
- '64', // 宁夏
1190
- '65', // 新疆
1191
- '71', // 台湾
1192
- '81', // 香港
1193
- '82', // 澳门
1194
- '91' // 国外
1195
- ];
1196
- var powers = ['7', '9', '10', '5', '8', '4', '2', '1', '6', '3', '7', '9', '10', '5', '8', '4', '2'];
1197
- var parityBit = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
1198
-
1199
- var checkAddressCode = function checkAddressCode(addressCode) {
1200
- return provincesAndCities.includes(addressCode);
1201
- };
1202
-
1203
- var checkBirthDayCode = function checkBirthDayCode(birDayCode) {
1204
- var yyyy = parseInt(birDayCode.substring(0, 4), 10);
1205
- var mm = parseInt(birDayCode.substring(4, 6), 10);
1206
- var dd = parseInt(birDayCode.substring(6), 10);
1207
- var xdata = new Date(yyyy, mm - 1, dd);
1208
-
1209
- if (xdata > new Date()) {
1210
- return false; // eslint-disable-next-line max-len
1211
- } else if (xdata.getFullYear() === yyyy && xdata.getMonth() === mm - 1 && xdata.getDate() === dd) {
1212
- return true;
1213
- }
1214
-
1215
- return false;
1216
- };
1217
-
1218
- var getParityBit = function getParityBit(idCardNo) {
1219
- var id17 = idCardNo.substring(0, 17);
1220
- var power = 0;
1221
-
1222
- for (var i = 0; i < 17; i++) {
1223
- power += parseInt(id17.charAt(i), 10) * parseInt(powers[i], 10);
1224
- }
1225
-
1226
- var mod = power % 11;
1227
- return parityBit[mod];
1228
- };
1229
-
1230
- var checkParityBit = function checkParityBit(idCardNo) {
1231
- return getParityBit(idCardNo) === idCardNo.charAt(17).toUpperCase();
1232
- };
1233
-
1234
- var check15IdCardNo = function check15IdCardNo(idCardNo) {
1235
- 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);
1236
- if (!check) return false;
1237
- var addressCode = idCardNo.substring(0, 2);
1238
- check = checkAddressCode(addressCode);
1239
- if (!check) return false;
1240
- var birDayCode = "19".concat(idCardNo.substring(6, 12));
1241
- check = checkBirthDayCode(birDayCode);
1242
- if (!check) return false;
1243
- return true;
1244
- };
1245
-
1246
- var check18IdCardNo = function check18IdCardNo(idCardNo) {
1247
- 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);
1248
- if (!check) return false;
1249
- var addressCode = idCardNo.substring(0, 2);
1250
- check = checkAddressCode(addressCode);
1251
- if (!check) return false;
1252
- var birDayCode = idCardNo.substring(6, 14);
1253
- check = checkBirthDayCode(birDayCode);
1254
- if (!check) return false;
1255
- return checkParityBit(idCardNo);
1256
- };
1257
-
1258
- var checkIdCardNo = function checkIdCardNo(idCardNo) {
1259
- var check = /^\d{15}|(\d{17}(\d|x|X))$/.test(idCardNo);
1260
- if (!check) return false;
1261
-
1262
- if (idCardNo.length === 15) {
1263
- return check15IdCardNo(idCardNo);
1264
- }
1265
-
1266
- return check18IdCardNo(idCardNo);
1267
- };
1268
-
1269
- return checkIdCardNo(str);
1270
- },
1271
- 'zh-TW': function zhTW(str) {
1272
- var ALPHABET_CODES = {
1273
- A: 10,
1274
- B: 11,
1275
- C: 12,
1276
- D: 13,
1277
- E: 14,
1278
- F: 15,
1279
- G: 16,
1280
- H: 17,
1281
- I: 34,
1282
- J: 18,
1283
- K: 19,
1284
- L: 20,
1285
- M: 21,
1286
- N: 22,
1287
- O: 35,
1288
- P: 23,
1289
- Q: 24,
1290
- R: 25,
1291
- S: 26,
1292
- T: 27,
1293
- U: 28,
1294
- V: 29,
1295
- W: 32,
1296
- X: 30,
1297
- Y: 31,
1298
- Z: 33
1299
- };
1300
- var sanitized = str.trim().toUpperCase();
1301
- if (!/^[A-Z][0-9]{9}$/.test(sanitized)) return false;
1302
- return Array.from(sanitized).reduce(function (sum, number, index) {
1303
- if (index === 0) {
1304
- var code = ALPHABET_CODES[number];
1305
- return code % 10 * 9 + Math.floor(code / 10);
1306
- }
1307
-
1308
- if (index === 9) {
1309
- return (10 - sum % 10 - Number(number)) % 10 === 0;
1310
- }
1311
-
1312
- return sum + Number(number) * (9 - index);
1313
- }, 0);
1314
- }
1315
- };
1316
- function isIdentityCard(str, locale) {
1317
- assertString(str);
1318
-
1319
- if (locale in validators) {
1320
- return validators[locale](str);
1321
- } else if (locale === 'any') {
1322
- for (var key in validators) {
1323
- // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
1324
- // istanbul ignore else
1325
- if (validators.hasOwnProperty(key)) {
1326
- var validator = validators[key];
1327
-
1328
- if (validator(str)) {
1329
- return true;
1330
- }
1331
- }
1332
- }
1333
-
1334
- return false;
1335
- }
1336
-
1337
- throw new Error("Invalid locale '".concat(locale, "'"));
1338
- }
1339
-
1340
- function _typeof$2(obj) {
1341
- "@babel/helpers - typeof";
1342
-
1343
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
1344
- _typeof$2 = function _typeof(obj) {
1345
- return typeof obj;
1346
- };
1347
- } else {
1348
- _typeof$2 = function _typeof(obj) {
1349
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
1350
- };
1351
- }
1352
-
1353
- return _typeof$2(obj);
1354
- }
1355
- var default_json_options = {
1356
- allow_primitives: false
1357
- };
1358
- function isJSON(str, options) {
1359
- assertString(str);
1360
-
1361
- try {
1362
- options = merge(options, default_json_options);
1363
- var primitives = [];
1364
-
1365
- if (options.allow_primitives) {
1366
- primitives = [null, false, true];
1367
- }
1368
-
1369
- var obj = JSON.parse(str);
1370
- return primitives.includes(obj) || !!obj && _typeof$2(obj) === 'object';
1371
- } catch (e) {
1372
- /* ignore */
1373
- }
1374
-
1375
- return false;
1376
- }
1377
-
1378
- var localeReg = /^[A-z]{2,4}([_-]([A-z]{4}|[\d]{3}))?([_-]([A-z]{2}|[\d]{3}))?$/;
1379
- function isLocale(str) {
1380
- assertString(str);
1381
-
1382
- if (str === 'en_US_POSIX' || str === 'ca_ES_VALENCIA') {
1383
- return true;
1384
- }
1385
-
1386
- return localeReg.test(str);
1387
- }
1388
-
1389
- /*
1390
- Checks if the provided string matches to a correct Media type format (MIME type)
1391
-
1392
- This function only checks is the string format follows the
1393
- etablished rules by the according RFC specifications.
1394
- This function supports 'charset' in textual media types
1395
- (https://tools.ietf.org/html/rfc6657).
1396
-
1397
- This function does not check against all the media types listed
1398
- by the IANA (https://www.iana.org/assignments/media-types/media-types.xhtml)
1399
- because of lightness purposes : it would require to include
1400
- all these MIME types in this librairy, which would weigh it
1401
- significantly. This kind of effort maybe is not worth for the use that
1402
- this function has in this entire librairy.
1403
-
1404
- More informations in the RFC specifications :
1405
- - https://tools.ietf.org/html/rfc2045
1406
- - https://tools.ietf.org/html/rfc2046
1407
- - https://tools.ietf.org/html/rfc7231#section-3.1.1.1
1408
- - https://tools.ietf.org/html/rfc7231#section-3.1.1.5
1409
- */
1410
- // Match simple MIME types
1411
- // NB :
1412
- // Subtype length must not exceed 100 characters.
1413
- // This rule does not comply to the RFC specs (what is the max length ?).
1414
-
1415
- var mimeTypeSimple = /^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9\.\-\+]{1,100}$/i; // eslint-disable-line max-len
1416
- // Handle "charset" in "text/*"
1417
-
1418
- var mimeTypeText = /^text\/[a-zA-Z0-9\.\-\+]{1,100};\s?charset=("[a-zA-Z0-9\.\-\+\s]{0,70}"|[a-zA-Z0-9\.\-\+]{0,70})(\s?\([a-zA-Z0-9\.\-\+\s]{1,20}\))?$/i; // eslint-disable-line max-len
1419
- // Handle "boundary" in "multipart/*"
1420
-
1421
- var mimeTypeMultipart = /^multipart\/[a-zA-Z0-9\.\-\+]{1,100}(;\s?(boundary|charset)=("[a-zA-Z0-9\.\-\+\s]{0,70}"|[a-zA-Z0-9\.\-\+]{0,70})(\s?\([a-zA-Z0-9\.\-\+\s]{1,20}\))?){0,2}$/i; // eslint-disable-line max-len
1422
-
1423
- function isMimeType(str) {
1424
- assertString(str);
1425
- return mimeTypeSimple.test(str) || mimeTypeText.test(str) || mimeTypeMultipart.test(str);
1426
- }
1427
-
1428
- /* eslint-disable max-len */
1429
-
1430
- var phones = {
1431
- 'am-AM': /^(\+?374|0)((10|[9|7][0-9])\d{6}$|[2-4]\d{7}$)/,
1432
- 'ar-AE': /^((\+?971)|0)?5[024568]\d{7}$/,
1433
- 'ar-BH': /^(\+?973)?(3|6)\d{7}$/,
1434
- 'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/,
1435
- 'ar-EG': /^((\+?20)|0)?1[0125]\d{8}$/,
1436
- 'ar-IQ': /^(\+?964|0)?7[0-9]\d{8}$/,
1437
- 'ar-JO': /^(\+?962|0)?7[789]\d{7}$/,
1438
- 'ar-KW': /^(\+?965)[569]\d{7}$/,
1439
- 'ar-LY': /^((\+?218)|0)?(9[1-6]\d{7}|[1-8]\d{7,9})$/,
1440
- 'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/,
1441
- 'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/,
1442
- 'ar-TN': /^(\+?216)?[2459]\d{7}$/,
1443
- 'az-AZ': /^(\+994|0)(5[015]|7[07]|99)\d{7}$/,
1444
- 'bs-BA': /^((((\+|00)3876)|06))((([0-3]|[5-6])\d{6})|(4\d{7}))$/,
1445
- 'be-BY': /^(\+?375)?(24|25|29|33|44)\d{7}$/,
1446
- 'bg-BG': /^(\+?359|0)?8[789]\d{7}$/,
1447
- 'bn-BD': /^(\+?880|0)1[13456789][0-9]{8}$/,
1448
- 'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
1449
- 'da-DK': /^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/,
1450
- 'de-DE': /^(\+49)?0?[1|3]([0|5][0-45-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7}$/,
1451
- 'de-AT': /^(\+43|0)\d{1,4}\d{3,12}$/,
1452
- 'de-CH': /^(\+41|0)(7[5-9])\d{1,7}$/,
1453
- 'el-GR': /^(\+?30|0)?(69\d{8})$/,
1454
- 'en-AU': /^(\+?61|0)4\d{8}$/,
1455
- 'en-GB': /^(\+?44|0)7\d{9}$/,
1456
- 'en-GG': /^(\+?44|0)1481\d{6}$/,
1457
- 'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28)\d{7}$/,
1458
- 'en-HK': /^(\+?852[-\s]?)?[456789]\d{3}[-\s]?\d{4}$/,
1459
- 'en-MO': /^(\+?853[-\s]?)?[6]\d{3}[-\s]?\d{4}$/,
1460
- 'en-IE': /^(\+?353|0)8[356789]\d{7}$/,
1461
- 'en-IN': /^(\+?91|0)?[6789]\d{9}$/,
1462
- 'en-KE': /^(\+?254|0)(7|1)\d{8}$/,
1463
- 'en-MT': /^(\+?356|0)?(99|79|77|21|27|22|25)[0-9]{6}$/,
1464
- 'en-MU': /^(\+?230|0)?\d{8}$/,
1465
- 'en-NG': /^(\+?234|0)?[789]\d{9}$/,
1466
- 'en-NZ': /^(\+?64|0)[28]\d{7,9}$/,
1467
- 'en-PK': /^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$/,
1468
- 'en-PH': /^(09|\+639)\d{9}$/,
1469
- 'en-RW': /^(\+?250|0)?[7]\d{8}$/,
1470
- 'en-SG': /^(\+65)?[689]\d{7}$/,
1471
- 'en-SL': /^(?:0|94|\+94)?(7(0|1|2|5|6|7|8)( |-)?\d)\d{6}$/,
1472
- 'en-TZ': /^(\+?255|0)?[67]\d{8}$/,
1473
- 'en-UG': /^(\+?256|0)?[7]\d{8}$/,
1474
- 'en-US': /^((\+1|1)?( |-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})( |-)?([2-9][0-9]{2}( |-)?[0-9]{4})$/,
1475
- 'en-ZA': /^(\+?27|0)\d{9}$/,
1476
- 'en-ZM': /^(\+?26)?09[567]\d{7}$/,
1477
- 'en-ZW': /^(\+263)[0-9]{9}$/,
1478
- 'es-CO': /^(\+?57)?([1-8]{1}|3[0-9]{2})?[2-9]{1}\d{6}$/,
1479
- 'es-CL': /^(\+?56|0)[2-9]\d{1}\d{7}$/,
1480
- 'es-CR': /^(\+506)?[2-8]\d{7}$/,
1481
- 'es-EC': /^(\+?593|0)([2-7]|9[2-9])\d{7}$/,
1482
- 'es-ES': /^(\+?34)?[6|7]\d{8}$/,
1483
- 'es-MX': /^(\+?52)?(1|01)?\d{10,11}$/,
1484
- 'es-PA': /^(\+?507)\d{7,8}$/,
1485
- 'es-PY': /^(\+?595|0)9[9876]\d{7}$/,
1486
- 'es-UY': /^(\+598|0)9[1-9][\d]{6}$/,
1487
- 'et-EE': /^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/,
1488
- 'fa-IR': /^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/,
1489
- 'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5|6)?|50)\s?(\d\s?){4,8}\d$/,
1490
- 'fj-FJ': /^(\+?679)?\s?\d{3}\s?\d{4}$/,
1491
- 'fo-FO': /^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
1492
- 'fr-FR': /^(\+?33|0)[67]\d{8}$/,
1493
- 'fr-GF': /^(\+?594|0|00594)[67]\d{8}$/,
1494
- 'fr-GP': /^(\+?590|0|00590)[67]\d{8}$/,
1495
- 'fr-MQ': /^(\+?596|0|00596)[67]\d{8}$/,
1496
- 'fr-RE': /^(\+?262|0|00262)[67]\d{8}$/,
1497
- 'he-IL': /^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/,
1498
- 'hu-HU': /^(\+?36)(20|30|70)\d{7}$/,
1499
- 'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,
1500
- 'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/,
1501
- 'ja-JP': /^(\+81[ \-]?(\(0\))?|0)[6789]0[ \-]?\d{4}[ \-]?\d{4}$/,
1502
- 'kk-KZ': /^(\+?7|8)?7\d{9}$/,
1503
- 'kl-GL': /^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
1504
- 'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,
1505
- 'lt-LT': /^(\+370|8)\d{8}$/,
1506
- 'ms-MY': /^(\+?6?01){1}(([0145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,
1507
- 'nb-NO': /^(\+?47)?[49]\d{7}$/,
1508
- 'ne-NP': /^(\+?977)?9[78]\d{8}$/,
1509
- 'nl-BE': /^(\+?32|0)4?\d{8}$/,
1510
- 'nl-NL': /^(((\+|00)?31\(0\))|((\+|00)?31)|0)6{1}\d{8}$/,
1511
- 'nn-NO': /^(\+?47)?[49]\d{7}$/,
1512
- 'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/,
1513
- 'pt-BR': /(?=^(\+?5{2}\-?|0)[1-9]{2}\-?\d{4}\-?\d{4}$)(^(\+?5{2}\-?|0)[1-9]{2}\-?[6-9]{1}\d{3}\-?\d{4}$)|(^(\+?5{2}\-?|0)[1-9]{2}\-?9[6-9]{1}\d{3}\-?\d{4}$)/,
1514
- 'pt-PT': /^(\+?351)?9[1236]\d{7}$/,
1515
- 'ro-RO': /^(\+?4?0)\s?7\d{2}(\/|\s|\.|\-)?\d{3}(\s|\.|\-)?\d{3}$/,
1516
- 'ru-RU': /^(\+?7|8)?9\d{9}$/,
1517
- 'sl-SI': /^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/,
1518
- 'sk-SK': /^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
1519
- 'sr-RS': /^(\+3816|06)[- \d]{5,9}$/,
1520
- 'sv-SE': /^(\+?46|0)[\s\-]?7[\s\-]?[02369]([\s\-]?\d){7}$/,
1521
- 'th-TH': /^(\+66|66|0)\d{9}$/,
1522
- 'tr-TR': /^(\+?90|0)?5\d{9}$/,
1523
- 'uk-UA': /^(\+?38|8)?0\d{9}$/,
1524
- 'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/,
1525
- 'vi-VN': /^(\+?84|0)((3([2-9]))|(5([2689]))|(7([0|6-9]))|(8([1-6|89]))|(9([0-9])))([0-9]{7})$/,
1526
- 'zh-CN': /^((\+|00)86)?1([3568][0-9]|4[579]|6[67]|7[01235678]|9[012356789])[0-9]{8}$/,
1527
- 'zh-TW': /^(\+?886\-?|0)?9\d{8}$/
1528
- };
1529
- /* eslint-enable max-len */
1530
- // aliases
1531
-
1532
- phones['en-CA'] = phones['en-US'];
1533
- phones['fr-BE'] = phones['nl-BE'];
1534
- phones['zh-HK'] = phones['en-HK'];
1535
- phones['zh-MO'] = phones['en-MO'];
1536
- function isMobilePhone(str, locale, options) {
1537
- assertString(str);
1538
-
1539
- if (options && options.strictMode && !str.startsWith('+')) {
1540
- return false;
1541
- }
1542
-
1543
- if (Array.isArray(locale)) {
1544
- return locale.some(function (key) {
1545
- // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
1546
- // istanbul ignore else
1547
- if (phones.hasOwnProperty(key)) {
1548
- var phone = phones[key];
1549
-
1550
- if (phone.test(str)) {
1551
- return true;
1552
- }
1553
- }
1554
-
1555
- return false;
1556
- });
1557
- } else if (locale in phones) {
1558
- return phones[locale].test(str); // alias falsey locale as 'any'
1559
- } else if (!locale || locale === 'any') {
1560
- for (var key in phones) {
1561
- // istanbul ignore else
1562
- if (phones.hasOwnProperty(key)) {
1563
- var phone = phones[key];
1564
-
1565
- if (phone.test(str)) {
1566
- return true;
1567
- }
1568
- }
1569
- }
1570
-
1571
- return false;
1572
- }
1573
-
1574
- throw new Error("Invalid locale '".concat(locale, "'"));
1575
- }
1576
- var locales$1 = Object.keys(phones);
1577
-
1578
- /**
1579
- * Reference:
1580
- * https://en.wikipedia.org/ -- Wikipedia
1581
- * https://docs.microsoft.com/en-us/microsoft-365/compliance/eu-passport-number -- EU Passport Number
1582
- * https://countrycode.org/ -- Country Codes
1583
- */
1584
-
1585
- var passportRegexByCountryCode = {
1586
- AM: /^[A-Z]{2}\d{7}$/,
1587
- // ARMENIA
1588
- AR: /^[A-Z]{3}\d{6}$/,
1589
- // ARGENTINA
1590
- AT: /^[A-Z]\d{7}$/,
1591
- // AUSTRIA
1592
- AU: /^[A-Z]\d{7}$/,
1593
- // AUSTRALIA
1594
- BE: /^[A-Z]{2}\d{6}$/,
1595
- // BELGIUM
1596
- BG: /^\d{9}$/,
1597
- // BULGARIA
1598
- CA: /^[A-Z]{2}\d{6}$/,
1599
- // CANADA
1600
- CH: /^[A-Z]\d{7}$/,
1601
- // SWITZERLAND
1602
- CN: /^[GE]\d{8}$/,
1603
- // CHINA [G=Ordinary, E=Electronic] followed by 8-digits
1604
- CY: /^[A-Z](\d{6}|\d{8})$/,
1605
- // CYPRUS
1606
- CZ: /^\d{8}$/,
1607
- // CZECH REPUBLIC
1608
- DE: /^[CFGHJKLMNPRTVWXYZ0-9]{9}$/,
1609
- // GERMANY
1610
- DK: /^\d{9}$/,
1611
- // DENMARK
1612
- DZ: /^\d{9}$/,
1613
- // ALGERIA
1614
- EE: /^([A-Z]\d{7}|[A-Z]{2}\d{7})$/,
1615
- // ESTONIA (K followed by 7-digits), e-passports have 2 UPPERCASE followed by 7 digits
1616
- ES: /^[A-Z0-9]{2}([A-Z0-9]?)\d{6}$/,
1617
- // SPAIN
1618
- FI: /^[A-Z]{2}\d{7}$/,
1619
- // FINLAND
1620
- FR: /^\d{2}[A-Z]{2}\d{5}$/,
1621
- // FRANCE
1622
- GB: /^\d{9}$/,
1623
- // UNITED KINGDOM
1624
- GR: /^[A-Z]{2}\d{7}$/,
1625
- // GREECE
1626
- HR: /^\d{9}$/,
1627
- // CROATIA
1628
- HU: /^[A-Z]{2}(\d{6}|\d{7})$/,
1629
- // HUNGARY
1630
- IE: /^[A-Z0-9]{2}\d{7}$/,
1631
- // IRELAND
1632
- IN: /^[A-Z]{1}-?\d{7}$/,
1633
- // INDIA
1634
- IS: /^(A)\d{7}$/,
1635
- // ICELAND
1636
- IT: /^[A-Z0-9]{2}\d{7}$/,
1637
- // ITALY
1638
- JP: /^[A-Z]{2}\d{7}$/,
1639
- // JAPAN
1640
- KR: /^[MS]\d{8}$/,
1641
- // SOUTH KOREA, REPUBLIC OF KOREA, [S=PS Passports, M=PM Passports]
1642
- LT: /^[A-Z0-9]{8}$/,
1643
- // LITHUANIA
1644
- LU: /^[A-Z0-9]{8}$/,
1645
- // LUXEMBURG
1646
- LV: /^[A-Z0-9]{2}\d{7}$/,
1647
- // LATVIA
1648
- MT: /^\d{7}$/,
1649
- // MALTA
1650
- NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/,
1651
- // NETHERLANDS
1652
- PO: /^[A-Z]{2}\d{7}$/,
1653
- // POLAND
1654
- PT: /^[A-Z]\d{6}$/,
1655
- // PORTUGAL
1656
- RO: /^\d{8,9}$/,
1657
- // ROMANIA
1658
- SE: /^\d{8}$/,
1659
- // SWEDEN
1660
- SL: /^(P)[A-Z]\d{7}$/,
1661
- // SLOVANIA
1662
- SK: /^[0-9A-Z]\d{7}$/,
1663
- // SLOVAKIA
1664
- TR: /^[A-Z]\d{8}$/,
1665
- // TURKEY
1666
- UA: /^[A-Z]{2}\d{6}$/,
1667
- // UKRAINE
1668
- US: /^\d{9}$/ // UNITED STATES
1669
-
1670
- };
1671
- /**
1672
- * Check if str is a valid passport number
1673
- * relative to provided ISO Country Code.
1674
- *
1675
- * @param {string} str
1676
- * @param {string} countryCode
1677
- * @return {boolean}
1678
- */
1679
-
1680
- function isPassportNumber(str, countryCode) {
1681
- assertString(str);
1682
- /** Remove All Whitespaces, Convert to UPPERCASE */
1683
-
1684
- var normalizedStr = str.replace(/\s/g, '').toUpperCase();
1685
- return countryCode.toUpperCase() in passportRegexByCountryCode && passportRegexByCountryCode[countryCode].test(normalizedStr);
1686
- }
1687
-
1688
- var threeDigit = /^\d{3}$/;
1689
- var fourDigit = /^\d{4}$/;
1690
- var fiveDigit = /^\d{5}$/;
1691
- var sixDigit = /^\d{6}$/;
1692
- var patterns = {
1693
- AD: /^AD\d{3}$/,
1694
- AT: fourDigit,
1695
- AU: fourDigit,
1696
- AZ: /^AZ\d{4}$/,
1697
- BE: fourDigit,
1698
- BG: fourDigit,
1699
- BR: /^\d{5}-\d{3}$/,
1700
- CA: /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][\s\-]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,
1701
- CH: fourDigit,
1702
- CZ: /^\d{3}\s?\d{2}$/,
1703
- DE: fiveDigit,
1704
- DK: fourDigit,
1705
- DZ: fiveDigit,
1706
- EE: fiveDigit,
1707
- ES: /^(5[0-2]{1}|[0-4]{1}\d{1})\d{3}$/,
1708
- FI: fiveDigit,
1709
- FR: /^\d{2}\s?\d{3}$/,
1710
- GB: /^(gir\s?0aa|[a-z]{1,2}\d[\da-z]?\s?(\d[a-z]{2})?)$/i,
1711
- GR: /^\d{3}\s?\d{2}$/,
1712
- HR: /^([1-5]\d{4}$)/,
1713
- HU: fourDigit,
1714
- ID: fiveDigit,
1715
- IE: /^(?!.*(?:o))[A-z]\d[\dw]\s\w{4}$/i,
1716
- IL: /^(\d{5}|\d{7})$/,
1717
- IN: /^((?!10|29|35|54|55|65|66|86|87|88|89)[1-9][0-9]{5})$/,
1718
- IS: threeDigit,
1719
- IT: fiveDigit,
1720
- JP: /^\d{3}\-\d{4}$/,
1721
- KE: fiveDigit,
1722
- LI: /^(948[5-9]|949[0-7])$/,
1723
- LT: /^LT\-\d{5}$/,
1724
- LU: fourDigit,
1725
- LV: /^LV\-\d{4}$/,
1726
- MX: fiveDigit,
1727
- MT: /^[A-Za-z]{3}\s{0,1}\d{4}$/,
1728
- NL: /^\d{4}\s?[a-z]{2}$/i,
1729
- NO: fourDigit,
1730
- NP: /^(10|21|22|32|33|34|44|45|56|57)\d{3}$|^(977)$/i,
1731
- NZ: fourDigit,
1732
- PL: /^\d{2}\-\d{3}$/,
1733
- PR: /^00[679]\d{2}([ -]\d{4})?$/,
1734
- PT: /^\d{4}\-\d{3}?$/,
1735
- RO: sixDigit,
1736
- RU: sixDigit,
1737
- SA: fiveDigit,
1738
- SE: /^[1-9]\d{2}\s?\d{2}$/,
1739
- SI: fourDigit,
1740
- SK: /^\d{3}\s?\d{2}$/,
1741
- TN: fourDigit,
1742
- TW: /^\d{3}(\d{2})?$/,
1743
- UA: fiveDigit,
1744
- US: /^\d{5}(-\d{4})?$/,
1745
- ZA: fourDigit,
1746
- ZM: fiveDigit
1747
- };
1748
- var locales$2 = Object.keys(patterns);
1749
- function isPostalCode(str, locale) {
1750
- assertString(str);
1751
-
1752
- if (locale in patterns) {
1753
- return patterns[locale].test(str);
1754
- } else if (locale === 'any') {
1755
- for (var key in patterns) {
1756
- // https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
1757
- // istanbul ignore else
1758
- if (patterns.hasOwnProperty(key)) {
1759
- var pattern = patterns[key];
1760
-
1761
- if (pattern.test(str)) {
1762
- return true;
1763
- }
1764
- }
1765
- }
1766
-
1767
- return false;
1768
- }
1769
-
1770
- throw new Error("Invalid locale '".concat(locale, "'"));
1771
- }
1772
-
1773
- /*
1774
- options for isURL method
1775
-
1776
- require_protocol - if set as true isURL will return false if protocol is not present in the URL
1777
- require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option
1778
- protocols - valid protocols can be modified with this option
1779
- require_host - if set as false isURL will not check if host is present in the URL
1780
- allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed
1781
- validate_length - if set as false isURL will skip string length validation (IE maximum is 2083)
1782
-
1783
- */
1784
-
1785
- var default_url_options = {
1786
- protocols: ['http', 'https', 'ftp'],
1787
- require_tld: true,
1788
- require_protocol: false,
1789
- require_host: true,
1790
- require_valid_protocol: true,
1791
- allow_underscores: false,
1792
- allow_trailing_dot: false,
1793
- allow_protocol_relative_urls: false,
1794
- validate_length: true
1795
- };
1796
- var wrapped_ipv6 = /^\[([^\]]+)\](?::([0-9]+))?$/;
1797
-
1798
- function isRegExp(obj) {
1799
- return Object.prototype.toString.call(obj) === '[object RegExp]';
1800
- }
1801
-
1802
- function checkHost(host, matches) {
1803
- for (var i = 0; i < matches.length; i++) {
1804
- var match = matches[i];
1805
-
1806
- if (host === match || isRegExp(match) && match.test(host)) {
1807
- return true;
1808
- }
1809
- }
1810
-
1811
- return false;
1812
- }
1813
-
1814
- function isURL(url, options) {
1815
- assertString(url);
1816
-
1817
- if (!url || /[\s<>]/.test(url)) {
1818
- return false;
1819
- }
1820
-
1821
- if (url.indexOf('mailto:') === 0) {
1822
- return false;
1823
- }
1824
-
1825
- options = merge(options, default_url_options);
1826
-
1827
- if (options.validate_length && url.length >= 2083) {
1828
- return false;
1829
- }
1830
-
1831
- var protocol, auth, host, hostname, port, port_str, split, ipv6;
1832
- split = url.split('#');
1833
- url = split.shift();
1834
- split = url.split('?');
1835
- url = split.shift();
1836
- split = url.split('://');
1837
-
1838
- if (split.length > 1) {
1839
- protocol = split.shift().toLowerCase();
1840
-
1841
- if (options.require_valid_protocol && options.protocols.indexOf(protocol) === -1) {
1842
- return false;
1843
- }
1844
- } else if (options.require_protocol) {
1845
- return false;
1846
- } else if (url.substr(0, 2) === '//') {
1847
- if (!options.allow_protocol_relative_urls) {
1848
- return false;
1849
- }
1850
-
1851
- split[0] = url.substr(2);
1852
- }
1853
-
1854
- url = split.join('://');
1855
-
1856
- if (url === '') {
1857
- return false;
1858
- }
1859
-
1860
- split = url.split('/');
1861
- url = split.shift();
1862
-
1863
- if (url === '' && !options.require_host) {
1864
- return true;
1865
- }
1866
-
1867
- split = url.split('@');
1868
-
1869
- if (split.length > 1) {
1870
- if (options.disallow_auth) {
1871
- return false;
1872
- }
1873
-
1874
- auth = split.shift();
1875
-
1876
- if (auth.indexOf(':') === -1 || auth.indexOf(':') >= 0 && auth.split(':').length > 2) {
1877
- return false;
1878
- }
1879
- }
1880
-
1881
- hostname = split.join('@');
1882
- port_str = null;
1883
- ipv6 = null;
1884
- var ipv6_match = hostname.match(wrapped_ipv6);
1885
-
1886
- if (ipv6_match) {
1887
- host = '';
1888
- ipv6 = ipv6_match[1];
1889
- port_str = ipv6_match[2] || null;
1890
- } else {
1891
- split = hostname.split(':');
1892
- host = split.shift();
1893
-
1894
- if (split.length) {
1895
- port_str = split.join(':');
1896
- }
1897
- }
1898
-
1899
- if (port_str !== null) {
1900
- port = parseInt(port_str, 10);
1901
-
1902
- if (!/^[0-9]+$/.test(port_str) || port <= 0 || port > 65535) {
1903
- return false;
1904
- }
1905
- }
1906
-
1907
- if (!isIP(host) && !isFQDN(host, options) && (!ipv6 || !isIP(ipv6, 6))) {
1908
- return false;
1909
- }
1910
-
1911
- host = host || ipv6;
1912
-
1913
- if (options.host_whitelist && !checkHost(host, options.host_whitelist)) {
1914
- return false;
1915
- }
1916
-
1917
- if (options.host_blacklist && checkHost(host, options.host_blacklist)) {
1918
- return false;
1919
- }
1920
-
1921
- return true;
1922
- }
1923
-
1924
- var rules$1 = {
1925
- isAlphanumeric,
1926
- isCreditCard,
1927
- isCurrency,
1928
- isEmail,
1929
- isIP,
1930
- isIdentityCard,
1931
- isJSON,
1932
- isLocale,
1933
- isMimeType,
1934
- isMobilePhone,
1935
- isPassportNumber,
1936
- isPostalCode,
1937
- isURL
1938
- };
1939
-
1940
- enforce$1.extend(rules$1);
1941
- var index = Object.assign(enforce$1, {
1942
- isAlphanumericLocales: locales,
1943
- isMobilePhoneLocales: locales$1,
1944
- isPostalCodeLocales: locales$2
1945
- });
1946
-
1947
- export default index;