quival 0.2.6 → 0.2.8

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.
package/dist/quival.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * quival v0.2.6 (https://github.com/apih/quival)
2
+ * quival v0.2.8 (https://github.com/apih/quival)
3
3
  * (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
4
4
  * Released under the MIT License.
5
5
  */
@@ -7,10 +7,14 @@ var quival = (function (exports) {
7
7
  'use strict';
8
8
 
9
9
  function toCamelCase(string) {
10
- return string.replace(/[-_]/g, ' ').replace(/\s+/, ' ').trim().replace(/(\s\w)/g, match => match[1].toUpperCase());
10
+ return string
11
+ .replace(/[-_]/g, ' ')
12
+ .replace(/\s+/, ' ')
13
+ .trim()
14
+ .replace(/(\s\w)/g, (match) => match[1].toUpperCase());
11
15
  }
12
16
  function toSnakeCase(string) {
13
- return string.replace(/(.)(?=[A-Z])/g, match => match + '_').toLowerCase();
17
+ return string.replace(/(.)(?=[A-Z])/g, (match) => match + '_').toLowerCase();
14
18
  }
15
19
  function escapeRegExp(string) {
16
20
  return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
@@ -26,8 +30,7 @@ var quival = (function (exports) {
26
30
  }
27
31
  return current;
28
32
  }
29
- function flattenObject(obj) {
30
- let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
33
+ function flattenObject(obj, prefix = '') {
31
34
  return Object.keys(obj).reduce((accumulator, key) => {
32
35
  const prefixedKey = prefix ? `${prefix}.${key}` : key;
33
36
  if (typeof obj[key] === 'object' && obj[key] !== null) {
@@ -71,21 +74,24 @@ var quival = (function (exports) {
71
74
  return value;
72
75
  }
73
76
  let match, years, months, days, hours, minutes, seconds, meridiem;
74
- const castToIntegers = value => value && /^\d*$/.test(value) ? parseInt(value) : value;
77
+ const castToIntegers = (value) => (value && /^\d*$/.test(value) ? parseInt(value) : value);
75
78
  if ((match = value.match(/^(\d{1,2})[.\/-](\d{1,2})[.\/-](\d{2,4})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)) !== null) {
76
- [, days, months, years,, hours = 0, minutes = 0,, seconds = 0, meridiem = 'am'] = match.map(castToIntegers);
77
- } else if ((match = value.match(/^(\d{2,4})[.\/-](\d{1,2})[.\/-](\d{1,2})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)) !== null || (match = value.match(/^(\d{4})(\d{2})(\d{2})\s?((\d{2})(\d{2})((\d{2}))?\s?(am|pm)?)?/i)) !== null) {
78
- [, years, months, days,, hours = 0, minutes = 0,, seconds = 0, meridiem = 'am'] = match.map(castToIntegers);
79
- } else if (match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{4})[.\/-](\d{2})[.\/-](\d{2})/i)) {
80
- [, hours, minutes,, seconds, meridiem = 'am', years, months, days] = match.map(castToIntegers);
81
- } else if (match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{2})[.\/-](\d{2})[.\/-](\d{4})/i)) {
82
- [, hours, minutes,, seconds, meridiem = 'am', days, months, years] = match.map(castToIntegers);
83
- } else if (match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?/i)) {
79
+ [, days, months, years, , hours = 0, minutes = 0, , seconds = 0, meridiem = 'am'] = match.map(castToIntegers);
80
+ } else if (
81
+ (match = value.match(/^(\d{2,4})[.\/-](\d{1,2})[.\/-](\d{1,2})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)) !== null ||
82
+ (match = value.match(/^(\d{4})(\d{2})(\d{2})\s?((\d{2})(\d{2})((\d{2}))?\s?(am|pm)?)?/i)) !== null
83
+ ) {
84
+ [, years, months, days, , hours = 0, minutes = 0, , seconds = 0, meridiem = 'am'] = match.map(castToIntegers);
85
+ } else if ((match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{4})[.\/-](\d{2})[.\/-](\d{2})/i))) {
86
+ [, hours, minutes, , seconds, meridiem = 'am', years, months, days] = match.map(castToIntegers);
87
+ } else if ((match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{2})[.\/-](\d{2})[.\/-](\d{4})/i))) {
88
+ [, hours, minutes, , seconds, meridiem = 'am', days, months, years] = match.map(castToIntegers);
89
+ } else if ((match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?/i))) {
84
90
  const current = new Date();
85
91
  years = current.getFullYear();
86
92
  months = current.getMonth() + 1;
87
93
  days = current.getDate();
88
- [, hours = 0, minutes = 0,, seconds = 0, meridiem = 'am'] = match.map(castToIntegers);
94
+ [, hours = 0, minutes = 0, , seconds = 0, meridiem = 'am'] = match.map(castToIntegers);
89
95
  } else {
90
96
  return new Date(value);
91
97
  }
@@ -116,7 +122,7 @@ var quival = (function (exports) {
116
122
  i: '(\\d{2})',
117
123
  s: '(\\d{2})',
118
124
  A: '(AM|PM)',
119
- a: '(am|pm)'
125
+ a: '(am|pm)',
120
126
  };
121
127
  let pattern = '^';
122
128
  let indices = {
@@ -126,7 +132,7 @@ var quival = (function (exports) {
126
132
  hours: -1,
127
133
  minutes: -1,
128
134
  seconds: -1,
129
- meridiem: -1
135
+ meridiem: -1,
130
136
  };
131
137
  let index = 1;
132
138
  for (const char of format) {
@@ -156,7 +162,7 @@ var quival = (function (exports) {
156
162
  if (match === null) {
157
163
  return new Date('');
158
164
  }
159
- match = match.map(value => value && /^\d*$/.test(value) ? parseInt(value) : value);
165
+ match = match.map((value) => (value && /^\d*$/.test(value) ? parseInt(value) : value));
160
166
  const current = new Date();
161
167
  let years = match[indices.years];
162
168
  let months = match[indices.months];
@@ -205,13 +211,13 @@ var quival = (function (exports) {
205
211
  }
206
212
 
207
213
  class Checkers {
208
- validator;
209
- #distinctCache = {};
210
- #imageCache = {};
214
+ #distinctCache;
215
+ #imageCache;
211
216
  constructor(validator) {
217
+ this.#distinctCache = {};
218
+ this.#imageCache = {};
212
219
  this.validator = validator;
213
220
  }
214
-
215
221
  // Internal helpers
216
222
  clearCaches() {
217
223
  this.#distinctCache = {};
@@ -219,7 +225,7 @@ var quival = (function (exports) {
219
225
  }
220
226
  isDependent(parameters) {
221
227
  const other = this.validator.getValue(parameters[0]);
222
- return parameters.slice(1).some(value => value == other);
228
+ return parameters.slice(1).some((value) => value == other);
223
229
  }
224
230
  collectRequiredsThenTest(attribute, value, parameters, callback) {
225
231
  let result = [];
@@ -241,8 +247,7 @@ var quival = (function (exports) {
241
247
  }
242
248
  return true;
243
249
  }
244
- testStringUsingRegex(attribute, value, asciiRegex, unicodeRegex) {
245
- let isAscii = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
250
+ testStringUsingRegex(attribute, value, asciiRegex, unicodeRegex, isAscii = false) {
246
251
  if (typeof value !== 'string' && typeof value !== 'number') {
247
252
  return false;
248
253
  }
@@ -291,7 +296,6 @@ var quival = (function (exports) {
291
296
  }
292
297
  return callback(value.getTime(), otherValue.getTime());
293
298
  }
294
-
295
299
  // Type
296
300
  checkArray(attribute, value, parameters) {
297
301
  if (!(Array.isArray(value) || isPlainObject(value))) {
@@ -306,6 +310,9 @@ var quival = (function (exports) {
306
310
  }
307
311
  return true;
308
312
  }
313
+ checkList(attribute, value, parameters) {
314
+ return Array.isArray(value);
315
+ }
309
316
  checkBoolean(attribute, value, parameters) {
310
317
  return [true, false, 0, 1, '0', '1'].includes(value);
311
318
  }
@@ -324,7 +331,6 @@ var quival = (function (exports) {
324
331
  checkString(attribute, value, parameters) {
325
332
  return typeof value === 'string';
326
333
  }
327
-
328
334
  // Numeric
329
335
  checkDecimal(attribute, value, parameters) {
330
336
  if (!this.checkNumeric(attribute, value)) {
@@ -351,7 +357,6 @@ var quival = (function (exports) {
351
357
  }
352
358
  return numerator % denominator === 0;
353
359
  }
354
-
355
360
  // Agreement
356
361
  checkAccepted(attribute, value, parameters) {
357
362
  return ['yes', 'on', '1', 1, true, 'true'].includes(value);
@@ -371,7 +376,6 @@ var quival = (function (exports) {
371
376
  }
372
377
  return true;
373
378
  }
374
-
375
379
  // Existence
376
380
  checkRequired(attribute, value, parameters) {
377
381
  if (isEmpty(value)) {
@@ -415,16 +419,16 @@ var quival = (function (exports) {
415
419
  return true;
416
420
  }
417
421
  checkRequiredWith(attribute, value, parameters) {
418
- return this.collectRequiredsThenTest(attribute, value, parameters, result => result.includes(true));
422
+ return this.collectRequiredsThenTest(attribute, value, parameters, (result) => result.includes(true));
419
423
  }
420
424
  checkRequiredWithAll(attribute, value, parameters) {
421
- return this.collectRequiredsThenTest(attribute, value, parameters, result => !result.includes(false));
425
+ return this.collectRequiredsThenTest(attribute, value, parameters, (result) => !result.includes(false));
422
426
  }
423
427
  checkRequiredWithout(attribute, value, parameters) {
424
- return this.collectRequiredsThenTest(attribute, value, parameters, result => result.includes(false));
428
+ return this.collectRequiredsThenTest(attribute, value, parameters, (result) => result.includes(false));
425
429
  }
426
430
  checkRequiredWithoutAll(attribute, value, parameters) {
427
- return this.collectRequiredsThenTest(attribute, value, parameters, result => !result.includes(true));
431
+ return this.collectRequiredsThenTest(attribute, value, parameters, (result) => !result.includes(true));
428
432
  }
429
433
  checkFilled(attribute, value, parameters) {
430
434
  if (typeof value !== 'undefined') {
@@ -435,7 +439,6 @@ var quival = (function (exports) {
435
439
  checkPresent(attribute, value, parameters) {
436
440
  return typeof value !== 'undefined';
437
441
  }
438
-
439
442
  // Missing
440
443
  checkMissing(attribute, value, parameters) {
441
444
  return !this.validator.hasAttribute(attribute);
@@ -453,12 +456,11 @@ var quival = (function (exports) {
453
456
  return true;
454
457
  }
455
458
  checkMissingWith(attribute, value, parameters) {
456
- return this.collectMissingsThenTest(attribute, value, parameters, result => result.includes(false));
459
+ return this.collectMissingsThenTest(attribute, value, parameters, (result) => result.includes(false));
457
460
  }
458
461
  checkMissingWithAll(attribute, value, parameters) {
459
- return this.collectMissingsThenTest(attribute, value, parameters, result => !result.includes(true));
462
+ return this.collectMissingsThenTest(attribute, value, parameters, (result) => !result.includes(true));
460
463
  }
461
-
462
464
  // Prohibition
463
465
  checkProhibited(attribute, value, parameters) {
464
466
  return !this.checkRequired(attribute, value);
@@ -485,7 +487,6 @@ var quival = (function (exports) {
485
487
  }
486
488
  return true;
487
489
  }
488
-
489
490
  // Size
490
491
  checkSize(attribute, value, parameters) {
491
492
  return this.validator.getSize(attribute, value) === parseFloat(parameters[0]);
@@ -499,10 +500,8 @@ var quival = (function (exports) {
499
500
  checkBetween(attribute, value, parameters) {
500
501
  return this.checkMin(attribute, value, [parameters[0]]) && this.checkMax(attribute, value, [parameters[1]]);
501
502
  }
502
-
503
503
  // Digits
504
- checkDigits(attribute, value, parameters) {
505
- let callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : (length, value) => length === value;
504
+ checkDigits(attribute, value, parameters, callback = (length, value) => length === value) {
506
505
  value = String(value ?? '');
507
506
  if (!isDigits(value)) {
508
507
  return false;
@@ -518,7 +517,6 @@ var quival = (function (exports) {
518
517
  checkDigitsBetween(attribute, value, parameters) {
519
518
  return this.checkDigits(attribute, value, parameters, (length, value1, value2) => length >= value1 && length <= value2);
520
519
  }
521
-
522
520
  // String
523
521
  checkAlpha(attribute, value, parameters) {
524
522
  return this.testStringUsingRegex(attribute, value, /^[a-z]+$/i, /^[\p{L}\p{M}]+$/u, parameters.includes('ascii'));
@@ -532,8 +530,7 @@ var quival = (function (exports) {
532
530
  checkAscii(attribute, value, parameters) {
533
531
  return !/[^\x09\x10\x13\x0A\x0D\x20-\x7E]/.test(value);
534
532
  }
535
- checkRegex(attribute, value, parameters) {
536
- let invert = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
533
+ checkRegex(attribute, value, parameters, invert = false) {
537
534
  if (!(typeof value === 'string' || isNumeric(value))) {
538
535
  return false;
539
536
  }
@@ -543,7 +540,11 @@ var quival = (function (exports) {
543
540
  throw new Error(`Invalid regular expression pattern: ${expression}`);
544
541
  }
545
542
  if (flags.includes('u')) {
546
- pattern = pattern.replace(/\\A/g, '^').replace(/\\z/gi, '$').replace(/\\([pP])([CLMNPSZ])/g, '\\$1{$2}').replace(/\\\x\{([0-9a-f]+)\}/g, '\\u{$1}');
543
+ pattern = pattern
544
+ .replace(/\\A/g, '^')
545
+ .replace(/\\z/gi, '$')
546
+ .replace(/\\([pP])([CLMNPSZ])/g, '\\$1{$2}')
547
+ .replace(/\\\x\{([0-9a-f]+)\}/g, '\\u{$1}');
547
548
  }
548
549
  const result = new RegExp(pattern, flags).test(value);
549
550
  return invert ? !result : result;
@@ -581,7 +582,6 @@ var quival = (function (exports) {
581
582
  checkDoesntEndWith(attribute, value, parameters) {
582
583
  return !this.checkEndsWith(attribute, value, parameters);
583
584
  }
584
-
585
585
  // Compare values
586
586
  checkSame(attribute, value, parameters) {
587
587
  const other = this.validator.getValue(parameters[0]);
@@ -611,7 +611,6 @@ var quival = (function (exports) {
611
611
  checkLte(attribute, value, parameters) {
612
612
  return this.compareValues(attribute, value, parameters, (val1, val2) => val1 <= val2);
613
613
  }
614
-
615
614
  // Dates
616
615
  checkAfter(attribute, value, parameters) {
617
616
  return this.compareDates(attribute, value, parameters, (val1, val2) => val1 > val2);
@@ -644,7 +643,7 @@ var quival = (function (exports) {
644
643
  i: '(\\d{2})',
645
644
  s: '(\\d{2})',
646
645
  A: '(AM|PM)',
647
- a: '(am|pm)'
646
+ a: '(am|pm)',
648
647
  };
649
648
  let pattern = '^';
650
649
  for (const char of format) {
@@ -657,7 +656,6 @@ var quival = (function (exports) {
657
656
  pattern += '$';
658
657
  return new RegExp(pattern).test(value);
659
658
  }
660
-
661
659
  // Array / Object
662
660
  checkDistinct(attribute, value, parameters) {
663
661
  const unparsed = this.validator.getPrimaryAttribute(attribute);
@@ -697,14 +695,14 @@ var quival = (function (exports) {
697
695
  return false;
698
696
  }
699
697
  const data = this.validator.getValue(unparsed.split('.*')[0]) ?? {};
700
- return Object.values(flattenObject(data)).some(item => item == value);
698
+ return Object.values(flattenObject(data)).some((item) => item == value);
701
699
  }
702
700
  checkIn(attribute, value, parameters) {
703
701
  if (!(this.checkArray(attribute, value) && this.validator.hasRule(attribute, 'array'))) {
704
- return parameters.some(parameter => parameter == value);
702
+ return parameters.some((parameter) => parameter == value);
705
703
  }
706
704
  for (const item of Object.values(value)) {
707
- if (!parameters.some(parameter => parameter == item)) {
705
+ if (!parameters.some((parameter) => parameter == item)) {
708
706
  return false;
709
707
  }
710
708
  }
@@ -713,7 +711,6 @@ var quival = (function (exports) {
713
711
  checkNotIn(attribute, value, parameters) {
714
712
  return !this.checkIn(attribute, value, parameters);
715
713
  }
716
-
717
714
  // File
718
715
  checkMimetypes(attribute, value, parameters) {
719
716
  if (this.checkFile(attribute, value)) {
@@ -727,6 +724,9 @@ var quival = (function (exports) {
727
724
  }
728
725
  return false;
729
726
  }
727
+ checkExtensions(attribute, value, parameters) {
728
+ return this.checkMimes(attribute, value, parameters);
729
+ }
730
730
  async checkImage(attribute, value, parameters) {
731
731
  let result = this.checkMimes(attribute, value, ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg', 'webp']);
732
732
  if (!result || typeof FileReader === 'undefined') {
@@ -734,17 +734,19 @@ var quival = (function (exports) {
734
734
  }
735
735
  await new Promise((resolve, reject) => {
736
736
  const reader = new FileReader();
737
- reader.onload = event => resolve(event.target.result);
737
+ reader.onload = (event) => resolve(event.target.result);
738
738
  reader.onerror = reject;
739
739
  reader.readAsDataURL(value);
740
- }).then(async data => {
741
- const image = new Image();
742
- image.src = data;
743
- await image.decode();
744
- this.#imageCache[attribute] = image;
745
- }).catch(() => {
746
- result = false;
747
- });
740
+ })
741
+ .then(async (data) => {
742
+ const image = new Image();
743
+ image.src = data;
744
+ await image.decode();
745
+ this.#imageCache[attribute] = image;
746
+ })
747
+ .catch(() => {
748
+ result = false;
749
+ });
748
750
  return result;
749
751
  }
750
752
  async checkDimensions(attribute, value, parameters) {
@@ -755,7 +757,7 @@ var quival = (function (exports) {
755
757
  for (const parameter of parameters) {
756
758
  const [key, value] = parameter.split('=', 2);
757
759
  if (key === 'ratio' && value.includes('/')) {
758
- const [numerator, denominator] = value.split('/', 2).map(part => parseFloat(part, 10));
760
+ const [numerator, denominator] = value.split('/', 2).map((part) => parseFloat(part, 10));
759
761
  constraints[key] = numerator / denominator;
760
762
  } else {
761
763
  constraints[key] = parseFloat(value, 10);
@@ -764,7 +766,14 @@ var quival = (function (exports) {
764
766
  const image = this.#imageCache[attribute];
765
767
  const width = image.naturalWidth;
766
768
  const height = image.naturalHeight;
767
- if (constraints.hasOwnProperty('width') && constraints.width !== width || constraints.hasOwnProperty('height') && constraints.height !== height || constraints.hasOwnProperty('min_width') && constraints.min_width > width || constraints.hasOwnProperty('min_height') && constraints.min_height > height || constraints.hasOwnProperty('max_width') && constraints.max_width < width || constraints.hasOwnProperty('max_height') && constraints.max_height < height) {
769
+ if (
770
+ (constraints.hasOwnProperty('width') && constraints.width !== width) ||
771
+ (constraints.hasOwnProperty('height') && constraints.height !== height) ||
772
+ (constraints.hasOwnProperty('min_width') && constraints.min_width > width) ||
773
+ (constraints.hasOwnProperty('min_height') && constraints.min_height > height) ||
774
+ (constraints.hasOwnProperty('max_width') && constraints.max_width < width) ||
775
+ (constraints.hasOwnProperty('max_height') && constraints.max_height < height)
776
+ ) {
768
777
  return false;
769
778
  }
770
779
  if (constraints.hasOwnProperty('ratio')) {
@@ -772,12 +781,13 @@ var quival = (function (exports) {
772
781
  }
773
782
  return true;
774
783
  }
775
-
776
784
  // Miscellaneous
777
785
  checkEmail(attribute, value, parameters) {
778
- const firstRegex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
786
+ const firstRegex =
787
+ /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
779
788
  if (!firstRegex.test(value)) {
780
- const secondRegex = /^((?:[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]|[^\u0000-\u007F])+@(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?(?:\.(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?)+)*$/;
789
+ const secondRegex =
790
+ /^((?:[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]|[^\u0000-\u007F])+@(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?(?:\.(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?)+)*$/;
781
791
  return secondRegex.test(value);
782
792
  }
783
793
  return true;
@@ -790,12 +800,15 @@ var quival = (function (exports) {
790
800
  }
791
801
  return true;
792
802
  }
803
+ checkHexColor(attribute, value, parameters) {
804
+ return /^#(?:(?:[0-9a-f]{3}){1,2}|(?:[0-9a-f]{4}){1,2})$/i.test(value);
805
+ }
793
806
  checkMacAddress(attribute, value, parameters) {
794
807
  value = String(value);
795
808
  const separators = {
796
809
  '-': 2,
797
810
  ':': 2,
798
- '.': 4
811
+ '.': 4,
799
812
  };
800
813
  let separator, digits;
801
814
  for ([separator, digits] of Object.entries(separators)) {
@@ -851,7 +864,7 @@ var quival = (function (exports) {
851
864
  checkTimezone(attribute, value, parameters) {
852
865
  try {
853
866
  Intl.DateTimeFormat(undefined, {
854
- timeZone: value
867
+ timeZone: value,
855
868
  });
856
869
  } catch (error) {
857
870
  if (String(error).toLowerCase().includes('invalid time zone')) {
@@ -877,7 +890,7 @@ var quival = (function (exports) {
877
890
  }
878
891
 
879
892
  class ErrorBag {
880
- #data = {};
893
+ #data;
881
894
  keys() {
882
895
  return Object.keys(this.#data);
883
896
  }
@@ -921,12 +934,12 @@ var quival = (function (exports) {
921
934
  }
922
935
  all() {
923
936
  const result = [];
924
- this.values().forEach(messages => result.push(...messages));
937
+ this.values().forEach((messages) => result.push(...messages));
925
938
  return result;
926
939
  }
927
940
  count() {
928
941
  let count = 0;
929
- this.values().forEach(messages => count += messages.length);
942
+ this.values().forEach((messages) => (count += messages.length));
930
943
  return count;
931
944
  }
932
945
  isEmpty() {
@@ -935,6 +948,9 @@ var quival = (function (exports) {
935
948
  isNotEmpty() {
936
949
  return !this.isEmpty();
937
950
  }
951
+ constructor() {
952
+ this.#data = {};
953
+ }
938
954
  }
939
955
 
940
956
  class Lang {
@@ -965,45 +981,38 @@ var quival = (function (exports) {
965
981
  }
966
982
 
967
983
  class Replacers {
968
- validator;
969
984
  constructor(validator) {
970
985
  this.validator = validator;
971
986
  }
972
987
  replace(message, data) {
973
- Object.entries(data).forEach(_ref => {
974
- let [key, value] = _ref;
975
- return message = message.replaceAll(':' + key, value);
976
- });
988
+ Object.entries(data).forEach(([key, value]) => (message = message.replaceAll(':' + key, value)));
977
989
  return message;
978
990
  }
979
-
980
991
  // Numeric
981
992
  replaceDecimal(message, attribute, rule, parameters) {
982
993
  return this.replace(message, {
983
- decimal: parameters.join('-')
994
+ decimal: parameters.join('-'),
984
995
  });
985
996
  }
986
997
  replaceMultipleOf(message, attribute, rule, parameters) {
987
998
  return this.replace(message, {
988
- value: parameters[0]
999
+ value: parameters[0],
989
1000
  });
990
1001
  }
991
-
992
1002
  // Agreement
993
1003
  replaceAcceptedIf(message, attribute, rule, parameters) {
994
1004
  return this.replace(message, {
995
1005
  other: this.validator.getDisplayableAttribute(parameters[0]),
996
- value: this.validator.getDisplayableValue(parameters[0], this.validator.getValue(parameters[0]))
1006
+ value: this.validator.getDisplayableValue(parameters[0], this.validator.getValue(parameters[0])),
997
1007
  });
998
1008
  }
999
1009
  replaceDeclinedIf(message, attribute, rule, parameters) {
1000
1010
  return this.replaceAcceptedIf(message, attribute, rule, parameters);
1001
1011
  }
1002
-
1003
1012
  // Existence
1004
1013
  replaceRequiredArrayKeys(message, attribute, rule, parameters) {
1005
1014
  return this.replace(message, {
1006
- values: parameters.map(value => this.validator.getDisplayableValue(attribute, value)).join(', ')
1015
+ values: parameters.map((value) => this.validator.getDisplayableValue(attribute, value)).join(', '),
1007
1016
  });
1008
1017
  }
1009
1018
  replaceRequiredIf(message, attribute, rule, parameters) {
@@ -1015,12 +1024,15 @@ var quival = (function (exports) {
1015
1024
  replaceRequiredUnless(message, attribute, rule, parameters) {
1016
1025
  return this.replace(message, {
1017
1026
  other: this.validator.getDisplayableAttribute(parameters[0]),
1018
- values: parameters.slice(1).map(value => this.validator.getDisplayableValue(parameters[0], value)).join(', ')
1027
+ values: parameters
1028
+ .slice(1)
1029
+ .map((value) => this.validator.getDisplayableValue(parameters[0], value))
1030
+ .join(', '),
1019
1031
  });
1020
1032
  }
1021
1033
  replaceRequiredWith(message, attribute, rule, parameters) {
1022
1034
  return this.replace(message, {
1023
- values: parameters.map(value => this.validator.getDisplayableAttribute(value)).join(' / ')
1035
+ values: parameters.map((value) => this.validator.getDisplayableAttribute(value)).join(' / '),
1024
1036
  });
1025
1037
  }
1026
1038
  replaceRequiredWithAll(message, attribute, rule, parameters) {
@@ -1032,14 +1044,13 @@ var quival = (function (exports) {
1032
1044
  replaceRequiredWithoutAll(message, attribute, rule, parameters) {
1033
1045
  return this.replaceRequiredWith(message, attribute, rule, parameters);
1034
1046
  }
1035
-
1036
1047
  // Missing
1037
1048
  replaceMissingIf(message, attribute, rule, parameters) {
1038
1049
  return this.replaceAcceptedIf(message, attribute, rule, parameters);
1039
1050
  }
1040
1051
  replaceMissingUnless(message, attribute, rule, parameters) {
1041
1052
  return this.replace(this.replaceRequiredUnless(message, attribute, rule, parameters), {
1042
- value: this.validator.getDisplayableValue(parameters[0], parameters[1])
1053
+ value: this.validator.getDisplayableValue(parameters[0], parameters[1]),
1043
1054
  });
1044
1055
  }
1045
1056
  replaceMissingWith(message, attribute, rule, parameters) {
@@ -1048,7 +1059,6 @@ var quival = (function (exports) {
1048
1059
  replaceMissingWithAll(message, attribute, rule, parameters) {
1049
1060
  return this.replaceRequiredWith(message, attribute, rule, parameters);
1050
1061
  }
1051
-
1052
1062
  // Prohibition
1053
1063
  replaceProhibitedIf(message, attribute, rule, parameters) {
1054
1064
  return this.replaceAcceptedIf(message, attribute, rule, parameters);
@@ -1058,37 +1068,35 @@ var quival = (function (exports) {
1058
1068
  }
1059
1069
  replaceProhibits(message, attribute, rule, parameters) {
1060
1070
  return this.replace(message, {
1061
- other: parameters.map(value => this.validator.getDisplayableAttribute(value)).join(' / ')
1071
+ other: parameters.map((value) => this.validator.getDisplayableAttribute(value)).join(' / '),
1062
1072
  });
1063
1073
  }
1064
-
1065
1074
  // Size
1066
1075
  replaceSize(message, attribute, rule, parameters) {
1067
1076
  return this.replace(message, {
1068
- size: parameters[0]
1077
+ size: parameters[0],
1069
1078
  });
1070
1079
  }
1071
1080
  replaceMin(message, attribute, rule, parameters) {
1072
1081
  return this.replace(message, {
1073
- min: parameters[0]
1082
+ min: parameters[0],
1074
1083
  });
1075
1084
  }
1076
1085
  replaceMax(message, attribute, rule, parameters) {
1077
1086
  return this.replace(message, {
1078
- max: parameters[0]
1087
+ max: parameters[0],
1079
1088
  });
1080
1089
  }
1081
1090
  replaceBetween(message, attribute, rule, parameters) {
1082
1091
  return this.replace(message, {
1083
1092
  min: parameters[0],
1084
- max: parameters[1]
1093
+ max: parameters[1],
1085
1094
  });
1086
1095
  }
1087
-
1088
1096
  // Digits
1089
1097
  replaceDigits(message, attribute, rule, parameters) {
1090
1098
  return this.replace(message, {
1091
- digits: parameters[0]
1099
+ digits: parameters[0],
1092
1100
  });
1093
1101
  }
1094
1102
  replaceMinDigits(message, attribute, rule, parameters) {
@@ -1100,7 +1108,6 @@ var quival = (function (exports) {
1100
1108
  replaceDigitsBetween(message, attribute, rule, parameters) {
1101
1109
  return this.replaceBetween(message, attribute, rule, parameters);
1102
1110
  }
1103
-
1104
1111
  // String
1105
1112
  replaceStartsWith(message, attribute, rule, parameters) {
1106
1113
  return this.replaceRequiredArrayKeys(message, attribute, rule, parameters);
@@ -1114,7 +1121,6 @@ var quival = (function (exports) {
1114
1121
  replaceDoesntEndWith(message, attribute, rule, parameters) {
1115
1122
  return this.replaceRequiredArrayKeys(message, attribute, rule, parameters);
1116
1123
  }
1117
-
1118
1124
  // Compare values
1119
1125
  replaceSame(message, attribute, rule, parameters) {
1120
1126
  return this.replaceAcceptedIf(message, attribute, rule, parameters);
@@ -1125,7 +1131,7 @@ var quival = (function (exports) {
1125
1131
  replaceGt(message, attribute, rule, parameters) {
1126
1132
  const value = this.validator.getValue(parameters[0]);
1127
1133
  return this.replace(message, {
1128
- value: value ? this.validator.getSize(parameters[0], value) : this.validator.getDisplayableAttribute(parameters[0])
1134
+ value: value ? this.validator.getSize(parameters[0], value) : this.validator.getDisplayableAttribute(parameters[0]),
1129
1135
  });
1130
1136
  }
1131
1137
  replaceGte(message, attribute, rule, parameters) {
@@ -1137,12 +1143,11 @@ var quival = (function (exports) {
1137
1143
  replaceLte(message, attribute, rule, parameters) {
1138
1144
  return this.replaceGt(message, attribute, rule, parameters);
1139
1145
  }
1140
-
1141
1146
  // Dates
1142
1147
  replaceAfter(message, attribute, rule, parameters) {
1143
1148
  const other = parameters[0];
1144
1149
  return this.replace(message, {
1145
- date: this.validator.hasAttribute(other) ? this.validator.getDisplayableAttribute(other) : other
1150
+ date: this.validator.hasAttribute(other) ? this.validator.getDisplayableAttribute(other) : other,
1146
1151
  });
1147
1152
  }
1148
1153
  replaceAfterOrEqual(message, attribute, rule, parameters) {
@@ -1159,10 +1164,9 @@ var quival = (function (exports) {
1159
1164
  }
1160
1165
  replaceDateFormat(message, attribute, rule, parameters) {
1161
1166
  return this.replace(message, {
1162
- format: parameters[0]
1167
+ format: parameters[0],
1163
1168
  });
1164
1169
  }
1165
-
1166
1170
  // Array
1167
1171
  replaceInArray(message, attribute, rule, parameters) {
1168
1172
  return this.replaceAcceptedIf(message, attribute, rule, parameters);
@@ -1173,23 +1177,60 @@ var quival = (function (exports) {
1173
1177
  replaceNotIn(message, attribute, rule, parameters) {
1174
1178
  return this.replaceRequiredArrayKeys(message, attribute, rule, parameters);
1175
1179
  }
1176
-
1177
1180
  // File
1178
1181
  replaceMimetypes(message, attribute, rule, parameters) {
1179
1182
  return this.replace(message, {
1180
- values: parameters.join(', ')
1183
+ values: parameters.join(', '),
1181
1184
  });
1182
1185
  }
1183
1186
  replaceMimes(message, attribute, rule, parameters) {
1184
1187
  return this.replaceMimetypes(message, attribute, rule, parameters);
1185
1188
  }
1189
+ replaceExtensions(message, attribute, rule, parameters) {
1190
+ return this.replaceMimetypes(message, attribute, rule, parameters);
1191
+ }
1186
1192
  }
1187
1193
 
1188
1194
  class Validator {
1189
1195
  static #customCheckers = {};
1190
1196
  static #customReplacers = {};
1191
- static #dummyRules = ['active_url', 'bail', 'current_password', 'enum', 'exclude', 'exclude_if', 'exclude_unless', 'exclude_with', 'exclude_without', 'exists', 'nullable', 'sometimes', 'unique'];
1192
- static #implicitRules = ['accepted', 'accepted_if', 'declined', 'declined_if', 'filled', 'missing', 'missing_if', 'missing_unless', 'missing_with', 'missing_with_all', 'present', 'required', 'required_if', 'required_if_accepted', 'required_unless', 'required_with', 'required_with_all', 'required_without', 'required_without_all'];
1197
+ static #dummyRules = [
1198
+ 'active_url',
1199
+ 'bail',
1200
+ 'can',
1201
+ 'current_password',
1202
+ 'enum',
1203
+ 'exclude',
1204
+ 'exclude_if',
1205
+ 'exclude_unless',
1206
+ 'exclude_with',
1207
+ 'exclude_without',
1208
+ 'exists',
1209
+ 'nullable',
1210
+ 'sometimes',
1211
+ 'unique',
1212
+ ];
1213
+ static #implicitRules = [
1214
+ 'accepted',
1215
+ 'accepted_if',
1216
+ 'declined',
1217
+ 'declined_if',
1218
+ 'filled',
1219
+ 'missing',
1220
+ 'missing_if',
1221
+ 'missing_unless',
1222
+ 'missing_with',
1223
+ 'missing_with_all',
1224
+ 'present',
1225
+ 'required',
1226
+ 'required_if',
1227
+ 'required_if_accepted',
1228
+ 'required_unless',
1229
+ 'required_with',
1230
+ 'required_with_all',
1231
+ 'required_without',
1232
+ 'required_without_all',
1233
+ ];
1193
1234
  #data;
1194
1235
  #rules;
1195
1236
  #customMessages;
@@ -1198,12 +1239,9 @@ var quival = (function (exports) {
1198
1239
  #checkers;
1199
1240
  #replacers;
1200
1241
  #errors;
1201
- #implicitAttributes = {};
1202
- #stopOnFirstFailure = false;
1203
- #alwaysBail = false;
1204
- fileRules = ['file', 'image', 'mimetypes', 'mimes'];
1205
- numericRules = ['decimal', 'numeric', 'integer'];
1206
- sizeRules = ['size', 'between', 'min', 'max', 'gt', 'lt', 'gte', 'lte'];
1242
+ #implicitAttributes;
1243
+ #stopOnFirstFailure;
1244
+ #alwaysBail;
1207
1245
  static setLocale(locale) {
1208
1246
  Lang.locale(locale);
1209
1247
  }
@@ -1226,12 +1264,13 @@ var quival = (function (exports) {
1226
1264
  static addDummyRule(rule) {
1227
1265
  Validator.#dummyRules.push(rule);
1228
1266
  }
1229
- constructor() {
1230
- let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1231
- let rules = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1232
- let messages = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1233
- let attributes = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1234
- let values = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
1267
+ constructor(data = {}, rules = {}, messages = {}, attributes = {}, values = {}) {
1268
+ this.#implicitAttributes = {};
1269
+ this.#stopOnFirstFailure = false;
1270
+ this.#alwaysBail = false;
1271
+ this.fileRules = ['file', 'image', 'mimetypes', 'mimes'];
1272
+ this.numericRules = ['decimal', 'numeric', 'integer'];
1273
+ this.sizeRules = ['size', 'between', 'min', 'max', 'gt', 'lt', 'gte', 'lte'];
1235
1274
  this.setProperties(data, rules, messages, attributes, values);
1236
1275
  this.#checkers = new Checkers(this);
1237
1276
  this.#replacers = new Replacers(this);
@@ -1243,12 +1282,7 @@ var quival = (function (exports) {
1243
1282
  }
1244
1283
  this.#errors = new ErrorBag();
1245
1284
  }
1246
- setProperties() {
1247
- let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1248
- let rules = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1249
- let messages = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1250
- let attributes = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1251
- let values = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
1285
+ setProperties(data = {}, rules = {}, messages = {}, attributes = {}, values = {}) {
1252
1286
  this.#data = data;
1253
1287
  this.#rules = this.parseRules(rules);
1254
1288
  this.#customMessages = messages;
@@ -1280,13 +1314,11 @@ var quival = (function (exports) {
1280
1314
  this.#implicitAttributes[implicitAttribute] = attribute;
1281
1315
  return this;
1282
1316
  }
1283
- stopOnFirstFailure() {
1284
- let flag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1317
+ stopOnFirstFailure(flag = true) {
1285
1318
  this.#stopOnFirstFailure = flag;
1286
1319
  return this;
1287
1320
  }
1288
- alwaysBail() {
1289
- let flag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1321
+ alwaysBail(flag = true) {
1290
1322
  this.#alwaysBail = flag;
1291
1323
  return this;
1292
1324
  }
@@ -1314,12 +1346,11 @@ var quival = (function (exports) {
1314
1346
  if (!(Array.isArray(data) || isPlainObject(data))) {
1315
1347
  return [attribute];
1316
1348
  }
1317
- Object.entries(data).forEach(_ref => {
1318
- let [key, value] = _ref;
1349
+ Object.entries(data).forEach(([key, value]) => {
1319
1350
  const implicitAttribute = `${parentPath}.${key}.${childPath}`.replace(/\.$/, '');
1320
1351
  const implicitAttributes = implicitAttribute.includes('*') ? this.parseWildcardAttribute(implicitAttribute) : [implicitAttribute];
1321
1352
  attributes.push(...implicitAttributes);
1322
- implicitAttributes.forEach(value => this.#implicitAttributes[value] = attribute);
1353
+ implicitAttributes.forEach((value) => (this.#implicitAttributes[value] = attribute));
1323
1354
  });
1324
1355
  return attributes;
1325
1356
  }
@@ -1356,7 +1387,10 @@ var quival = (function (exports) {
1356
1387
  if (rule === '') {
1357
1388
  continue;
1358
1389
  }
1359
- if (!Validator.#implicitRules.includes(rule) && (typeof value === 'undefined' || typeof value === 'string' && value.trim() === '' || isNullable && value === null)) {
1390
+ if (
1391
+ !Validator.#implicitRules.includes(rule) &&
1392
+ (typeof value === 'undefined' || (typeof value === 'string' && value.trim() === '') || (isNullable && value === null))
1393
+ ) {
1360
1394
  continue;
1361
1395
  }
1362
1396
  let result, status, message;
@@ -1371,10 +1405,7 @@ var quival = (function (exports) {
1371
1405
  if (typeof result === 'boolean') {
1372
1406
  status = result;
1373
1407
  } else {
1374
- ({
1375
- status,
1376
- message
1377
- } = result);
1408
+ ({ status, message } = result);
1378
1409
  }
1379
1410
  if (!status) {
1380
1411
  hasError = true;
@@ -1442,7 +1473,7 @@ var quival = (function (exports) {
1442
1473
  attribute: attributeName,
1443
1474
  ATTRIBUTE: attributeName.toLocaleUpperCase(),
1444
1475
  Attribute: attributeName.charAt(0).toLocaleUpperCase() + attributeName.substring(1),
1445
- input: this.getDisplayableValue(attribute, value)
1476
+ input: this.getDisplayableValue(attribute, value),
1446
1477
  };
1447
1478
  for (const [key, value] of Object.entries(data)) {
1448
1479
  message = message.replaceAll(':' + key, value);
@@ -1538,5 +1569,4 @@ var quival = (function (exports) {
1538
1569
  exports.Validator = Validator;
1539
1570
 
1540
1571
  return exports;
1541
-
1542
1572
  })({});