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