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