quival 0.2.8 → 0.3.0

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/README.md CHANGED
@@ -29,7 +29,7 @@ There are 2 ways to start using `quival` in your project.
29
29
  Get the script from [jsDelivr CDN page](https://www.jsdelivr.com/package/npm/quival) and include it in your HTML page.
30
30
 
31
31
  ```html
32
- <script src="https://cdn.jsdelivr.net/npm/quival@0.2.x/dist/quival.min.js"></script>
32
+ <script src="https://cdn.jsdelivr.net/npm/quival@0.3.x/dist/quival.min.js"></script>
33
33
  ```
34
34
 
35
35
  Extract `Validator` class from `quival` global variable, and you are good to go.
@@ -129,14 +129,7 @@ const validator = new Validator(data, rules, customMessages, customAttributes, c
129
129
  // Perform validation
130
130
  validator
131
131
  .validate()
132
- .then(() => {
133
- console.log('Successful!');
134
- })
135
- .catch((errorBag) => {
136
- if (errorBag instanceof Error) {
137
- throw errorBag;
138
- }
139
-
132
+ .then((errorBag) => {
140
133
  console.log(errorBag.messages());
141
134
  });
142
135
  ```
@@ -190,6 +183,7 @@ The produced error messages for the code snippet above.
190
183
  The following rules are not implemented and will always pass the validation if used.
191
184
 
192
185
  - `active_url`
186
+ - `can`
193
187
  - `current_password`
194
188
  - `exclude`
195
189
  - `exclude_if`
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * quival v0.2.8 (https://github.com/apih/quival)
2
+ * quival v0.3.0 (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
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * quival v0.2.8 (https://github.com/apih/quival)
2
+ * quival v0.3.0 (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
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * quival v0.2.8 (https://github.com/apih/quival)
2
+ * quival v0.3.0 (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
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * quival v0.2.8 (https://github.com/apih/quival)
2
+ * quival v0.3.0 (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
  */
package/dist/quival.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * quival v0.2.8 (https://github.com/apih/quival)
2
+ * quival v0.3.0 (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
  */
@@ -23,7 +23,7 @@ var quival = (function (exports) {
23
23
  const keys = path.split('.');
24
24
  let current = obj;
25
25
  for (const key of keys) {
26
- if (!current.hasOwnProperty(key)) {
26
+ if (!Object.hasOwn(current, key)) {
27
27
  return defaultValue;
28
28
  }
29
29
  current = current[key];
@@ -136,7 +136,7 @@ var quival = (function (exports) {
136
136
  };
137
137
  let index = 1;
138
138
  for (const char of format) {
139
- if (formats.hasOwnProperty(char)) {
139
+ if (Object.hasOwn(formats, char)) {
140
140
  pattern += formats[char];
141
141
  if (['Y', 'y'].indexOf(char) !== -1) {
142
142
  indices.years = index++;
@@ -279,7 +279,7 @@ var quival = (function (exports) {
279
279
  }
280
280
  compareDates(attribute, value, parameters, callback) {
281
281
  const rule = this.validator.getRule(attribute);
282
- value = rule.hasOwnProperty('date_format') ? parseDateByFormat(value, rule.date_format[0]) : parseDate(value);
282
+ value = Object.hasOwn(rule, 'date_format') ? parseDateByFormat(value, rule.date_format[0]) : parseDate(value);
283
283
  if (!isValidDate(value)) {
284
284
  return false;
285
285
  }
@@ -289,7 +289,7 @@ var quival = (function (exports) {
289
289
  otherValue = parseDate(other);
290
290
  } else {
291
291
  const otherRule = this.validator.getRule(other);
292
- otherValue = otherRule.hasOwnProperty('date_format') ? parseDateByFormat(otherValue, otherRule.date_format[0]) : parseDate(otherValue);
292
+ otherValue = Object.hasOwn(otherRule, 'date_format') ? parseDateByFormat(otherValue, otherRule.date_format[0]) : parseDate(otherValue);
293
293
  }
294
294
  if (!isValidDate(otherValue)) {
295
295
  return false;
@@ -647,7 +647,7 @@ var quival = (function (exports) {
647
647
  };
648
648
  let pattern = '^';
649
649
  for (const char of format) {
650
- if (formats.hasOwnProperty(char)) {
650
+ if (Object.hasOwn(formats, char)) {
651
651
  pattern += formats[char];
652
652
  } else {
653
653
  pattern += '\\' + char;
@@ -665,7 +665,7 @@ var quival = (function (exports) {
665
665
  const index = unparsed.indexOf('*');
666
666
  const parentPath = unparsed.substring(0, index - 1);
667
667
  let stringified;
668
- if (this.#distinctCache.hasOwnProperty(parentPath)) {
668
+ if (Object.hasOwn(this.#distinctCache, parentPath)) {
669
669
  stringified = this.#distinctCache[parentPath];
670
670
  } else {
671
671
  stringified = JSON.stringify(flattenObject(this.validator.getValue(parentPath) ?? {}));
@@ -750,7 +750,7 @@ var quival = (function (exports) {
750
750
  return result;
751
751
  }
752
752
  async checkDimensions(attribute, value, parameters) {
753
- if (!this.checkImage(attribute, value) || !this.#imageCache.hasOwnProperty(attribute)) {
753
+ if (!this.checkImage(attribute, value) || !Object.hasOwn(this.#imageCache, attribute)) {
754
754
  return false;
755
755
  }
756
756
  const constraints = {};
@@ -767,16 +767,16 @@ var quival = (function (exports) {
767
767
  const width = image.naturalWidth;
768
768
  const height = image.naturalHeight;
769
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)
770
+ (Object.hasOwn(constraints, 'width') && constraints.width !== width) ||
771
+ (Object.hasOwn(constraints, 'height') && constraints.height !== height) ||
772
+ (Object.hasOwn(constraints, 'min_width') && constraints.min_width > width) ||
773
+ (Object.hasOwn(constraints, 'min_height') && constraints.min_height > height) ||
774
+ (Object.hasOwn(constraints, 'max_width') && constraints.max_width < width) ||
775
+ (Object.hasOwn(constraints, 'max_height') && constraints.max_height < height)
776
776
  ) {
777
777
  return false;
778
778
  }
779
- if (constraints.hasOwnProperty('ratio')) {
779
+ if (Object.hasOwn(constraints, 'ratio')) {
780
780
  return Math.abs(constraints.ratio - width / height) <= 1 / (Math.max(width, height) + 1);
781
781
  }
782
782
  return true;
@@ -901,7 +901,7 @@ var quival = (function (exports) {
901
901
  return Object.entries(this.#data);
902
902
  }
903
903
  add(key, message) {
904
- if (this.#data.hasOwnProperty(key)) {
904
+ if (Object.hasOwn(this.#data, key)) {
905
905
  this.#data[key].push(message);
906
906
  } else {
907
907
  this.#data[key] = [message];
@@ -909,7 +909,7 @@ var quival = (function (exports) {
909
909
  }
910
910
  get(key) {
911
911
  if (!key.includes('*')) {
912
- return this.#data.hasOwnProperty(key) ? this.#data[key] : {};
912
+ return Object.hasOwn(this.#data, key) ? this.#data[key] : {};
913
913
  }
914
914
  const pattern = new RegExp('^' + key.replaceAll('*', '.*?') + '$');
915
915
  const result = {};
@@ -948,6 +948,15 @@ var quival = (function (exports) {
948
948
  isNotEmpty() {
949
949
  return !this.isEmpty();
950
950
  }
951
+ sortByKeys(keys) {
952
+ const data = {};
953
+ for (const key of keys) {
954
+ if (Object.hasOwn(this.#data, key)) {
955
+ data[key] = this.#data[key];
956
+ }
957
+ }
958
+ this.#data = data;
959
+ }
951
960
  constructor() {
952
961
  this.#data = {};
953
962
  }
@@ -1375,63 +1384,66 @@ var quival = (function (exports) {
1375
1384
  async validate() {
1376
1385
  this.#checkers.clearCaches();
1377
1386
  this.#errors = new ErrorBag();
1387
+ const tasks = [];
1378
1388
  for (const [attribute, rules] of Object.entries(this.#rules)) {
1379
1389
  let value = this.getValue(attribute);
1380
- if (rules.hasOwnProperty('sometimes') && typeof value === 'undefined') {
1390
+ if (Object.hasOwn(rules, 'sometimes') && typeof value === 'undefined') {
1381
1391
  continue;
1382
1392
  }
1383
- const doBail = this.#alwaysBail || rules.hasOwnProperty('bail');
1384
- const isNullable = rules.hasOwnProperty('nullable');
1385
- let hasError = false;
1386
- for (const [rule, parameters] of Object.entries(rules)) {
1387
- if (rule === '') {
1388
- continue;
1389
- }
1390
- if (
1391
- !Validator.#implicitRules.includes(rule) &&
1392
- (typeof value === 'undefined' || (typeof value === 'string' && value.trim() === '') || (isNullable && value === null))
1393
- ) {
1394
- continue;
1395
- }
1396
- let result, status, message;
1397
- const camelRule = toCamelCase('check_' + rule);
1398
- if (typeof this.#checkers[camelRule] === 'function') {
1399
- result = await this.#checkers[camelRule](attribute, value, parameters);
1400
- } else if (Validator.#dummyRules.includes(rule)) {
1401
- result = true;
1402
- } else {
1403
- throw new Error(`Invalid validation rule: ${rule}`);
1404
- }
1405
- if (typeof result === 'boolean') {
1406
- status = result;
1407
- } else {
1408
- ({ status, message } = result);
1409
- }
1410
- if (!status) {
1411
- hasError = true;
1412
- message = isEmpty(message) ? this.getMessage(attribute, rule) : message;
1413
- message = this.makeReplacements(message, attribute, rule, parameters);
1414
- this.#errors.add(attribute, message);
1415
- if (doBail || Validator.#implicitRules.includes(rule)) {
1416
- break;
1393
+ tasks.push(async () => {
1394
+ const doBail = this.#alwaysBail || Object.hasOwn(rules, 'bail');
1395
+ const isNullable = Object.hasOwn(rules, 'nullable');
1396
+ let noError = true;
1397
+ for (const [rule, parameters] of Object.entries(rules)) {
1398
+ if (rule === '') {
1399
+ continue;
1400
+ }
1401
+ if (
1402
+ !Validator.#implicitRules.includes(rule) &&
1403
+ (typeof value === 'undefined' || (typeof value === 'string' && value.trim() === '') || (isNullable && value === null))
1404
+ ) {
1405
+ continue;
1406
+ }
1407
+ let result, success, message;
1408
+ const camelRule = toCamelCase('check_' + rule);
1409
+ if (typeof this.#checkers[camelRule] === 'function') {
1410
+ result = await this.#checkers[camelRule](attribute, value, parameters);
1411
+ } else if (Validator.#dummyRules.includes(rule)) {
1412
+ result = true;
1413
+ } else {
1414
+ throw new Error(`Invalid validation rule: ${rule}`);
1415
+ }
1416
+ if (typeof result === 'boolean') {
1417
+ success = result;
1418
+ } else {
1419
+ ({ success, message } = result);
1420
+ }
1421
+ if (!success) {
1422
+ noError = false;
1423
+ message = isEmpty(message) ? this.getMessage(attribute, rule) : message;
1424
+ message = this.makeReplacements(message, attribute, rule, parameters);
1425
+ this.#errors.add(attribute, message);
1426
+ if (doBail || Validator.#implicitRules.includes(rule)) {
1427
+ break;
1428
+ }
1417
1429
  }
1418
1430
  }
1419
- }
1420
- if (this.#stopOnFirstFailure && hasError) {
1421
- break;
1422
- }
1431
+ return noError;
1432
+ });
1423
1433
  }
1424
- if (this.#errors.isNotEmpty()) {
1425
- throw this.#errors;
1434
+ if (this.#stopOnFirstFailure) {
1435
+ for (const task of tasks) {
1436
+ if (!(await task())) break;
1437
+ }
1438
+ } else {
1439
+ await Promise.allSettled(tasks.map((task) => task()));
1440
+ this.#errors.sortByKeys(Object.keys(this.#rules));
1426
1441
  }
1442
+ return this.#errors;
1427
1443
  }
1428
1444
  async passes() {
1429
- try {
1430
- await this.validate();
1431
- } catch (error) {
1432
- if (error instanceof Error) {
1433
- throw error;
1434
- }
1445
+ await this.validate();
1446
+ if (this.#errors.isNotEmpty()) {
1435
1447
  return false;
1436
1448
  }
1437
1449
  return true;
@@ -1444,7 +1456,7 @@ var quival = (function (exports) {
1444
1456
  attribute = this.getPrimaryAttribute(attribute);
1445
1457
  let message;
1446
1458
  for (const key of [`${attribute}.${rule}`, rule]) {
1447
- if (this.#customMessages.hasOwnProperty(key)) {
1459
+ if (Object.hasOwn(this.#customMessages, key)) {
1448
1460
  message = this.#customMessages[key];
1449
1461
  break;
1450
1462
  }
@@ -1456,7 +1468,7 @@ var quival = (function (exports) {
1456
1468
  key += '.array';
1457
1469
  } else if (value instanceof File || this.hasRule(attribute, this.fileRules)) {
1458
1470
  key += '.file';
1459
- } else if (typeof value === 'number' || this.hasRule(attribute, this.numericRules)) {
1471
+ } else if (isNumeric(value) || this.hasRule(attribute, this.numericRules)) {
1460
1472
  key += '.numeric';
1461
1473
  } else {
1462
1474
  key += '.string';
@@ -1492,13 +1504,13 @@ var quival = (function (exports) {
1492
1504
  getDisplayableAttribute(attribute) {
1493
1505
  const unparsed = this.getPrimaryAttribute(attribute);
1494
1506
  for (const name of [attribute, unparsed]) {
1495
- if (this.#customAttributes.hasOwnProperty(name)) {
1507
+ if (Object.hasOwn(this.#customAttributes, name)) {
1496
1508
  return this.#customAttributes[name];
1497
1509
  } else if (Lang.has(`attributes.${name}`)) {
1498
1510
  return Lang.get(`attributes.${name}`);
1499
1511
  }
1500
1512
  }
1501
- if (this.#implicitAttributes.hasOwnProperty(attribute)) {
1513
+ if (Object.hasOwn(this.#implicitAttributes, attribute)) {
1502
1514
  return attribute;
1503
1515
  }
1504
1516
  return toSnakeCase(attribute).replaceAll('_', ' ');
@@ -1510,7 +1522,7 @@ var quival = (function (exports) {
1510
1522
  return 'empty';
1511
1523
  } else if (typeof value === 'boolean' || this.hasRule(attribute, 'boolean')) {
1512
1524
  return Number(value) ? 'true' : 'false';
1513
- } else if (this.#customValues.hasOwnProperty(path)) {
1525
+ } else if (Object.hasOwn(this.#customValues, path)) {
1514
1526
  return this.#customValues[path];
1515
1527
  } else if (Lang.has(`values.${path}`)) {
1516
1528
  return Lang.get(`values.${path}`);
@@ -1526,7 +1538,7 @@ var quival = (function (exports) {
1526
1538
  return value.size / 1024;
1527
1539
  } else if (isPlainObject(value)) {
1528
1540
  return Object.keys(value).length;
1529
- } else if (value.hasOwnProperty('length')) {
1541
+ } else if (Object.hasOwn(value, 'length')) {
1530
1542
  return value.length;
1531
1543
  }
1532
1544
  return value;
@@ -1538,7 +1550,7 @@ var quival = (function (exports) {
1538
1550
  hasRule(attribute, rules) {
1539
1551
  attribute = this.getPrimaryAttribute(attribute);
1540
1552
  rules = typeof rules === 'string' ? [rules] : rules;
1541
- if (!this.#rules.hasOwnProperty(attribute)) {
1553
+ if (!Object.hasOwn(this.#rules, attribute)) {
1542
1554
  return false;
1543
1555
  }
1544
1556
  for (const rule of rules) {
@@ -1549,7 +1561,7 @@ var quival = (function (exports) {
1549
1561
  return false;
1550
1562
  }
1551
1563
  getPrimaryAttribute(attribute) {
1552
- return this.#implicitAttributes.hasOwnProperty(attribute) ? this.#implicitAttributes[attribute] : attribute;
1564
+ return Object.hasOwn(this.#implicitAttributes, attribute) ? this.#implicitAttributes[attribute] : attribute;
1553
1565
  }
1554
1566
  hasAttribute(attribute) {
1555
1567
  return typeof this.getValue(attribute) !== 'undefined';
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * quival v0.2.8 (https://github.com/apih/quival)
2
+ * quival v0.3.0 (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
  */
6
- var quival=function(e){"use strict";function t(e){return e.replace(/[-_]/g," ").replace(/\s+/," ").trim().replace(/(\s\w)/g,(e=>e[1].toUpperCase()))}function r(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function s(e,t=""){return Object.keys(e).reduce(((r,i)=>{const a=t?`${t}.${i}`:i;return"object"==typeof e[i]&&null!==e[i]?Object.assign(r,s(e[i],a)):r[a]=e[i],r}),{})}function i(e){const t=[];let r="",s=!1;for(let i=0;i<e.length;i++){const a=e[i];'"'===a?s&&'"'===e[i+1]?(r+='"',i++):(s=!s,s&&(r=r.trim())):","!==a||s?r+=a:(t.push(r),r="")}return t.push(r),t}function a(e){if(n(e)||"string"!=typeof e)return new Date("");if(e instanceof Date)return e;let t,r,s,i,a,c,u,h;const l=e=>e&&/^\d*$/.test(e)?parseInt(e):e;if(null!==(t=e.match(/^(\d{1,2})[.\/-](\d{1,2})[.\/-](\d{2,4})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)))[,i,s,r,,a=0,c=0,,u=0,h="am"]=t.map(l);else if(null!==(t=e.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!==(t=e.match(/^(\d{4})(\d{2})(\d{2})\s?((\d{2})(\d{2})((\d{2}))?\s?(am|pm)?)?/i)))[,r,s,i,,a=0,c=0,,u=0,h="am"]=t.map(l);else if(t=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{4})[.\/-](\d{2})[.\/-](\d{2})/i))[,a,c,,u,h="am",r,s,i]=t.map(l);else if(t=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{2})[.\/-](\d{2})[.\/-](\d{4})/i))[,a,c,,u,h="am",i,s,r]=t.map(l);else{if(!(t=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?/i)))return new Date(e);{const e=new Date;r=e.getFullYear(),s=e.getMonth()+1,i=e.getDate(),[,a=0,c=0,,u=0,h="am"]=t.map(l)}}return r>=10&&r<100&&(r+=2e3),"pm"===h.toLowerCase()&&a<12&&(a+=12),new Date(`${r}-${s}-${i} ${a}:${c}:${u}`)}function c(e,t){if(n(e))return new Date("");t=t.split("");const r={Y:"(\\d{4})",y:"(\\d{2})",m:"(\\d{2})",n:"([1-9]\\d?)",d:"(\\d{2})",j:"([1-9]\\d?)",G:"([1-9]\\d?)",g:"([1-9]\\d?)",H:"(\\d{2})",h:"(\\d{2})",i:"(\\d{2})",s:"(\\d{2})",A:"(AM|PM)",a:"(am|pm)"};let s="^",i={years:-1,months:-1,days:-1,hours:-1,minutes:-1,seconds:-1,meridiem:-1},a=1;for(const e of t)r.hasOwnProperty(e)?(s+=r[e],-1!==["Y","y"].indexOf(e)?i.years=a++:-1!==["m","n"].indexOf(e)?i.months=a++:-1!==["d","j"].indexOf(e)?i.days=a++:-1!==["G","g","H","h"].indexOf(e)?i.hours=a++:"i"===e?i.minutes=a++:"s"===e?i.seconds=a++:-1!==["A","a"].indexOf(e)&&(i.meridiem=a++)):s+="\\"+e;s+="$";let c=e.match(new RegExp(s));if(null===c)return new Date("");c=c.map((e=>e&&/^\d*$/.test(e)?parseInt(e):e));const u=new Date;let h=c[i.years],l=c[i.months],o=c[i.days],p=c[i.hours]??0,d=c[i.minutes]??0,f=c[i.seconds]??0,g=c[i.meridiem]??"am";return h||l||o?!h||l||o?h||!l||o?h||l||!o||(h=u.getFullYear(),l=u.getMonth()+1):(h=u.getFullYear(),o=1):(l=1,o=1):(h=u.getFullYear(),l=u.getMonth()+1,o=u.getDate()),h>=10&&h<100&&(h+=2e3),"pm"===g.toLowerCase()&&p<12&&(p+=12),new Date(`${h}-${l}-${o} ${p}:${d}:${f}`)}function n(e){return""===e||null==e}function u(e){const t=Number(e);return null!==e&&"boolean"!=typeof e&&"number"==typeof t&&!isNaN(t)}function h(e){return"[object Object]"===Object.prototype.toString.call(e)}function l(e){return e instanceof Date&&"Invalid Date"!==e.toDateString()}class o{#e;#t;constructor(e){this.#e={},this.#t={},this.validator=e}clearCaches(){this.#e={},this.#t={}}isDependent(e){const t=this.validator.getValue(e[0]);return e.slice(1).some((e=>e==t))}collectRequiredsThenTest(e,t,r,s){let i=[];for(const e of r)i.push(this.checkRequired(e,this.validator.getValue(e)));return!s(i)||this.checkRequired(e,t)}collectMissingsThenTest(e,t,r,s){let i=[];for(const e of r)i.push(this.checkMissing(e));return!s(i)||this.checkMissing(e)}testStringUsingRegex(e,t,r,s,i=!1){return("string"==typeof t||"number"==typeof t)&&(t=String(t),i||this.validator.hasRule(e,"ascii")?r.test(t):s.test(t))}compareValues(e,t,r,s){if(n(t))return!1;const i=r[0]??"";let a=this.validator.getValue(i);return a=void 0===a?u(i)?parseFloat(i,10):null:this.validator.getSize(i,a),!n(a)&&s(this.validator.getSize(e,t),a)}compareDates(e,t,r,s){const i=this.validator.getRule(e);if(!l(t=i.hasOwnProperty("date_format")?c(t,i.date_format[0]):a(t)))return!1;const n=r[0]??"";let u=this.validator.getValue(n);if(void 0===u)u=a(n);else{const e=this.validator.getRule(n);u=e.hasOwnProperty("date_format")?c(u,e.date_format[0]):a(u)}return!!l(u)&&s(t.getTime(),u.getTime())}checkArray(e,t,r){if(!Array.isArray(t)&&!h(t))return!1;if(r&&r.length>0)for(const e of Object.keys(t))if(!r.includes(e))return!1;return!0}checkList(e,t,r){return Array.isArray(t)}checkBoolean(e,t,r){return[!0,!1,0,1,"0","1"].includes(t)}checkDate(e,t,r){return l(a(t))}checkFile(e,t,r){return t instanceof File}checkInteger(e,t,r){return String(parseInt(t,10))===String(t)}checkNumeric(e,t,r){return u(t)}checkString(e,t,r){return"string"==typeof t}checkDecimal(e,t,r){if(!this.checkNumeric(e,t))return!1;const s=(String(t).split(".")[1]??"").length;return 1===r.length?s==r[0]:s>=r[0]&&s<=r[1]}checkMultipleOf(e,t,r){if(!u(t)||!u(r[0]))return!1;const s=parseInt(t,10),i=parseInt(r[0],10);return(0!==s||0!==i)&&(0===s||0!==i&&s%i==0)}checkAccepted(e,t,r){return["yes","on","1",1,!0,"true"].includes(t)}checkAcceptedIf(e,t,r){return!this.isDependent(r)||this.checkAccepted(e,t,r)}checkDeclined(e,t,r){return["no","off","0",0,!1,"false"].includes(t)}checkDeclinedIf(e,t,r){return!this.isDependent(r)||this.checkDeclined(e,t,r)}checkRequired(e,t,r){return!n(t)&&(Array.isArray(t)?t.length>0:t instanceof File?t.size>0:(t=String(t).replace(/\s/g,"")).length>0)}checkRequiredArrayKeys(e,t,r){if(!this.checkArray(e,t))return!1;const s=Object.keys(t);for(const e of r)if(!s.includes(e))return!1;return!0}checkRequiredIf(e,t,r){return!this.isDependent(r)||this.checkRequired(e,t)}checkRequiredIfAccepted(e,t,r){return!this.checkAccepted(r[0],this.validator.getValue(r[0]))||this.checkRequired(e,t)}checkRequiredUnless(e,t,r){return!!this.isDependent(r)||this.checkRequired(e,t)}checkRequiredWith(e,t,r){return this.collectRequiredsThenTest(e,t,r,(e=>e.includes(!0)))}checkRequiredWithAll(e,t,r){return this.collectRequiredsThenTest(e,t,r,(e=>!e.includes(!1)))}checkRequiredWithout(e,t,r){return this.collectRequiredsThenTest(e,t,r,(e=>e.includes(!1)))}checkRequiredWithoutAll(e,t,r){return this.collectRequiredsThenTest(e,t,r,(e=>!e.includes(!0)))}checkFilled(e,t,r){return void 0===t||this.checkRequired(e,t)}checkPresent(e,t,r){return void 0!==t}checkMissing(e,t,r){return!this.validator.hasAttribute(e)}checkMissingIf(e,t,r){return!this.isDependent(r)||this.checkMissing(e)}checkMissingUnless(e,t,r){return!!this.isDependent(r)||this.checkMissing(e)}checkMissingWith(e,t,r){return this.collectMissingsThenTest(e,t,r,(e=>e.includes(!1)))}checkMissingWithAll(e,t,r){return this.collectMissingsThenTest(e,t,r,(e=>!e.includes(!0)))}checkProhibited(e,t,r){return!this.checkRequired(e,t)}checkProhibitedIf(e,t,r){return!this.isDependent(r)||!this.checkRequired(e,t)}checkProhibitedUnless(e,t,r){return!!this.isDependent(r)||!this.checkRequired(e,t)}checkProhibits(e,t,r){if(this.checkRequired(e,t))for(const e of r)if(this.checkRequired(e,this.validator.getValue(e)))return!1;return!0}checkSize(e,t,r){return this.validator.getSize(e,t)===parseFloat(r[0])}checkMin(e,t,r){return this.validator.getSize(e,t)>=parseFloat(r[0])}checkMax(e,t,r){return this.validator.getSize(e,t)<=parseFloat(r[0])}checkBetween(e,t,r){return this.checkMin(e,t,[r[0]])&&this.checkMax(e,t,[r[1]])}checkDigits(e,t,r,s=((e,t)=>e===t)){return!!function(e){return-1===String(e).search(/[^0-9]/)}(t=String(t??""))&&s(t.length,parseInt(r[0],10),parseInt(r[1]??0,10))}checkMinDigits(e,t,r){return this.checkDigits(e,t,r,((e,t)=>e>=t))}checkMaxDigits(e,t,r){return this.checkDigits(e,t,r,((e,t)=>e<=t))}checkDigitsBetween(e,t,r){return this.checkDigits(e,t,r,((e,t,r)=>e>=t&&e<=r))}checkAlpha(e,t,r){return this.testStringUsingRegex(e,t,/^[a-z]+$/i,/^[\p{L}\p{M}]+$/u,r.includes("ascii"))}checkAlphaDash(e,t,r){return this.testStringUsingRegex(e,t,/^[a-z0-9_-]+$/i,/^[\p{L}\p{M}\p{N}_-]+$/u,r.includes("ascii"))}checkAlphaNum(e,t,r){return this.testStringUsingRegex(e,t,/^[a-z0-9]+$/i,/^[\p{L}\p{M}\p{N}]+$/u,r.includes("ascii"))}checkAscii(e,t,r){return!/[^\x09\x10\x13\x0A\x0D\x20-\x7E]/.test(t)}checkRegex(e,t,r,s=!1){if("string"!=typeof t&&!u(t))return!1;const i=r.join(",");let[a,c,h]=i.match(/^\/(.*)\/([gimu]*)$/)??[];if(n(a))throw new Error(`Invalid regular expression pattern: ${i}`);h.includes("u")&&(c=c.replace(/\\A/g,"^").replace(/\\z/gi,"$").replace(/\\([pP])([CLMNPSZ])/g,"\\$1{$2}").replace(/\\\x\{([0-9a-f]+)\}/g,"\\u{$1}"));const l=new RegExp(c,h).test(t);return s?!l:l}checkNotRegex(e,t,r){return this.checkRegex(e,t,r,!0)}checkLowercase(e,t,r){return t===String(t).toLocaleLowerCase()}checkUppercase(e,t,r){return t===String(t).toLocaleUpperCase()}checkStartsWith(e,t,r){t=String(t);for(const e of r)if(t.startsWith(e))return!0;return!1}checkDoesntStartWith(e,t,r){return!this.checkStartsWith(e,t,r)}checkEndsWith(e,t,r){t=String(t);for(const e of r)if(t.endsWith(e))return!0;return!1}checkDoesntEndWith(e,t,r){return!this.checkEndsWith(e,t,r)}checkSame(e,t,r){return t===this.validator.getValue(r[0])}checkDifferent(e,t,r){for(const e of r){const r=this.validator.getValue(e);if(void 0!==r&&t===r)return!1}return!0}checkConfirmed(e,t,r){return this.checkSame(e,t,[e+"_confirmation"])}checkGt(e,t,r){return this.compareValues(e,t,r,((e,t)=>e>t))}checkGte(e,t,r){return this.compareValues(e,t,r,((e,t)=>e>=t))}checkLt(e,t,r){return this.compareValues(e,t,r,((e,t)=>e<t))}checkLte(e,t,r){return this.compareValues(e,t,r,((e,t)=>e<=t))}checkAfter(e,t,r){return this.compareDates(e,t,r,((e,t)=>e>t))}checkAfterOrEqual(e,t,r){return this.compareDates(e,t,r,((e,t)=>e>=t))}checkBefore(e,t,r){return this.compareDates(e,t,r,((e,t)=>e<t))}checkBeforeOrEqual(e,t,r){return this.compareDates(e,t,r,((e,t)=>e<=t))}checkDateEquals(e,t,r){return this.compareDates(e,t,r,((e,t)=>e===t))}checkDateFormat(e,t,r){const s=r[0].split(""),i={Y:"(\\d{4})",y:"(\\d{2})",m:"(\\d{2})",n:"([1-9]\\d?)",d:"(\\d{2})",j:"([1-9]\\d?)",G:"([1-9]\\d?)",g:"([1-9]\\d?)",H:"(\\d{2})",h:"(\\d{2})",i:"(\\d{2})",s:"(\\d{2})",A:"(AM|PM)",a:"(am|pm)"};let a="^";for(const e of s)i.hasOwnProperty(e)?a+=i[e]:a+="\\"+e;return a+="$",new RegExp(a).test(t)}checkDistinct(e,t,i){const a=this.validator.getPrimaryAttribute(e);if(!a.includes("*"))return!0;const c=a.indexOf("*"),n=a.substring(0,c-1);let u;this.#e.hasOwnProperty(n)?u=this.#e[n]:(u=JSON.stringify(s(this.validator.getValue(n)??{})),this.#e[n]=u);const h=i.includes("ignore_case"),l=!h&&i.includes("strict"),o=r(String(t));let p=`"${r(a.substring(c)).replaceAll("\\*",'[^."]+')}":`,d=0;return p+=l?"string"==typeof t?`"${o}"`:`${o}`:`(${o}|"${o}")`,p+="[,}]+",d+=u.match(new RegExp(p,"g"+(h?"i":"")))?.length??0,1===d}checkInArray(e,t,r){const i=this.validator.getPrimaryAttribute(r[0]);if(!i.includes("*"))return!1;const a=this.validator.getValue(i.split(".*")[0])??{};return Object.values(s(a)).some((e=>e==t))}checkIn(e,t,r){if(!this.checkArray(e,t)||!this.validator.hasRule(e,"array"))return r.some((e=>e==t));for(const e of Object.values(t))if(!r.some((t=>t==e)))return!1;return!0}checkNotIn(e,t,r){return!this.checkIn(e,t,r)}checkMimetypes(e,t,r){return!!this.checkFile(e,t)&&r.includes(t.type)}checkMimes(e,t,r){return!!this.checkFile(e,t)&&r.includes(t.name.split(".").pop().toLowerCase())}checkExtensions(e,t,r){return this.checkMimes(e,t,r)}async checkImage(e,t,r){let s=this.checkMimes(e,t,["jpg","jpeg","png","gif","bmp","svg","webp"]);return s&&"undefined"!=typeof FileReader?(await new Promise(((e,r)=>{const s=new FileReader;s.onload=t=>e(t.target.result),s.onerror=r,s.readAsDataURL(t)})).then((async t=>{const r=new Image;r.src=t,await r.decode(),this.#t[e]=r})).catch((()=>{s=!1})),s):s}async checkDimensions(e,t,r){if(!this.checkImage(e,t)||!this.#t.hasOwnProperty(e))return!1;const s={};for(const e of r){const[t,r]=e.split("=",2);if("ratio"===t&&r.includes("/")){const[e,i]=r.split("/",2).map((e=>parseFloat(e,10)));s[t]=e/i}else s[t]=parseFloat(r,10)}const i=this.#t[e],a=i.naturalWidth,c=i.naturalHeight;return!(s.hasOwnProperty("width")&&s.width!==a||s.hasOwnProperty("height")&&s.height!==c||s.hasOwnProperty("min_width")&&s.min_width>a||s.hasOwnProperty("min_height")&&s.min_height>c||s.hasOwnProperty("max_width")&&s.max_width<a||s.hasOwnProperty("max_height")&&s.max_height<c)&&(!s.hasOwnProperty("ratio")||Math.abs(s.ratio-a/c)<=1/(Math.max(a,c)+1))}checkEmail(e,t,r){if(!/^(([^<>()[\]\\.,;:\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,}))$/.test(t)){return/^((?:[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]))?)+)*$/.test(t)}return!0}checkJson(e,t,r){try{JSON.parse(t)}catch(e){return!1}return!0}checkHexColor(e,t,r){return/^#(?:(?:[0-9a-f]{3}){1,2}|(?:[0-9a-f]{4}){1,2})$/i.test(t)}checkMacAddress(e,t,r){t=String(t);const s={"-":2,":":2,".":4};let i,a;for([i,a]of Object.entries(s))if(t.includes(i))break;const c=t.split(i);if(c.length!==12/a)return!1;for(const e of c)if(!new RegExp("^[0-9a-f]{"+a+"}$","i").test(e))return!1;return!0}checkIpv4(e,t,r){if(/[^\d.]/.test(t))return!1;const s=String(t).split(".");if(4!==s.length)return!1;for(const e of s)if(e<0||e>255)return!1;return!0}checkIpv6(e,t,r){if((t=String(t)).includes(":::")||t.split("::").length>2)return!1;const s=t.split(":");if(s.length<3||s.length>8)return!1;for(const e of s)if(""!==e&&!/^[0-9a-f]{1,4}$/i.test(e))return!1;return!0}checkIp(e,t,r){return this.checkIpv4(e,t,r)||this.checkIpv6(e,t,r)}checkTimezone(e,t,r){try{Intl.DateTimeFormat(void 0,{timeZone:t})}catch(e){if(String(e).toLowerCase().includes("invalid time zone"))return!1}return!0}checkUrl(e,t,r){try{new URL(t)}catch(e){return!1}return!0}checkUlid(e,t,r){return/[0-7][0-9A-HJKMNP-TV-Z]{25}/.test(t)}checkUuid(e,t,r){return/[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/.test(t)}}class p{#r;keys(){return Object.keys(this.#r)}values(){return Object.values(this.#r)}entries(){return Object.entries(this.#r)}add(e,t){this.#r.hasOwnProperty(e)?this.#r[e].push(t):this.#r[e]=[t]}get(e){if(!e.includes("*"))return this.#r.hasOwnProperty(e)?this.#r[e]:{};const t=new RegExp("^"+e.replaceAll("*",".*?")+"$"),r={};for(const[e,s]of this.entries())t.test(e)&&(r[e]=s);return r}first(e){for(const t of Object.values(this.get(e)))return Array.isArray(t)?t[0]:t;return""}has(e){return""!==this.first(e)}messages(){return this.#r}all(){const e=[];return this.values().forEach((t=>e.push(...t))),e}count(){let e=0;return this.values().forEach((t=>e+=t.length)),e}isEmpty(){return 0===this.keys().length}isNotEmpty(){return!this.isEmpty()}constructor(){this.#r={}}}class d{static#s;static#i={};static locale(e){this.#s=e}static setMessages(e,t){this.#i[e]=s(t)}static get(e){if(this.#i[this.#s]&&this.#i[this.#s][e])return this.#i[this.#s][e]}static has(e){return void 0!==this.get(e)}static set(e,t){h(t)?Object.assign(this.#i[this.#s],s(t,e)):"string"==typeof t&&(this.#i[this.#s][e]=t)}}class f{constructor(e){this.validator=e}replace(e,t){return Object.entries(t).forEach((([t,r])=>e=e.replaceAll(":"+t,r))),e}replaceDecimal(e,t,r,s){return this.replace(e,{decimal:s.join("-")})}replaceMultipleOf(e,t,r,s){return this.replace(e,{value:s[0]})}replaceAcceptedIf(e,t,r,s){return this.replace(e,{other:this.validator.getDisplayableAttribute(s[0]),value:this.validator.getDisplayableValue(s[0],this.validator.getValue(s[0]))})}replaceDeclinedIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredArrayKeys(e,t,r,s){return this.replace(e,{values:s.map((e=>this.validator.getDisplayableValue(t,e))).join(", ")})}replaceRequiredIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredIfAccepted(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredUnless(e,t,r,s){return this.replace(e,{other:this.validator.getDisplayableAttribute(s[0]),values:s.slice(1).map((e=>this.validator.getDisplayableValue(s[0],e))).join(", ")})}replaceRequiredWith(e,t,r,s){return this.replace(e,{values:s.map((e=>this.validator.getDisplayableAttribute(e))).join(" / ")})}replaceRequiredWithAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceRequiredWithout(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceRequiredWithoutAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceMissingIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceMissingUnless(e,t,r,s){return this.replace(this.replaceRequiredUnless(e,t,r,s),{value:this.validator.getDisplayableValue(s[0],s[1])})}replaceMissingWith(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceMissingWithAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceProhibitedIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceProhibitedUnless(e,t,r,s){return this.replaceRequiredUnless(e,t,r,s)}replaceProhibits(e,t,r,s){return this.replace(e,{other:s.map((e=>this.validator.getDisplayableAttribute(e))).join(" / ")})}replaceSize(e,t,r,s){return this.replace(e,{size:s[0]})}replaceMin(e,t,r,s){return this.replace(e,{min:s[0]})}replaceMax(e,t,r,s){return this.replace(e,{max:s[0]})}replaceBetween(e,t,r,s){return this.replace(e,{min:s[0],max:s[1]})}replaceDigits(e,t,r,s){return this.replace(e,{digits:s[0]})}replaceMinDigits(e,t,r,s){return this.replaceMin(e,t,r,s)}replaceMaxDigits(e,t,r,s){return this.replaceMax(e,t,r,s)}replaceDigitsBetween(e,t,r,s){return this.replaceBetween(e,t,r,s)}replaceStartsWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceDoesntStartWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceEndsWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceDoesntEndWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceSame(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceDifferent(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceGt(e,t,r,s){const i=this.validator.getValue(s[0]);return this.replace(e,{value:i?this.validator.getSize(s[0],i):this.validator.getDisplayableAttribute(s[0])})}replaceGte(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceLt(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceLte(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceAfter(e,t,r,s){const i=s[0];return this.replace(e,{date:this.validator.hasAttribute(i)?this.validator.getDisplayableAttribute(i):i})}replaceAfterOrEqual(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceBefore(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceBeforeOrEqual(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceDateEquals(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceDateFormat(e,t,r,s){return this.replace(e,{format:s[0]})}replaceInArray(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceIn(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceNotIn(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceMimetypes(e,t,r,s){return this.replace(e,{values:s.join(", ")})}replaceMimes(e,t,r,s){return this.replaceMimetypes(e,t,r,s)}replaceExtensions(e,t,r,s){return this.replaceMimetypes(e,t,r,s)}}class g{static#a={};static#c={};static#n=["active_url","bail","can","current_password","enum","exclude","exclude_if","exclude_unless","exclude_with","exclude_without","exists","nullable","sometimes","unique"];static#u=["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"];#r;#h;#l;#o;#p;#d;#f;#g;#m;#y;#k;static setLocale(e){d.locale(e)}static setMessages(e,t){d.setMessages(e,t)}static addChecker(e,t,r){g.#a[e]=t,r&&d.set(e,r)}static addImplicitChecker(e,t,r){g.addChecker(e,t,r),g.#u.push(e)}static addReplacer(e,t){g.#c[e]=t}static addDummyRule(e){g.#n.push(e)}constructor(e={},r={},s={},i={},a={}){this.#m={},this.#y=!1,this.#k=!1,this.fileRules=["file","image","mimetypes","mimes"],this.numericRules=["decimal","numeric","integer"],this.sizeRules=["size","between","min","max","gt","lt","gte","lte"],this.setProperties(e,r,s,i,a),this.#d=new o(this),this.#f=new f(this);for(const[e,r]of Object.entries(g.#a))this.#d[t("check_"+e)]=r;for(const[e,r]of Object.entries(g.#c))this.#f[t("replace_"+e)]=r;this.#g=new p}setProperties(e={},t={},r={},i={},a={}){return this.#r=e,this.#h=this.parseRules(t),this.#l=r,this.#o=i,this.#p=s(a),this}setData(e){return this.#r=e,this}setRules(e){return this.#h=this.parseRules(e),this}setCustomMessages(e){return this.#l=e,this}setCustomAttributes(e){return this.#o=e,this}setCustomValues(e){return this.#p=s(e),this}addImplicitAttribute(e,t){return this.#m[e]=t,this}stopOnFirstFailure(e=!0){return this.#y=e,this}alwaysBail(e=!0){return this.#k=e,this}parseRules(e){const t={};for(const[r,s]of Object.entries(e)){const e=r.includes("*")?this.parseWildcardAttribute(r):[r];for(const r of e){const e={};for(const t of this.parseAttributeRules(s)){const[r,s]=this.parseAttributeRule(t);e[r]=s}t[r]=e}}return t}parseWildcardAttribute(e){const t=[],r=e.indexOf("*"),s=e.substring(0,r-1),i=e.substring(r+2),a=this.getValue(s);return Array.isArray(a)||h(a)?(Object.entries(a).forEach((([r,a])=>{const c=`${s}.${r}.${i}`.replace(/\.$/,""),n=c.includes("*")?this.parseWildcardAttribute(c):[c];t.push(...n),n.forEach((t=>this.#m[t]=e))})),t):[e]}parseAttributeRules(e){return Array.isArray(e)?e:String(e).split("|")}parseAttributeRule(e){if(Array.isArray(e))return[e.shift()??"",e];const t=e.indexOf(":");return-1===t?[e,[]]:[e.substring(0,t),i(e.substring(t+1))]}async validate(){this.#d.clearCaches(),this.#g=new p;for(const[e,r]of Object.entries(this.#h)){let s=this.getValue(e);if(r.hasOwnProperty("sometimes")&&void 0===s)continue;const i=this.#k||r.hasOwnProperty("bail"),a=r.hasOwnProperty("nullable");let c=!1;for(const[u,h]of Object.entries(r)){if(""===u)continue;if(!g.#u.includes(u)&&(void 0===s||"string"==typeof s&&""===s.trim()||a&&null===s))continue;let r,l,o;const p=t("check_"+u);if("function"==typeof this.#d[p])r=await this.#d[p](e,s,h);else{if(!g.#n.includes(u))throw new Error(`Invalid validation rule: ${u}`);r=!0}if("boolean"==typeof r?l=r:({status:l,message:o}=r),!l&&(c=!0,o=n(o)?this.getMessage(e,u):o,o=this.makeReplacements(o,e,u,h),this.#g.add(e,o),i||g.#u.includes(u)))break}if(this.#y&&c)break}if(this.#g.isNotEmpty())throw this.#g}async passes(){try{await this.validate()}catch(e){if(e instanceof Error)throw e;return!1}return!0}async fails(){return!await this.passes()}getMessage(e,t){const r=this.getValue(e);let s;e=this.getPrimaryAttribute(e);for(const r of[`${e}.${t}`,t])if(this.#l.hasOwnProperty(r)){s=this.#l[r];break}if(!s){let i=t;this.sizeRules.includes(i)&&(Array.isArray(r)||h(r)||this.hasRule(e,"array")?i+=".array":r instanceof File||this.hasRule(e,this.fileRules)?i+=".file":"number"==typeof r||this.hasRule(e,this.numericRules)?i+=".numeric":i+=".string"),s=d.get(i)}return s??`validation.${t}`}makeReplacements(e,r,s,i){const a=this.getDisplayableAttribute(r),c=this.getValue(r),n={attribute:a,ATTRIBUTE:a.toLocaleUpperCase(),Attribute:a.charAt(0).toLocaleUpperCase()+a.substring(1),input:this.getDisplayableValue(r,c)};for(const[t,r]of Object.entries(n))e=e.replaceAll(":"+t,r);const u=r.match(/\.(\d+)\.?/),h=null===u?-1:parseInt(u[1],10);-1!==h&&(e=e.replaceAll(":index",h).replaceAll(":position",h+1));const l=t("replace_"+s);return"function"==typeof this.#f[l]&&(e=this.#f[l](e,r,s,i)),e}getDisplayableAttribute(e){const t=this.getPrimaryAttribute(e);for(const r of[e,t]){if(this.#o.hasOwnProperty(r))return this.#o[r];if(d.has(`attributes.${r}`))return d.get(`attributes.${r}`)}return this.#m.hasOwnProperty(e)?e:(r=e,r.replace(/(.)(?=[A-Z])/g,(e=>e+"_")).toLowerCase()).replaceAll("_"," ");var r}getDisplayableValue(e,t){const r=`${e=this.getPrimaryAttribute(e)}.${t}`;return n(t)?"empty":"boolean"==typeof t||this.hasRule(e,"boolean")?Number(t)?"true":"false":this.#p.hasOwnProperty(r)?this.#p[r]:d.has(`values.${r}`)?d.get(`values.${r}`):t}getSize(e,t){return n(t)?0:u(t)&&this.hasRule(e,this.numericRules)?parseFloat("string"==typeof t?t.trim():t,10):t instanceof File?t.size/1024:h(t)?Object.keys(t).length:t.hasOwnProperty("length")?t.length:t}getRule(e){return e=this.getPrimaryAttribute(e),this.#h[e]??{}}hasRule(e,t){if(e=this.getPrimaryAttribute(e),t="string"==typeof t?[t]:t,!this.#h.hasOwnProperty(e))return!1;for(const r of t)if(this.#h[e].hasOwnProperty(r))return!0;return!1}getPrimaryAttribute(e){return this.#m.hasOwnProperty(e)?this.#m[e]:e}hasAttribute(e){return void 0!==this.getValue(e)}getValue(e){return function(e,t,r){const s=t.split(".");let i=e;for(const e of s){if(!i.hasOwnProperty(e))return r;i=i[e]}return i}(this.#r,e)}errors(){return this.#g}}return e.Checkers=o,e.ErrorBag=p,e.Lang=d,e.Replacers=f,e.Validator=g,e}({});
6
+ var quival=function(e){"use strict";function t(e){return e.replace(/[-_]/g," ").replace(/\s+/," ").trim().replace(/(\s\w)/g,(e=>e[1].toUpperCase()))}function r(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function s(e,t=""){return Object.keys(e).reduce(((r,i)=>{const a=t?`${t}.${i}`:i;return"object"==typeof e[i]&&null!==e[i]?Object.assign(r,s(e[i],a)):r[a]=e[i],r}),{})}function i(e){const t=[];let r="",s=!1;for(let i=0;i<e.length;i++){const a=e[i];'"'===a?s&&'"'===e[i+1]?(r+='"',i++):(s=!s,s&&(r=r.trim())):","!==a||s?r+=a:(t.push(r),r="")}return t.push(r),t}function a(e){if(n(e)||"string"!=typeof e)return new Date("");if(e instanceof Date)return e;let t,r,s,i,a,c,l,h;const u=e=>e&&/^\d*$/.test(e)?parseInt(e):e;if(null!==(t=e.match(/^(\d{1,2})[.\/-](\d{1,2})[.\/-](\d{2,4})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)))[,i,s,r,,a=0,c=0,,l=0,h="am"]=t.map(u);else if(null!==(t=e.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!==(t=e.match(/^(\d{4})(\d{2})(\d{2})\s?((\d{2})(\d{2})((\d{2}))?\s?(am|pm)?)?/i)))[,r,s,i,,a=0,c=0,,l=0,h="am"]=t.map(u);else if(t=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{4})[.\/-](\d{2})[.\/-](\d{2})/i))[,a,c,,l,h="am",r,s,i]=t.map(u);else if(t=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{2})[.\/-](\d{2})[.\/-](\d{4})/i))[,a,c,,l,h="am",i,s,r]=t.map(u);else{if(!(t=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?/i)))return new Date(e);{const e=new Date;r=e.getFullYear(),s=e.getMonth()+1,i=e.getDate(),[,a=0,c=0,,l=0,h="am"]=t.map(u)}}return r>=10&&r<100&&(r+=2e3),"pm"===h.toLowerCase()&&a<12&&(a+=12),new Date(`${r}-${s}-${i} ${a}:${c}:${l}`)}function c(e,t){if(n(e))return new Date("");t=t.split("");const r={Y:"(\\d{4})",y:"(\\d{2})",m:"(\\d{2})",n:"([1-9]\\d?)",d:"(\\d{2})",j:"([1-9]\\d?)",G:"([1-9]\\d?)",g:"([1-9]\\d?)",H:"(\\d{2})",h:"(\\d{2})",i:"(\\d{2})",s:"(\\d{2})",A:"(AM|PM)",a:"(am|pm)"};let s="^",i={years:-1,months:-1,days:-1,hours:-1,minutes:-1,seconds:-1,meridiem:-1},a=1;for(const e of t)Object.hasOwn(r,e)?(s+=r[e],-1!==["Y","y"].indexOf(e)?i.years=a++:-1!==["m","n"].indexOf(e)?i.months=a++:-1!==["d","j"].indexOf(e)?i.days=a++:-1!==["G","g","H","h"].indexOf(e)?i.hours=a++:"i"===e?i.minutes=a++:"s"===e?i.seconds=a++:-1!==["A","a"].indexOf(e)&&(i.meridiem=a++)):s+="\\"+e;s+="$";let c=e.match(new RegExp(s));if(null===c)return new Date("");c=c.map((e=>e&&/^\d*$/.test(e)?parseInt(e):e));const l=new Date;let h=c[i.years],u=c[i.months],o=c[i.days],d=c[i.hours]??0,p=c[i.minutes]??0,f=c[i.seconds]??0,g=c[i.meridiem]??"am";return h||u||o?!h||u||o?h||!u||o?h||u||!o||(h=l.getFullYear(),u=l.getMonth()+1):(h=l.getFullYear(),o=1):(u=1,o=1):(h=l.getFullYear(),u=l.getMonth()+1,o=l.getDate()),h>=10&&h<100&&(h+=2e3),"pm"===g.toLowerCase()&&d<12&&(d+=12),new Date(`${h}-${u}-${o} ${d}:${p}:${f}`)}function n(e){return""===e||null==e}function l(e){const t=Number(e);return null!==e&&"boolean"!=typeof e&&"number"==typeof t&&!isNaN(t)}function h(e){return"[object Object]"===Object.prototype.toString.call(e)}function u(e){return e instanceof Date&&"Invalid Date"!==e.toDateString()}class o{#e;#t;constructor(e){this.#e={},this.#t={},this.validator=e}clearCaches(){this.#e={},this.#t={}}isDependent(e){const t=this.validator.getValue(e[0]);return e.slice(1).some((e=>e==t))}collectRequiredsThenTest(e,t,r,s){let i=[];for(const e of r)i.push(this.checkRequired(e,this.validator.getValue(e)));return!s(i)||this.checkRequired(e,t)}collectMissingsThenTest(e,t,r,s){let i=[];for(const e of r)i.push(this.checkMissing(e));return!s(i)||this.checkMissing(e)}testStringUsingRegex(e,t,r,s,i=!1){return("string"==typeof t||"number"==typeof t)&&(t=String(t),i||this.validator.hasRule(e,"ascii")?r.test(t):s.test(t))}compareValues(e,t,r,s){if(n(t))return!1;const i=r[0]??"";let a=this.validator.getValue(i);return a=void 0===a?l(i)?parseFloat(i,10):null:this.validator.getSize(i,a),!n(a)&&s(this.validator.getSize(e,t),a)}compareDates(e,t,r,s){const i=this.validator.getRule(e);if(!u(t=Object.hasOwn(i,"date_format")?c(t,i.date_format[0]):a(t)))return!1;const n=r[0]??"";let l=this.validator.getValue(n);if(void 0===l)l=a(n);else{const e=this.validator.getRule(n);l=Object.hasOwn(e,"date_format")?c(l,e.date_format[0]):a(l)}return!!u(l)&&s(t.getTime(),l.getTime())}checkArray(e,t,r){if(!Array.isArray(t)&&!h(t))return!1;if(r&&r.length>0)for(const e of Object.keys(t))if(!r.includes(e))return!1;return!0}checkList(e,t,r){return Array.isArray(t)}checkBoolean(e,t,r){return[!0,!1,0,1,"0","1"].includes(t)}checkDate(e,t,r){return u(a(t))}checkFile(e,t,r){return t instanceof File}checkInteger(e,t,r){return String(parseInt(t,10))===String(t)}checkNumeric(e,t,r){return l(t)}checkString(e,t,r){return"string"==typeof t}checkDecimal(e,t,r){if(!this.checkNumeric(e,t))return!1;const s=(String(t).split(".")[1]??"").length;return 1===r.length?s==r[0]:s>=r[0]&&s<=r[1]}checkMultipleOf(e,t,r){if(!l(t)||!l(r[0]))return!1;const s=parseInt(t,10),i=parseInt(r[0],10);return(0!==s||0!==i)&&(0===s||0!==i&&s%i==0)}checkAccepted(e,t,r){return["yes","on","1",1,!0,"true"].includes(t)}checkAcceptedIf(e,t,r){return!this.isDependent(r)||this.checkAccepted(e,t,r)}checkDeclined(e,t,r){return["no","off","0",0,!1,"false"].includes(t)}checkDeclinedIf(e,t,r){return!this.isDependent(r)||this.checkDeclined(e,t,r)}checkRequired(e,t,r){return!n(t)&&(Array.isArray(t)?t.length>0:t instanceof File?t.size>0:(t=String(t).replace(/\s/g,"")).length>0)}checkRequiredArrayKeys(e,t,r){if(!this.checkArray(e,t))return!1;const s=Object.keys(t);for(const e of r)if(!s.includes(e))return!1;return!0}checkRequiredIf(e,t,r){return!this.isDependent(r)||this.checkRequired(e,t)}checkRequiredIfAccepted(e,t,r){return!this.checkAccepted(r[0],this.validator.getValue(r[0]))||this.checkRequired(e,t)}checkRequiredUnless(e,t,r){return!!this.isDependent(r)||this.checkRequired(e,t)}checkRequiredWith(e,t,r){return this.collectRequiredsThenTest(e,t,r,(e=>e.includes(!0)))}checkRequiredWithAll(e,t,r){return this.collectRequiredsThenTest(e,t,r,(e=>!e.includes(!1)))}checkRequiredWithout(e,t,r){return this.collectRequiredsThenTest(e,t,r,(e=>e.includes(!1)))}checkRequiredWithoutAll(e,t,r){return this.collectRequiredsThenTest(e,t,r,(e=>!e.includes(!0)))}checkFilled(e,t,r){return void 0===t||this.checkRequired(e,t)}checkPresent(e,t,r){return void 0!==t}checkMissing(e,t,r){return!this.validator.hasAttribute(e)}checkMissingIf(e,t,r){return!this.isDependent(r)||this.checkMissing(e)}checkMissingUnless(e,t,r){return!!this.isDependent(r)||this.checkMissing(e)}checkMissingWith(e,t,r){return this.collectMissingsThenTest(e,t,r,(e=>e.includes(!1)))}checkMissingWithAll(e,t,r){return this.collectMissingsThenTest(e,t,r,(e=>!e.includes(!0)))}checkProhibited(e,t,r){return!this.checkRequired(e,t)}checkProhibitedIf(e,t,r){return!this.isDependent(r)||!this.checkRequired(e,t)}checkProhibitedUnless(e,t,r){return!!this.isDependent(r)||!this.checkRequired(e,t)}checkProhibits(e,t,r){if(this.checkRequired(e,t))for(const e of r)if(this.checkRequired(e,this.validator.getValue(e)))return!1;return!0}checkSize(e,t,r){return this.validator.getSize(e,t)===parseFloat(r[0])}checkMin(e,t,r){return this.validator.getSize(e,t)>=parseFloat(r[0])}checkMax(e,t,r){return this.validator.getSize(e,t)<=parseFloat(r[0])}checkBetween(e,t,r){return this.checkMin(e,t,[r[0]])&&this.checkMax(e,t,[r[1]])}checkDigits(e,t,r,s=((e,t)=>e===t)){return!!function(e){return-1===String(e).search(/[^0-9]/)}(t=String(t??""))&&s(t.length,parseInt(r[0],10),parseInt(r[1]??0,10))}checkMinDigits(e,t,r){return this.checkDigits(e,t,r,((e,t)=>e>=t))}checkMaxDigits(e,t,r){return this.checkDigits(e,t,r,((e,t)=>e<=t))}checkDigitsBetween(e,t,r){return this.checkDigits(e,t,r,((e,t,r)=>e>=t&&e<=r))}checkAlpha(e,t,r){return this.testStringUsingRegex(e,t,/^[a-z]+$/i,/^[\p{L}\p{M}]+$/u,r.includes("ascii"))}checkAlphaDash(e,t,r){return this.testStringUsingRegex(e,t,/^[a-z0-9_-]+$/i,/^[\p{L}\p{M}\p{N}_-]+$/u,r.includes("ascii"))}checkAlphaNum(e,t,r){return this.testStringUsingRegex(e,t,/^[a-z0-9]+$/i,/^[\p{L}\p{M}\p{N}]+$/u,r.includes("ascii"))}checkAscii(e,t,r){return!/[^\x09\x10\x13\x0A\x0D\x20-\x7E]/.test(t)}checkRegex(e,t,r,s=!1){if("string"!=typeof t&&!l(t))return!1;const i=r.join(",");let[a,c,h]=i.match(/^\/(.*)\/([gimu]*)$/)??[];if(n(a))throw new Error(`Invalid regular expression pattern: ${i}`);h.includes("u")&&(c=c.replace(/\\A/g,"^").replace(/\\z/gi,"$").replace(/\\([pP])([CLMNPSZ])/g,"\\$1{$2}").replace(/\\\x\{([0-9a-f]+)\}/g,"\\u{$1}"));const u=new RegExp(c,h).test(t);return s?!u:u}checkNotRegex(e,t,r){return this.checkRegex(e,t,r,!0)}checkLowercase(e,t,r){return t===String(t).toLocaleLowerCase()}checkUppercase(e,t,r){return t===String(t).toLocaleUpperCase()}checkStartsWith(e,t,r){t=String(t);for(const e of r)if(t.startsWith(e))return!0;return!1}checkDoesntStartWith(e,t,r){return!this.checkStartsWith(e,t,r)}checkEndsWith(e,t,r){t=String(t);for(const e of r)if(t.endsWith(e))return!0;return!1}checkDoesntEndWith(e,t,r){return!this.checkEndsWith(e,t,r)}checkSame(e,t,r){return t===this.validator.getValue(r[0])}checkDifferent(e,t,r){for(const e of r){const r=this.validator.getValue(e);if(void 0!==r&&t===r)return!1}return!0}checkConfirmed(e,t,r){return this.checkSame(e,t,[e+"_confirmation"])}checkGt(e,t,r){return this.compareValues(e,t,r,((e,t)=>e>t))}checkGte(e,t,r){return this.compareValues(e,t,r,((e,t)=>e>=t))}checkLt(e,t,r){return this.compareValues(e,t,r,((e,t)=>e<t))}checkLte(e,t,r){return this.compareValues(e,t,r,((e,t)=>e<=t))}checkAfter(e,t,r){return this.compareDates(e,t,r,((e,t)=>e>t))}checkAfterOrEqual(e,t,r){return this.compareDates(e,t,r,((e,t)=>e>=t))}checkBefore(e,t,r){return this.compareDates(e,t,r,((e,t)=>e<t))}checkBeforeOrEqual(e,t,r){return this.compareDates(e,t,r,((e,t)=>e<=t))}checkDateEquals(e,t,r){return this.compareDates(e,t,r,((e,t)=>e===t))}checkDateFormat(e,t,r){const s=r[0].split(""),i={Y:"(\\d{4})",y:"(\\d{2})",m:"(\\d{2})",n:"([1-9]\\d?)",d:"(\\d{2})",j:"([1-9]\\d?)",G:"([1-9]\\d?)",g:"([1-9]\\d?)",H:"(\\d{2})",h:"(\\d{2})",i:"(\\d{2})",s:"(\\d{2})",A:"(AM|PM)",a:"(am|pm)"};let a="^";for(const e of s)Object.hasOwn(i,e)?a+=i[e]:a+="\\"+e;return a+="$",new RegExp(a).test(t)}checkDistinct(e,t,i){const a=this.validator.getPrimaryAttribute(e);if(!a.includes("*"))return!0;const c=a.indexOf("*"),n=a.substring(0,c-1);let l;Object.hasOwn(this.#e,n)?l=this.#e[n]:(l=JSON.stringify(s(this.validator.getValue(n)??{})),this.#e[n]=l);const h=i.includes("ignore_case"),u=!h&&i.includes("strict"),o=r(String(t));let d=`"${r(a.substring(c)).replaceAll("\\*",'[^."]+')}":`,p=0;return d+=u?"string"==typeof t?`"${o}"`:`${o}`:`(${o}|"${o}")`,d+="[,}]+",p+=l.match(new RegExp(d,"g"+(h?"i":"")))?.length??0,1===p}checkInArray(e,t,r){const i=this.validator.getPrimaryAttribute(r[0]);if(!i.includes("*"))return!1;const a=this.validator.getValue(i.split(".*")[0])??{};return Object.values(s(a)).some((e=>e==t))}checkIn(e,t,r){if(!this.checkArray(e,t)||!this.validator.hasRule(e,"array"))return r.some((e=>e==t));for(const e of Object.values(t))if(!r.some((t=>t==e)))return!1;return!0}checkNotIn(e,t,r){return!this.checkIn(e,t,r)}checkMimetypes(e,t,r){return!!this.checkFile(e,t)&&r.includes(t.type)}checkMimes(e,t,r){return!!this.checkFile(e,t)&&r.includes(t.name.split(".").pop().toLowerCase())}checkExtensions(e,t,r){return this.checkMimes(e,t,r)}async checkImage(e,t,r){let s=this.checkMimes(e,t,["jpg","jpeg","png","gif","bmp","svg","webp"]);return s&&"undefined"!=typeof FileReader?(await new Promise(((e,r)=>{const s=new FileReader;s.onload=t=>e(t.target.result),s.onerror=r,s.readAsDataURL(t)})).then((async t=>{const r=new Image;r.src=t,await r.decode(),this.#t[e]=r})).catch((()=>{s=!1})),s):s}async checkDimensions(e,t,r){if(!this.checkImage(e,t)||!Object.hasOwn(this.#t,e))return!1;const s={};for(const e of r){const[t,r]=e.split("=",2);if("ratio"===t&&r.includes("/")){const[e,i]=r.split("/",2).map((e=>parseFloat(e,10)));s[t]=e/i}else s[t]=parseFloat(r,10)}const i=this.#t[e],a=i.naturalWidth,c=i.naturalHeight;return!(Object.hasOwn(s,"width")&&s.width!==a||Object.hasOwn(s,"height")&&s.height!==c||Object.hasOwn(s,"min_width")&&s.min_width>a||Object.hasOwn(s,"min_height")&&s.min_height>c||Object.hasOwn(s,"max_width")&&s.max_width<a||Object.hasOwn(s,"max_height")&&s.max_height<c)&&(!Object.hasOwn(s,"ratio")||Math.abs(s.ratio-a/c)<=1/(Math.max(a,c)+1))}checkEmail(e,t,r){if(!/^(([^<>()[\]\\.,;:\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,}))$/.test(t)){return/^((?:[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]))?)+)*$/.test(t)}return!0}checkJson(e,t,r){try{JSON.parse(t)}catch(e){return!1}return!0}checkHexColor(e,t,r){return/^#(?:(?:[0-9a-f]{3}){1,2}|(?:[0-9a-f]{4}){1,2})$/i.test(t)}checkMacAddress(e,t,r){t=String(t);const s={"-":2,":":2,".":4};let i,a;for([i,a]of Object.entries(s))if(t.includes(i))break;const c=t.split(i);if(c.length!==12/a)return!1;for(const e of c)if(!new RegExp("^[0-9a-f]{"+a+"}$","i").test(e))return!1;return!0}checkIpv4(e,t,r){if(/[^\d.]/.test(t))return!1;const s=String(t).split(".");if(4!==s.length)return!1;for(const e of s)if(e<0||e>255)return!1;return!0}checkIpv6(e,t,r){if((t=String(t)).includes(":::")||t.split("::").length>2)return!1;const s=t.split(":");if(s.length<3||s.length>8)return!1;for(const e of s)if(""!==e&&!/^[0-9a-f]{1,4}$/i.test(e))return!1;return!0}checkIp(e,t,r){return this.checkIpv4(e,t,r)||this.checkIpv6(e,t,r)}checkTimezone(e,t,r){try{Intl.DateTimeFormat(void 0,{timeZone:t})}catch(e){if(String(e).toLowerCase().includes("invalid time zone"))return!1}return!0}checkUrl(e,t,r){try{new URL(t)}catch(e){return!1}return!0}checkUlid(e,t,r){return/[0-7][0-9A-HJKMNP-TV-Z]{25}/.test(t)}checkUuid(e,t,r){return/[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/.test(t)}}class d{#r;keys(){return Object.keys(this.#r)}values(){return Object.values(this.#r)}entries(){return Object.entries(this.#r)}add(e,t){Object.hasOwn(this.#r,e)?this.#r[e].push(t):this.#r[e]=[t]}get(e){if(!e.includes("*"))return Object.hasOwn(this.#r,e)?this.#r[e]:{};const t=new RegExp("^"+e.replaceAll("*",".*?")+"$"),r={};for(const[e,s]of this.entries())t.test(e)&&(r[e]=s);return r}first(e){for(const t of Object.values(this.get(e)))return Array.isArray(t)?t[0]:t;return""}has(e){return""!==this.first(e)}messages(){return this.#r}all(){const e=[];return this.values().forEach((t=>e.push(...t))),e}count(){let e=0;return this.values().forEach((t=>e+=t.length)),e}isEmpty(){return 0===this.keys().length}isNotEmpty(){return!this.isEmpty()}sortByKeys(e){const t={};for(const r of e)Object.hasOwn(this.#r,r)&&(t[r]=this.#r[r]);this.#r=t}constructor(){this.#r={}}}class p{static#s;static#i={};static locale(e){this.#s=e}static setMessages(e,t){this.#i[e]=s(t)}static get(e){if(this.#i[this.#s]&&this.#i[this.#s][e])return this.#i[this.#s][e]}static has(e){return void 0!==this.get(e)}static set(e,t){h(t)?Object.assign(this.#i[this.#s],s(t,e)):"string"==typeof t&&(this.#i[this.#s][e]=t)}}class f{constructor(e){this.validator=e}replace(e,t){return Object.entries(t).forEach((([t,r])=>e=e.replaceAll(":"+t,r))),e}replaceDecimal(e,t,r,s){return this.replace(e,{decimal:s.join("-")})}replaceMultipleOf(e,t,r,s){return this.replace(e,{value:s[0]})}replaceAcceptedIf(e,t,r,s){return this.replace(e,{other:this.validator.getDisplayableAttribute(s[0]),value:this.validator.getDisplayableValue(s[0],this.validator.getValue(s[0]))})}replaceDeclinedIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredArrayKeys(e,t,r,s){return this.replace(e,{values:s.map((e=>this.validator.getDisplayableValue(t,e))).join(", ")})}replaceRequiredIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredIfAccepted(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredUnless(e,t,r,s){return this.replace(e,{other:this.validator.getDisplayableAttribute(s[0]),values:s.slice(1).map((e=>this.validator.getDisplayableValue(s[0],e))).join(", ")})}replaceRequiredWith(e,t,r,s){return this.replace(e,{values:s.map((e=>this.validator.getDisplayableAttribute(e))).join(" / ")})}replaceRequiredWithAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceRequiredWithout(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceRequiredWithoutAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceMissingIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceMissingUnless(e,t,r,s){return this.replace(this.replaceRequiredUnless(e,t,r,s),{value:this.validator.getDisplayableValue(s[0],s[1])})}replaceMissingWith(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceMissingWithAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceProhibitedIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceProhibitedUnless(e,t,r,s){return this.replaceRequiredUnless(e,t,r,s)}replaceProhibits(e,t,r,s){return this.replace(e,{other:s.map((e=>this.validator.getDisplayableAttribute(e))).join(" / ")})}replaceSize(e,t,r,s){return this.replace(e,{size:s[0]})}replaceMin(e,t,r,s){return this.replace(e,{min:s[0]})}replaceMax(e,t,r,s){return this.replace(e,{max:s[0]})}replaceBetween(e,t,r,s){return this.replace(e,{min:s[0],max:s[1]})}replaceDigits(e,t,r,s){return this.replace(e,{digits:s[0]})}replaceMinDigits(e,t,r,s){return this.replaceMin(e,t,r,s)}replaceMaxDigits(e,t,r,s){return this.replaceMax(e,t,r,s)}replaceDigitsBetween(e,t,r,s){return this.replaceBetween(e,t,r,s)}replaceStartsWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceDoesntStartWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceEndsWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceDoesntEndWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceSame(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceDifferent(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceGt(e,t,r,s){const i=this.validator.getValue(s[0]);return this.replace(e,{value:i?this.validator.getSize(s[0],i):this.validator.getDisplayableAttribute(s[0])})}replaceGte(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceLt(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceLte(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceAfter(e,t,r,s){const i=s[0];return this.replace(e,{date:this.validator.hasAttribute(i)?this.validator.getDisplayableAttribute(i):i})}replaceAfterOrEqual(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceBefore(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceBeforeOrEqual(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceDateEquals(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceDateFormat(e,t,r,s){return this.replace(e,{format:s[0]})}replaceInArray(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceIn(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceNotIn(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceMimetypes(e,t,r,s){return this.replace(e,{values:s.join(", ")})}replaceMimes(e,t,r,s){return this.replaceMimetypes(e,t,r,s)}replaceExtensions(e,t,r,s){return this.replaceMimetypes(e,t,r,s)}}class g{static#a={};static#c={};static#n=["active_url","bail","can","current_password","enum","exclude","exclude_if","exclude_unless","exclude_with","exclude_without","exists","nullable","sometimes","unique"];static#l=["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"];#r;#h;#u;#o;#d;#p;#f;#g;#m;#k;#b;static setLocale(e){p.locale(e)}static setMessages(e,t){p.setMessages(e,t)}static addChecker(e,t,r){g.#a[e]=t,r&&p.set(e,r)}static addImplicitChecker(e,t,r){g.addChecker(e,t,r),g.#l.push(e)}static addReplacer(e,t){g.#c[e]=t}static addDummyRule(e){g.#n.push(e)}constructor(e={},r={},s={},i={},a={}){this.#m={},this.#k=!1,this.#b=!1,this.fileRules=["file","image","mimetypes","mimes"],this.numericRules=["decimal","numeric","integer"],this.sizeRules=["size","between","min","max","gt","lt","gte","lte"],this.setProperties(e,r,s,i,a),this.#p=new o(this),this.#f=new f(this);for(const[e,r]of Object.entries(g.#a))this.#p[t("check_"+e)]=r;for(const[e,r]of Object.entries(g.#c))this.#f[t("replace_"+e)]=r;this.#g=new d}setProperties(e={},t={},r={},i={},a={}){return this.#r=e,this.#h=this.parseRules(t),this.#u=r,this.#o=i,this.#d=s(a),this}setData(e){return this.#r=e,this}setRules(e){return this.#h=this.parseRules(e),this}setCustomMessages(e){return this.#u=e,this}setCustomAttributes(e){return this.#o=e,this}setCustomValues(e){return this.#d=s(e),this}addImplicitAttribute(e,t){return this.#m[e]=t,this}stopOnFirstFailure(e=!0){return this.#k=e,this}alwaysBail(e=!0){return this.#b=e,this}parseRules(e){const t={};for(const[r,s]of Object.entries(e)){const e=r.includes("*")?this.parseWildcardAttribute(r):[r];for(const r of e){const e={};for(const t of this.parseAttributeRules(s)){const[r,s]=this.parseAttributeRule(t);e[r]=s}t[r]=e}}return t}parseWildcardAttribute(e){const t=[],r=e.indexOf("*"),s=e.substring(0,r-1),i=e.substring(r+2),a=this.getValue(s);return Array.isArray(a)||h(a)?(Object.entries(a).forEach((([r,a])=>{const c=`${s}.${r}.${i}`.replace(/\.$/,""),n=c.includes("*")?this.parseWildcardAttribute(c):[c];t.push(...n),n.forEach((t=>this.#m[t]=e))})),t):[e]}parseAttributeRules(e){return Array.isArray(e)?e:String(e).split("|")}parseAttributeRule(e){if(Array.isArray(e))return[e.shift()??"",e];const t=e.indexOf(":");return-1===t?[e,[]]:[e.substring(0,t),i(e.substring(t+1))]}async validate(){this.#p.clearCaches(),this.#g=new d;const e=[];for(const[r,s]of Object.entries(this.#h)){let i=this.getValue(r);Object.hasOwn(s,"sometimes")&&void 0===i||e.push((async()=>{const e=this.#b||Object.hasOwn(s,"bail"),a=Object.hasOwn(s,"nullable");let c=!0;for(const[l,h]of Object.entries(s)){if(""===l)continue;if(!g.#l.includes(l)&&(void 0===i||"string"==typeof i&&""===i.trim()||a&&null===i))continue;let s,u,o;const d=t("check_"+l);if("function"==typeof this.#p[d])s=await this.#p[d](r,i,h);else{if(!g.#n.includes(l))throw new Error(`Invalid validation rule: ${l}`);s=!0}if("boolean"==typeof s?u=s:({success:u,message:o}=s),!u&&(c=!1,o=n(o)?this.getMessage(r,l):o,o=this.makeReplacements(o,r,l,h),this.#g.add(r,o),e||g.#l.includes(l)))break}return c}))}if(this.#k){for(const t of e)if(!await t())break}else await Promise.allSettled(e.map((e=>e()))),this.#g.sortByKeys(Object.keys(this.#h));return this.#g}async passes(){return await this.validate(),!this.#g.isNotEmpty()}async fails(){return!await this.passes()}getMessage(e,t){const r=this.getValue(e);let s;e=this.getPrimaryAttribute(e);for(const r of[`${e}.${t}`,t])if(Object.hasOwn(this.#u,r)){s=this.#u[r];break}if(!s){let i=t;this.sizeRules.includes(i)&&(Array.isArray(r)||h(r)||this.hasRule(e,"array")?i+=".array":r instanceof File||this.hasRule(e,this.fileRules)?i+=".file":l(r)||this.hasRule(e,this.numericRules)?i+=".numeric":i+=".string"),s=p.get(i)}return s??`validation.${t}`}makeReplacements(e,r,s,i){const a=this.getDisplayableAttribute(r),c=this.getValue(r),n={attribute:a,ATTRIBUTE:a.toLocaleUpperCase(),Attribute:a.charAt(0).toLocaleUpperCase()+a.substring(1),input:this.getDisplayableValue(r,c)};for(const[t,r]of Object.entries(n))e=e.replaceAll(":"+t,r);const l=r.match(/\.(\d+)\.?/),h=null===l?-1:parseInt(l[1],10);-1!==h&&(e=e.replaceAll(":index",h).replaceAll(":position",h+1));const u=t("replace_"+s);return"function"==typeof this.#f[u]&&(e=this.#f[u](e,r,s,i)),e}getDisplayableAttribute(e){const t=this.getPrimaryAttribute(e);for(const r of[e,t]){if(Object.hasOwn(this.#o,r))return this.#o[r];if(p.has(`attributes.${r}`))return p.get(`attributes.${r}`)}return Object.hasOwn(this.#m,e)?e:(r=e,r.replace(/(.)(?=[A-Z])/g,(e=>e+"_")).toLowerCase()).replaceAll("_"," ");var r}getDisplayableValue(e,t){const r=`${e=this.getPrimaryAttribute(e)}.${t}`;return n(t)?"empty":"boolean"==typeof t||this.hasRule(e,"boolean")?Number(t)?"true":"false":Object.hasOwn(this.#d,r)?this.#d[r]:p.has(`values.${r}`)?p.get(`values.${r}`):t}getSize(e,t){return n(t)?0:l(t)&&this.hasRule(e,this.numericRules)?parseFloat("string"==typeof t?t.trim():t,10):t instanceof File?t.size/1024:h(t)?Object.keys(t).length:Object.hasOwn(t,"length")?t.length:t}getRule(e){return e=this.getPrimaryAttribute(e),this.#h[e]??{}}hasRule(e,t){if(e=this.getPrimaryAttribute(e),t="string"==typeof t?[t]:t,!Object.hasOwn(this.#h,e))return!1;for(const r of t)if(this.#h[e].hasOwnProperty(r))return!0;return!1}getPrimaryAttribute(e){return Object.hasOwn(this.#m,e)?this.#m[e]:e}hasAttribute(e){return void 0!==this.getValue(e)}getValue(e){return function(e,t,r){const s=t.split(".");let i=e;for(const e of s){if(!Object.hasOwn(i,e))return r;i=i[e]}return i}(this.#r,e)}errors(){return this.#g}}return e.Checkers=o,e.ErrorBag=d,e.Lang=p,e.Replacers=f,e.Validator=g,e}({});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quival",
3
- "version": "0.2.8",
3
+ "version": "0.3.0",
4
4
  "description": "Data validation à la Laravel Validation",
5
5
  "author": "Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>",
6
6
  "license": "MIT",
package/src/Checkers.js CHANGED
@@ -91,7 +91,7 @@ export default class Checkers {
91
91
  compareDates(attribute, value, parameters, callback) {
92
92
  const rule = this.validator.getRule(attribute);
93
93
 
94
- value = rule.hasOwnProperty('date_format') ? parseDateByFormat(value, rule.date_format[0]) : parseDate(value);
94
+ value = Object.hasOwn(rule, 'date_format') ? parseDateByFormat(value, rule.date_format[0]) : parseDate(value);
95
95
 
96
96
  if (!isValidDate(value)) {
97
97
  return false;
@@ -105,7 +105,7 @@ export default class Checkers {
105
105
  } else {
106
106
  const otherRule = this.validator.getRule(other);
107
107
 
108
- otherValue = otherRule.hasOwnProperty('date_format') ? parseDateByFormat(otherValue, otherRule.date_format[0]) : parseDate(otherValue);
108
+ otherValue = Object.hasOwn(otherRule, 'date_format') ? parseDateByFormat(otherValue, otherRule.date_format[0]) : parseDate(otherValue);
109
109
  }
110
110
 
111
111
  if (!isValidDate(otherValue)) {
@@ -573,7 +573,7 @@ export default class Checkers {
573
573
  let pattern = '^';
574
574
 
575
575
  for (const char of format) {
576
- if (formats.hasOwnProperty(char)) {
576
+ if (Object.hasOwn(formats, char)) {
577
577
  pattern += formats[char];
578
578
  } else {
579
579
  pattern += '\\' + char;
@@ -598,7 +598,7 @@ export default class Checkers {
598
598
 
599
599
  let stringified;
600
600
 
601
- if (this.#distinctCache.hasOwnProperty(parentPath)) {
601
+ if (Object.hasOwn(this.#distinctCache, parentPath)) {
602
602
  stringified = this.#distinctCache[parentPath];
603
603
  } else {
604
604
  stringified = JSON.stringify(flattenObject(this.validator.getValue(parentPath) ?? {}));
@@ -709,7 +709,7 @@ export default class Checkers {
709
709
  }
710
710
 
711
711
  async checkDimensions(attribute, value, parameters) {
712
- if (!this.checkImage(attribute, value) || !this.#imageCache.hasOwnProperty(attribute)) {
712
+ if (!this.checkImage(attribute, value) || !Object.hasOwn(this.#imageCache, attribute)) {
713
713
  return false;
714
714
  }
715
715
 
@@ -732,17 +732,17 @@ export default class Checkers {
732
732
  const height = image.naturalHeight;
733
733
 
734
734
  if (
735
- (constraints.hasOwnProperty('width') && constraints.width !== width) ||
736
- (constraints.hasOwnProperty('height') && constraints.height !== height) ||
737
- (constraints.hasOwnProperty('min_width') && constraints.min_width > width) ||
738
- (constraints.hasOwnProperty('min_height') && constraints.min_height > height) ||
739
- (constraints.hasOwnProperty('max_width') && constraints.max_width < width) ||
740
- (constraints.hasOwnProperty('max_height') && constraints.max_height < height)
735
+ (Object.hasOwn(constraints, 'width') && constraints.width !== width) ||
736
+ (Object.hasOwn(constraints, 'height') && constraints.height !== height) ||
737
+ (Object.hasOwn(constraints, 'min_width') && constraints.min_width > width) ||
738
+ (Object.hasOwn(constraints, 'min_height') && constraints.min_height > height) ||
739
+ (Object.hasOwn(constraints, 'max_width') && constraints.max_width < width) ||
740
+ (Object.hasOwn(constraints, 'max_height') && constraints.max_height < height)
741
741
  ) {
742
742
  return false;
743
743
  }
744
744
 
745
- if (constraints.hasOwnProperty('ratio')) {
745
+ if (Object.hasOwn(constraints, 'ratio')) {
746
746
  return Math.abs(constraints.ratio - width / height) <= 1 / (Math.max(width, height) + 1);
747
747
  }
748
748
 
package/src/ErrorBag.js CHANGED
@@ -14,7 +14,7 @@ export default class ErrorBag {
14
14
  }
15
15
 
16
16
  add(key, message) {
17
- if (this.#data.hasOwnProperty(key)) {
17
+ if (Object.hasOwn(this.#data, key)) {
18
18
  this.#data[key].push(message);
19
19
  } else {
20
20
  this.#data[key] = [message];
@@ -23,7 +23,7 @@ export default class ErrorBag {
23
23
 
24
24
  get(key) {
25
25
  if (!key.includes('*')) {
26
- return this.#data.hasOwnProperty(key) ? this.#data[key] : {};
26
+ return Object.hasOwn(this.#data, key) ? this.#data[key] : {};
27
27
  }
28
28
 
29
29
  const pattern = new RegExp('^' + key.replaceAll('*', '.*?') + '$');
@@ -77,4 +77,16 @@ export default class ErrorBag {
77
77
  isNotEmpty() {
78
78
  return !this.isEmpty();
79
79
  }
80
+
81
+ sortByKeys(keys) {
82
+ const data = {};
83
+
84
+ for (const key of keys) {
85
+ if (Object.hasOwn(this.#data, key)) {
86
+ data[key] = this.#data[key];
87
+ }
88
+ }
89
+
90
+ this.#data = data;
91
+ }
80
92
  }