quival 0.5.5 → 0.5.6

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * quival v0.5.5 (git+https://github.com/apih/quival.git)
2
+ * quival v0.5.6 (git+https://github.com/apih/quival.git)
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.5.5 (git+https://github.com/apih/quival.git)
2
+ * quival v0.5.6 (git+https://github.com/apih/quival.git)
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.5.5 (git+https://github.com/apih/quival.git)
2
+ * quival v0.5.6 (git+https://github.com/apih/quival.git)
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.5.5 (git+https://github.com/apih/quival.git)
2
+ * quival v0.5.6 (git+https://github.com/apih/quival.git)
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.5.5 (git+https://github.com/apih/quival.git)
2
+ * quival v0.5.6 (git+https://github.com/apih/quival.git)
3
3
  * (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
4
4
  * Released under the MIT License.
5
5
  */
@@ -111,27 +111,27 @@ var quival = (function (exports) {
111
111
  }
112
112
  return buildDate(years, months, days, hours, minutes, seconds, meridiem);
113
113
  }
114
+ const DATE_FORMAT_PATTERNS = {
115
+ Y: '(\\d{4})',
116
+ y: '(\\d{2})',
117
+ m: '(\\d{2})',
118
+ n: '([1-9]\\d?)',
119
+ d: '(\\d{2})',
120
+ j: '([1-9]\\d?)',
121
+ G: '([1-9]\\d?)',
122
+ g: '([1-9]\\d?)',
123
+ H: '(\\d{2})',
124
+ h: '(\\d{2})',
125
+ i: '(\\d{2})',
126
+ s: '(\\d{2})',
127
+ A: '(AM|PM)',
128
+ a: '(am|pm)',
129
+ };
114
130
  function parseDateByFormat(value, format) {
115
131
  if (isEmpty(value)) {
116
132
  return new Date('');
117
133
  }
118
134
  format = format.split('');
119
- const formats = {
120
- Y: '(\\d{4})',
121
- y: '(\\d{2})',
122
- m: '(\\d{2})',
123
- n: '([1-9]\\d?)',
124
- d: '(\\d{2})',
125
- j: '([1-9]\\d?)',
126
- G: '([1-9]\\d?)',
127
- g: '([1-9]\\d?)',
128
- H: '(\\d{2})',
129
- h: '(\\d{2})',
130
- i: '(\\d{2})',
131
- s: '(\\d{2})',
132
- A: '(AM|PM)',
133
- a: '(am|pm)',
134
- };
135
135
  let pattern = '^';
136
136
  let indices = {
137
137
  years: -1,
@@ -144,8 +144,8 @@ var quival = (function (exports) {
144
144
  };
145
145
  let index = 1;
146
146
  for (const char of format) {
147
- if (Object.hasOwn(formats, char)) {
148
- pattern += formats[char];
147
+ if (Object.hasOwn(DATE_FORMAT_PATTERNS, char)) {
148
+ pattern += DATE_FORMAT_PATTERNS[char];
149
149
  if (['Y', 'y'].indexOf(char) !== -1) {
150
150
  indices.years = index++;
151
151
  } else if (['m', 'n'].indexOf(char) !== -1) {
@@ -232,35 +232,18 @@ var quival = (function (exports) {
232
232
  const other = this.validator.getValue(parameters[0]);
233
233
  return parameters.slice(1).some((value) => value == other);
234
234
  }
235
+ collectAndTest(checker, attribute, value, parameters, callback) {
236
+ const result = parameters.map((other) => checker(other, this.validator.getValue(other)));
237
+ return callback(result) ? checker(attribute, value) : true;
238
+ }
235
239
  collectRequiredsThenTest(attribute, value, parameters, callback) {
236
- let result = [];
237
- for (const other of parameters) {
238
- result.push(this.checkRequired(other, this.validator.getValue(other)));
239
- }
240
- if (callback(result)) {
241
- return this.checkRequired(attribute, value);
242
- }
243
- return true;
240
+ return this.collectAndTest(this.checkRequired, attribute, value, parameters, callback);
244
241
  }
245
242
  collectPresentsThenTest(attribute, value, parameters, callback) {
246
- let result = [];
247
- for (const other of parameters) {
248
- result.push(this.checkPresent(other, this.validator.getValue(other)));
249
- }
250
- if (callback(result)) {
251
- return this.checkPresent(attribute, value);
252
- }
253
- return true;
243
+ return this.collectAndTest(this.checkPresent, attribute, value, parameters, callback);
254
244
  }
255
245
  collectMissingsThenTest(attribute, value, parameters, callback) {
256
- let result = [];
257
- for (const other of parameters) {
258
- result.push(this.checkMissing(other, this.validator.getValue(other)));
259
- }
260
- if (callback(result)) {
261
- return this.checkMissing(attribute, value);
262
- }
263
- return true;
246
+ return this.collectAndTest(this.checkMissing, attribute, value, parameters, callback);
264
247
  }
265
248
  testStringUsingRegex(attribute, value, asciiRegex, unicodeRegex, isAscii = false) {
266
249
  if (typeof value !== 'string' && typeof value !== 'number') {
@@ -346,7 +329,7 @@ var quival = (function (exports) {
346
329
  }
347
330
  checkInteger(attribute, value, parameters = []) {
348
331
  if (!parameters.includes('strict') && typeof value === 'string') {
349
- value = parseFloat(value);
332
+ value = Number(value);
350
333
  }
351
334
  return Number.isInteger(value);
352
335
  }
@@ -683,26 +666,10 @@ var quival = (function (exports) {
683
666
  }
684
667
  checkDateFormat(attribute, value, parameters) {
685
668
  const format = parameters[0].split('');
686
- const formats = {
687
- Y: '(\\d{4})',
688
- y: '(\\d{2})',
689
- m: '(\\d{2})',
690
- n: '([1-9]\\d?)',
691
- d: '(\\d{2})',
692
- j: '([1-9]\\d?)',
693
- G: '([1-9]\\d?)',
694
- g: '([1-9]\\d?)',
695
- H: '(\\d{2})',
696
- h: '(\\d{2})',
697
- i: '(\\d{2})',
698
- s: '(\\d{2})',
699
- A: '(AM|PM)',
700
- a: '(am|pm)',
701
- };
702
669
  let pattern = '^';
703
670
  for (const char of format) {
704
- if (Object.hasOwn(formats, char)) {
705
- pattern += formats[char];
671
+ if (Object.hasOwn(DATE_FORMAT_PATTERNS, char)) {
672
+ pattern += DATE_FORMAT_PATTERNS[char];
706
673
  } else {
707
674
  pattern += '\\' + char;
708
675
  }
@@ -715,8 +682,9 @@ var quival = (function (exports) {
715
682
  if (!this.checkArray(attribute, value)) {
716
683
  return false;
717
684
  }
685
+ const values = Array.isArray(value) ? value : Object.values(value);
718
686
  for (const parameter of parameters) {
719
- if (!value.includes(parameter)) {
687
+ if (!values.some((item) => item == parameter)) {
720
688
  return false;
721
689
  }
722
690
  }
@@ -726,8 +694,9 @@ var quival = (function (exports) {
726
694
  if (!this.checkArray(attribute, value)) {
727
695
  return false;
728
696
  }
697
+ const values = Array.isArray(value) ? value : Object.values(value);
729
698
  for (const parameter of parameters) {
730
- if (value.includes(parameter)) {
699
+ if (values.some((item) => item == parameter)) {
731
700
  return false;
732
701
  }
733
702
  }
@@ -843,10 +812,10 @@ var quival = (function (exports) {
843
812
  for (const parameter of parameters) {
844
813
  const [key, value] = parameter.split('=', 2);
845
814
  if (key === 'ratio' && value.includes('/')) {
846
- const [numerator, denominator] = value.split('/', 2).map((part) => parseFloat(part, 10));
815
+ const [numerator, denominator] = value.split('/', 2).map((part) => parseFloat(part));
847
816
  constraints[key] = numerator / denominator;
848
817
  } else {
849
- constraints[key] = parseFloat(value, 10);
818
+ constraints[key] = parseFloat(value);
850
819
  }
851
820
  }
852
821
  const image = this.#imageCache[attribute];
@@ -970,7 +939,7 @@ var quival = (function (exports) {
970
939
  return true;
971
940
  }
972
941
  checkUlid(attribute, value, parameters) {
973
- return /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/.test(value);
942
+ return /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i.test(value);
974
943
  }
975
944
  checkUuid(attribute, value, parameters) {
976
945
  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(value);
@@ -1090,11 +1059,14 @@ var quival = (function (exports) {
1090
1059
  }
1091
1060
  replaceCaseVariants(message, data) {
1092
1061
  Object.entries(data)
1093
- .flatMap(([key, value]) => [
1094
- [key, value],
1095
- [key.toLocaleUpperCase(), value.toLocaleUpperCase()],
1096
- [key.charAt(0).toLocaleUpperCase() + key.substring(1), value.charAt(0).toLocaleUpperCase() + value.substring(1)],
1097
- ])
1062
+ .flatMap(([key, value]) => {
1063
+ value = String(value);
1064
+ return [
1065
+ [key, value],
1066
+ [key.toLocaleUpperCase(), value.toLocaleUpperCase()],
1067
+ [key.charAt(0).toLocaleUpperCase() + key.substring(1), value.charAt(0).toLocaleUpperCase() + value.substring(1)],
1068
+ ];
1069
+ })
1098
1070
  .forEach(([key, value]) => (message = message.replaceAll(':' + key, value)));
1099
1071
  return message;
1100
1072
  }
@@ -1257,7 +1229,7 @@ var quival = (function (exports) {
1257
1229
  replaceGt(message, attribute, rule, parameters) {
1258
1230
  const value = this.validator.getValue(parameters[0]);
1259
1231
  return this.replace(message, {
1260
- value: value ? this.validator.getSize(parameters[0], value) : this.validator.getDisplayableAttribute(parameters[0]),
1232
+ value: typeof value === 'undefined' ? this.validator.getDisplayableAttribute(parameters[0]) : this.validator.getSize(parameters[0], value),
1261
1233
  });
1262
1234
  }
1263
1235
  replaceGte(message, attribute, rule, parameters) {
@@ -1723,7 +1695,7 @@ var quival = (function (exports) {
1723
1695
  } else if (this.hasRule(attribute, this.stringRules)) {
1724
1696
  return String(value).length;
1725
1697
  } else if (isNumeric(value) && this.hasRule(attribute, this.numericRules)) {
1726
- return parseFloat(typeof value === 'string' ? value.trim() : value, 10);
1698
+ return parseFloat(typeof value === 'string' ? value.trim() : value);
1727
1699
  } else if (value instanceof File) {
1728
1700
  return value.size / 1024;
1729
1701
  } else if (isPlainObject(value)) {
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * quival v0.5.5 (git+https://github.com/apih/quival.git)
2
+ * quival v0.5.6 (git+https://github.com/apih/quival.git)
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";const t=e=>e&&/^\d*$/.test(e)?parseInt(e):e,r=(e,t,r,s,i,c,a)=>(e>=10&&e<100&&(e+=2e3),null!==a&&("pm"===(a=a.toLowerCase())&&s<12?s+=12:"am"===a&&12===s&&(s=0)),new Date(`${e}-${t}-${r} ${s}:${i}:${c}`));function s(e){return e.replace(/[-_]/g," ").replace(/\s+/g," ").trim().replace(/(\s\w)/g,e=>e[1].toUpperCase())}function i(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function c(e,t=""){return Object.keys(e).reduce((r,s)=>{const i=t?`${t}.${s}`:s;return"object"==typeof e[s]&&null!==e[s]?Object.assign(r,c(e[s],i)):r[i]=e[s],r},{})}function a(e){if(e instanceof Date)return e;if(u(e)||"string"!=typeof e)return new Date("");let s,i,c,a,n,l,h,o;if(null!==(s=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)))[,a,c,i,,n=0,l=0,,h=0,o=null]=s.map(t);else if(null!==(s=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!==(s=e.match(/^(\d{4})(\d{2})(\d{2})\s?((\d{2})(\d{2})((\d{2}))?\s?(am|pm)?)?/i)))[,i,c,a,,n=0,l=0,,h=0,o=null]=s.map(t);else if(s=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{4})[.\/-](\d{2})[.\/-](\d{2})/i))[,n,l,,h,o=null,i,c,a]=s.map(t);else if(s=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{2})[.\/-](\d{2})[.\/-](\d{4})/i))[,n,l,,h,o=null,a,c,i]=s.map(t);else{if(!(s=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?/i)))return new Date(e);{const e=new Date;i=e.getFullYear(),c=e.getMonth()+1,a=e.getDate(),[,n=0,l=0,,h=0,o=null]=s.map(t)}}return r(i,c,a,n,l,h,o)}function n(e,s){if(u(e))return new Date("");s=s.split("");const 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 c="^",a={years:-1,months:-1,days:-1,hours:-1,minutes:-1,seconds:-1,meridiem:-1},n=1;for(const e of s)Object.hasOwn(i,e)?(c+=i[e],-1!==["Y","y"].indexOf(e)?a.years=n++:-1!==["m","n"].indexOf(e)?a.months=n++:-1!==["d","j"].indexOf(e)?a.days=n++:-1!==["G","g","H","h"].indexOf(e)?a.hours=n++:"i"===e?a.minutes=n++:"s"===e?a.seconds=n++:-1!==["A","a"].indexOf(e)&&(a.meridiem=n++)):c+="\\"+e;c+="$";let l=e.match(new RegExp(c));if(null===l)return new Date("");l=l.map(t);const h=new Date;let o=l[a.years],p=l[a.months],d=l[a.days],f=l[a.hours]??0,g=l[a.minutes]??0,m=l[a.seconds]??0,k=l[a.meridiem]??null;return o||p||d?!o||p||d?o||!p||d?o||p||!d||(o=h.getFullYear(),p=h.getMonth()+1):(o=h.getFullYear(),d=1):(p=1,d=1):(o=h.getFullYear(),p=h.getMonth()+1,d=h.getDate()),r(o,p,d,f,g,m,k)}function l(e){return(String(e).split(".")[1]??"").length}function u(e){return""===e||null==e}function h(e){const t=Number(e);return null!==e&&"boolean"!=typeof e&&"number"==typeof t&&!isNaN(t)}function o(e){return"[object Object]"===Object.prototype.toString.call(e)}function p(e){return e instanceof Date&&"Invalid Date"!==e.toDateString()}class d{#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)}collectPresentsThenTest(e,t,r,s){let i=[];for(const e of r)i.push(this.checkPresent(e,this.validator.getValue(e)));return!s(i)||this.checkPresent(e,t)}collectMissingsThenTest(e,t,r,s){let i=[];for(const e of r)i.push(this.checkMissing(e,this.validator.getValue(e)));return!s(i)||this.checkMissing(e,t)}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(u(t))return!1;const i=r[0]??"";let c=this.validator.getValue(i);return c=void 0===c?h(i)?parseFloat(i):null:this.validator.getSize(i,c),!u(c)&&s(this.validator.getSize(e,t),c)}compareDates(e,t,r,s){const i=this.validator.getRule(e),c=Array.isArray(i)?i.find(([e])=>"date_format"===e):null,l=c?c[1][0]:null;if(!p(t=l?n(t,l):a(t)))return!1;const u=r[0]??"";let h=this.validator.getValue(u);if(void 0===h)h=l?n(u,l):a(u);else{const e=this.validator.getRule(u),t=Array.isArray(e)?e.find(([e])=>"date_format"===e):null,r=t?t[1][0]:null;h=r?n(h,r):a(h)}return!!p(h)&&s(t.getTime(),h.getTime())}checkArray(e,t,r=[]){if(!Array.isArray(t)&&!o(t))return!1;if(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 r.includes("strict")?[!0,!1].includes(t):[!0,!1,0,1,"0","1"].includes(t)}checkDate(e,t,r){return p(a(t))}checkFile(e,t,r){return t instanceof File}checkInteger(e,t,r=[]){return r.includes("strict")||"string"!=typeof t||(t=parseFloat(t)),Number.isInteger(t)}checkNumeric(e,t,r=[]){return r.includes("strict")?"number"==typeof t:h(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(!h(t)||!h(r[0]))return!1;const s=Number(t),i=Number(r[0]);if(0===s&&0===i)return!1;if(0===s)return!0;if(0===i)return!1;const c=10**Math.max(l(s),l(i));return Math.round(s*c)%Math.round(i*c)===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!u(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)}checkRequiredIfDeclined(e,t,r){return!this.checkDeclined(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}checkPresentIf(e,t,r){return!this.isDependent(r)||this.checkPresent(e,t)}checkPresentUnless(e,t,r){return!!this.isDependent(r)||this.checkPresent(e,t)}checkPresentWith(e,t,r){return this.collectPresentsThenTest(e,t,r,e=>e.includes(!0))}checkPresentWithAll(e,t,r){return this.collectPresentsThenTest(e,t,r,e=>!e.includes(!1))}checkMissing(e,t,r){return void 0===t}checkMissingIf(e,t,r){return!this.isDependent(r)||this.checkMissing(e,t)}checkMissingUnless(e,t,r){return!!this.isDependent(r)||this.checkMissing(e,t)}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&&!h(t))return!1;const i=r.join(",");let[c,a,n]=i.match(/^\/(.*)\/([gimu]*)$/)??[];if(u(c))throw new Error(`Invalid regular expression pattern: ${i}`);n.includes("u")&&(a=a.replace(/\\A/g,"^").replace(/\\z/gi,"$").replace(/\\([pP])([CLMNPSZ])/g,"\\$1{$2}").replace(/\\\x\{([0-9a-f]+)\}/g,"\\u{$1}"));const l=new RegExp(a,n).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,[r[0]??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 c="^";for(const e of s)Object.hasOwn(i,e)?c+=i[e]:c+="\\"+e;return c+="$",new RegExp(c).test(t)}checkContains(e,t,r=[]){if(!this.checkArray(e,t))return!1;for(const e of r)if(!t.includes(e))return!1;return!0}checkDoesntContain(e,t,r=[]){if(!this.checkArray(e,t))return!1;for(const e of r)if(t.includes(e))return!1;return!0}checkDistinct(e,t,r){const s=this.validator.getPrimaryAttribute(e);if(!s.includes("*"))return!0;const a=s.indexOf("*"),n=s.substring(0,a-1);let l;Object.hasOwn(this.#e,n)?l=this.#e[n]:(l=JSON.stringify(c(this.validator.getValue(n)??{})),this.#e[n]=l);const u=r.includes("ignore_case"),h=!u&&r.includes("strict"),o=i(String(t));let p=`"${i(s.substring(a)).replaceAll("\\*",'[^."]+')}":`,d=0;return p+=h?"string"==typeof t?`"${o}"`:`${o}`:`(${o}|"${o}")`,p+="[,}]+",d+=l.match(new RegExp(p,"g"+(u?"i":"")))?.length??0,1===d}checkInArray(e,t,r){const s=this.validator.getPrimaryAttribute(r[0]);if(!s.includes("*"))return!1;const i=this.validator.getValue(s.split(".*")[0])??{};return Object.values(c(i)).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("jpg")&&!r.includes("jpeg")&&r.push("jpeg"),r.includes("jpeg")&&!r.includes("jpg")&&r.push("jpg"),r.includes(t.name.split(".").pop().toLowerCase()))}checkExtensions(e,t,r){return this.checkMimes(e,t,r)}async checkImage(e,t,r=[]){const s=["jpg","jpeg","png","gif","bmp","webp"];r.includes("allow_svg")&&s.push("svg");let i=this.checkMimes(e,t,s);return i&&"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(()=>{i=!1}),i):i}async checkDimensions(e,t,r=[]){if(!await 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],c=i.naturalWidth,a=i.naturalHeight;return!(Object.hasOwn(s,"width")&&s.width!==c||Object.hasOwn(s,"height")&&s.height!==a||Object.hasOwn(s,"min_width")&&s.min_width>c||Object.hasOwn(s,"min_height")&&s.min_height>a||Object.hasOwn(s,"max_width")&&s.max_width<c||Object.hasOwn(s,"max_height")&&s.max_height<a)&&(!Object.hasOwn(s,"ratio")||Math.abs(s.ratio-c/a)<=1/(Math.max(c,a)+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,c;for([i,c]of Object.entries(s))if(t.includes(i))break;const a=t.split(i);if(a.length!==12/c)return!1;for(const e of a)if(!new RegExp("^[0-9a-f]{"+c+"}$","i").test(e))return!1;return!0}checkIpv4(e,t,r){if(/[^\d.]/.test(t))return!1;const s=String(t).split(".").map(e=>parseInt(e,10));if(4!==s.length)return!1;for(const e of s)if(isNaN(e)||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(e instanceof RangeError)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 f{#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)}remove(e){delete this.#r[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 g{static#s;static#i={};static locale(e){this.#s=e}static setMessages(e,t){this.#i[e]=c(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){o(t)?Object.assign(this.#i[this.#s],c(t,e)):"string"==typeof t&&(this.#i[this.#s][e]=t)}}class m{constructor(e){this.validator=e}replace(e,t){return Object.entries(t).forEach(([t,r])=>e=e.replaceAll(":"+t,r)),e}replaceCaseVariants(e,t){return Object.entries(t).flatMap(([e,t])=>[[e,t],[e.toLocaleUpperCase(),t.toLocaleUpperCase()],[e.charAt(0).toLocaleUpperCase()+e.substring(1),t.charAt(0).toLocaleUpperCase()+t.substring(1)]]).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.replaceCaseVariants(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)}replaceRequiredIfDeclined(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredUnless(e,t,r,s){return this.replaceCaseVariants(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.replaceCaseVariants(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)}replacePresentIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replacePresentUnless(e,t,r,s){return this.replaceCaseVariants(this.replaceRequiredUnless(e,t,r,s),{value:this.validator.getDisplayableValue(s[0],s[1])})}replacePresentWith(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replacePresentWithAll(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.replacePresentUnless(e,t,r,s)}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.replaceCaseVariants(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)}replaceDoesntContain(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 k{static#c={};static#a={};static#n=["active_url","bail","can","current_password","encoding","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","present_if","present_unless","present_with","present_with_all","required","required_if","required_if_accepted","required_if_declined","required_unless","required_with","required_with_all","required_without","required_without_all"];#r;#u;#h;#o;#p;#d;#f;#g;#m;#k;#A;#y;static setLocale(e){g.locale(e)}static setMessages(e,t){g.setMessages(e,t)}static addChecker(e,t,r){k.#c[e]=t,r&&g.set(e,r)}static addImplicitChecker(e,t,r){k.addChecker(e,t,r),k.#l.push(e)}static addReplacer(e,t){k.#a[e]=t}static addDummyRule(e){k.#n.push(e)}constructor(e={},t={},r={},i={},c={}){this.#m=[],this.#k={},this.#A=!1,this.#y=!1,this.arrayRules=["array","list"],this.fileRules=["file","image","mimetypes","mimes"],this.stringRules=["string","alpha","alpha_dash","alpha_num","ascii","email"],this.numericRules=["decimal","numeric","integer"],this.sizeRules=["size","between","min","max","gt","lt","gte","lte"],this.setProperties(e,t,r,i,c),this.#d=new d(this),this.#f=new m(this);for(const[e,t]of Object.entries(k.#c))this.#d[s("check_"+e)]=t;for(const[e,t]of Object.entries(k.#a))this.#f[s("replace_"+e)]=t;this.#g=new f}setProperties(e={},t={},r={},s={},i={}){return this.#r=e,this.#u=this.parseRules(t),this.#h=r,this.#o=s,this.#p=c(i),this}setData(e){return this.#r=e,this}setRules(e){return this.#u=this.parseRules(e),this}setCustomMessages(e){return this.#h=e,this}setCustomAttributes(e){return this.#o=e,this}setCustomValues(e){return this.#p=c(e),this}addImplicitAttribute(e,t){return this.#k[e]=t,this}stopOnFirstFailure(e=!0){return this.#A=e,this}alwaysBail(e=!0){return this.#y=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))e.push(this.parseAttributeRule(t));t[r]=e}}return t}parseWildcardAttribute(e){const t=[],r=e.indexOf("*"),s=e.substring(0,r-1),i=e.substring(r+2),c=this.getValue(s);return Array.isArray(c)||o(c)?(Object.entries(c).forEach(([r,c])=>{const a=`${s}.${r}.${i}`.replace(/\.$/,""),n=a.includes("*")?this.parseWildcardAttribute(a):[a];t.push(...n),n.forEach(t=>this.#k[t]=e)}),t):[e]}parseAttributeRules(e){return Array.isArray(e)?e:"function"==typeof e?[e]:String(e).split("|")}parseAttributeRule(e){if("function"==typeof e)return[e,[]];let t,r;if(Array.isArray(e))t=e[0]??"",r=e.slice(1);else{const s=e.indexOf(":");-1===s?(t=e,r=[]):(t=e.substring(0,s),r=function(e){const t=[];let r="",s=!1;for(let i=0;i<e.length;i++){const c=e[i];'"'===c?s&&'"'===e[i+1]?(r+='"',i++):(s=!s,s&&(r=r.trim())):","!==c||s?r+=c:(t.push(r),r="")}return t.push(r),t}(e.substring(s+1)))}return[this.normalizeRuleName(t),r]}normalizeRuleName(e){return{int:"integer",bool:"boolean"}[e]??e}async validate(){this.#d.clearCaches(),this.#g=new f;const e=[],t=new Set;for(const[e,t]of Object.entries(this.#u))for(const[e]of t)if(""!==e&&"function"!=typeof e&&"function"!=typeof this.#d[s("check_"+e)]&&!k.#n.includes(e))throw new Error(`Invalid validation rule: ${e}`);for(const[r,i]of Object.entries(this.#u)){let c=this.getValue(r);const a=e=>i.some(t=>t[0]===e);a("sometimes")&&void 0===c?t.add(r):e.push(async()=>{const e=this.#y||a("bail"),n=a("nullable");let l=!0;for(const[a,h]of i){if(""===a||"function"!=typeof a&&!k.#l.includes(a)&&(void 0===c||"string"==typeof c&&""===c.trim()||n&&null===c)){t.add(r);continue}let i,o,p;const d=(()=>{if("function"==typeof a)return a;{const e=this.#d[s("check_"+a)]??null;return null===e&&k.#n.includes(a)?()=>!0:e}})();if(null===d)throw new Error(`Invalid validation rule: ${a}`);if(i=await d.call(this.#d,r,c,h),"boolean"==typeof i&&(i={success:i}),({success:o,message:p=""}=i),!o&&(l=!1,p=u(p)?this.getMessage(r,a):p,p=this.makeReplacements(p,r,a,h),this.#g.add(r,p),e||k.#l.includes(a)))break}return l})}if(this.#A){for(const t of e)if(!await t())break}else await Promise.allSettled(e.map(e=>e())).then(e=>{for(const t of e)if("rejected"===t.status)throw t.reason}),this.#g.sortByKeys(Object.keys(this.#u));return this.#m=[...t],this.#g}async passes(){return await this.validate(),!this.#g.isNotEmpty()}async fails(){return!await this.passes()}getMessage(e,t){if("function"==typeof t)return"";const r=this.getValue(e);let s;e=this.getPrimaryAttribute(e);for(const r of[`${e}.${t}`,t])if(Object.hasOwn(this.#h,r)){s=this.#h[r];break}if(!s){let i=t;this.sizeRules.includes(i)&&(Array.isArray(r)||o(r)||this.hasRule(e,this.arrayRules)?i+=".array":r instanceof File||this.hasRule(e,this.fileRules)?i+=".file":this.hasRule(e,this.stringRules)?i+=".string":h(r)||this.hasRule(e,this.numericRules)?i+=".numeric":i+=".string"),s=g.get(i)}return s??`validation.${t}`}makeReplacements(e,t,r,i){const c=this.getDisplayableAttribute(t),a=this.getValue(t),n={attribute:c,ATTRIBUTE:c.toLocaleUpperCase(),Attribute:c.charAt(0).toLocaleUpperCase()+c.substring(1),input:this.getDisplayableValue(t,a)};for(const[t,r]of Object.entries(n))e=e.replaceAll(":"+t,r);const l=t.match(/\.(\d+)\.?/),u=null===l?-1:parseInt(l[1],10);if(-1!==u&&(e=e.replaceAll(":index",u).replaceAll(":position",u+1)),"string"==typeof r){const c=this.#f[s("replace_"+r)]??null;c&&(e=c.call(this.#f,e,t,r,i))}return 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(g.has(`attributes.${r}`))return g.get(`attributes.${r}`)}return Object.hasOwn(this.#k,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 Object.hasOwn(this.#p,r)?this.#p[r]:g.has(`values.${r}`)?g.get(`values.${r}`):u(t)?"empty":Array.isArray(t)?"array":"boolean"==typeof t||this.hasRule(e,"boolean")?Number(t)?"true":"false":t}getSize(e,t){return u(t)?0:this.hasRule(e,this.stringRules)?String(t).length:h(t)&&this.hasRule(e,this.numericRules)?parseFloat("string"==typeof t?t.trim():t,10):t instanceof File?t.size/1024:o(t)?Object.keys(t).length:Object.hasOwn(t,"length")?t.length:t}getRule(e){return e=this.getPrimaryAttribute(e),this.#u[e]??[]}hasRule(e,t){if(e=this.getPrimaryAttribute(e),t="string"==typeof t?[t]:t,!Object.hasOwn(this.#u,e))return!1;for(const r of t)if(this.#u[e].some(e=>e[0]===r))return!0;return!1}getPrimaryAttribute(e){return Object.hasOwn(this.#k,e)?this.#k[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(null==i||!Object.hasOwn(i,e))return r;i=i[e]}return i}(this.#r,e)}errors(){return this.#g}skippedAttributes(){return this.#m}}return e.Checkers=d,e.ErrorBag=f,e.Lang=g,e.Replacers=m,e.Validator=k,e}({});
6
+ var quival=function(e){"use strict";const t=e=>e&&/^\d*$/.test(e)?parseInt(e):e,r=(e,t,r,s,i,c,a)=>(e>=10&&e<100&&(e+=2e3),null!==a&&("pm"===(a=a.toLowerCase())&&s<12?s+=12:"am"===a&&12===s&&(s=0)),new Date(`${e}-${t}-${r} ${s}:${i}:${c}`));function s(e){return e.replace(/[-_]/g," ").replace(/\s+/g," ").trim().replace(/(\s\w)/g,e=>e[1].toUpperCase())}function i(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function c(e,t=""){return Object.keys(e).reduce((r,s)=>{const i=t?`${t}.${s}`:s;return"object"==typeof e[s]&&null!==e[s]?Object.assign(r,c(e[s],i)):r[i]=e[s],r},{})}function a(e){if(e instanceof Date)return e;if(h(e)||"string"!=typeof e)return new Date("");let s,i,c,a,n,l,u,o;if(null!==(s=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)))[,a,c,i,,n=0,l=0,,u=0,o=null]=s.map(t);else if(null!==(s=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!==(s=e.match(/^(\d{4})(\d{2})(\d{2})\s?((\d{2})(\d{2})((\d{2}))?\s?(am|pm)?)?/i)))[,i,c,a,,n=0,l=0,,u=0,o=null]=s.map(t);else if(s=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{4})[.\/-](\d{2})[.\/-](\d{2})/i))[,n,l,,u,o=null,i,c,a]=s.map(t);else if(s=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{2})[.\/-](\d{2})[.\/-](\d{4})/i))[,n,l,,u,o=null,a,c,i]=s.map(t);else{if(!(s=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?/i)))return new Date(e);{const e=new Date;i=e.getFullYear(),c=e.getMonth()+1,a=e.getDate(),[,n=0,l=0,,u=0,o=null]=s.map(t)}}return r(i,c,a,n,l,u,o)}const n={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)"};function l(e,s){if(h(e))return new Date("");s=s.split("");let i="^",c={years:-1,months:-1,days:-1,hours:-1,minutes:-1,seconds:-1,meridiem:-1},a=1;for(const e of s)Object.hasOwn(n,e)?(i+=n[e],-1!==["Y","y"].indexOf(e)?c.years=a++:-1!==["m","n"].indexOf(e)?c.months=a++:-1!==["d","j"].indexOf(e)?c.days=a++:-1!==["G","g","H","h"].indexOf(e)?c.hours=a++:"i"===e?c.minutes=a++:"s"===e?c.seconds=a++:-1!==["A","a"].indexOf(e)&&(c.meridiem=a++)):i+="\\"+e;i+="$";let l=e.match(new RegExp(i));if(null===l)return new Date("");l=l.map(t);const u=new Date;let o=l[c.years],p=l[c.months],d=l[c.days],f=l[c.hours]??0,g=l[c.minutes]??0,m=l[c.seconds]??0,k=l[c.meridiem]??null;return o||p||d?!o||p||d?o||!p||d?o||p||!d||(o=u.getFullYear(),p=u.getMonth()+1):(o=u.getFullYear(),d=1):(p=1,d=1):(o=u.getFullYear(),p=u.getMonth()+1,d=u.getDate()),r(o,p,d,f,g,m,k)}function u(e){return(String(e).split(".")[1]??"").length}function h(e){return""===e||null==e}function o(e){const t=Number(e);return null!==e&&"boolean"!=typeof e&&"number"==typeof t&&!isNaN(t)}function p(e){return"[object Object]"===Object.prototype.toString.call(e)}function d(e){return e instanceof Date&&"Invalid Date"!==e.toDateString()}class f{#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)}collectAndTest(e,t,r,s,i){return!i(s.map(t=>e(t,this.validator.getValue(t))))||e(t,r)}collectRequiredsThenTest(e,t,r,s){return this.collectAndTest(this.checkRequired,e,t,r,s)}collectPresentsThenTest(e,t,r,s){return this.collectAndTest(this.checkPresent,e,t,r,s)}collectMissingsThenTest(e,t,r,s){return this.collectAndTest(this.checkMissing,e,t,r,s)}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(h(t))return!1;const i=r[0]??"";let c=this.validator.getValue(i);return c=void 0===c?o(i)?parseFloat(i):null:this.validator.getSize(i,c),!h(c)&&s(this.validator.getSize(e,t),c)}compareDates(e,t,r,s){const i=this.validator.getRule(e),c=Array.isArray(i)?i.find(([e])=>"date_format"===e):null,n=c?c[1][0]:null;if(!d(t=n?l(t,n):a(t)))return!1;const u=r[0]??"";let h=this.validator.getValue(u);if(void 0===h)h=n?l(u,n):a(u);else{const e=this.validator.getRule(u),t=Array.isArray(e)?e.find(([e])=>"date_format"===e):null,r=t?t[1][0]:null;h=r?l(h,r):a(h)}return!!d(h)&&s(t.getTime(),h.getTime())}checkArray(e,t,r=[]){if(!Array.isArray(t)&&!p(t))return!1;if(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 r.includes("strict")?[!0,!1].includes(t):[!0,!1,0,1,"0","1"].includes(t)}checkDate(e,t,r){return d(a(t))}checkFile(e,t,r){return t instanceof File}checkInteger(e,t,r=[]){return r.includes("strict")||"string"!=typeof t||(t=Number(t)),Number.isInteger(t)}checkNumeric(e,t,r=[]){return r.includes("strict")?"number"==typeof t:o(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(!o(t)||!o(r[0]))return!1;const s=Number(t),i=Number(r[0]);if(0===s&&0===i)return!1;if(0===s)return!0;if(0===i)return!1;const c=10**Math.max(u(s),u(i));return Math.round(s*c)%Math.round(i*c)===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!h(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)}checkRequiredIfDeclined(e,t,r){return!this.checkDeclined(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}checkPresentIf(e,t,r){return!this.isDependent(r)||this.checkPresent(e,t)}checkPresentUnless(e,t,r){return!!this.isDependent(r)||this.checkPresent(e,t)}checkPresentWith(e,t,r){return this.collectPresentsThenTest(e,t,r,e=>e.includes(!0))}checkPresentWithAll(e,t,r){return this.collectPresentsThenTest(e,t,r,e=>!e.includes(!1))}checkMissing(e,t,r){return void 0===t}checkMissingIf(e,t,r){return!this.isDependent(r)||this.checkMissing(e,t)}checkMissingUnless(e,t,r){return!!this.isDependent(r)||this.checkMissing(e,t)}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&&!o(t))return!1;const i=r.join(",");let[c,a,n]=i.match(/^\/(.*)\/([gimu]*)$/)??[];if(h(c))throw new Error(`Invalid regular expression pattern: ${i}`);n.includes("u")&&(a=a.replace(/\\A/g,"^").replace(/\\z/gi,"$").replace(/\\([pP])([CLMNPSZ])/g,"\\$1{$2}").replace(/\\\x\{([0-9a-f]+)\}/g,"\\u{$1}"));const l=new RegExp(a,n).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,[r[0]??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("");let i="^";for(const e of s)Object.hasOwn(n,e)?i+=n[e]:i+="\\"+e;return i+="$",new RegExp(i).test(t)}checkContains(e,t,r=[]){if(!this.checkArray(e,t))return!1;const s=Array.isArray(t)?t:Object.values(t);for(const e of r)if(!s.some(t=>t==e))return!1;return!0}checkDoesntContain(e,t,r=[]){if(!this.checkArray(e,t))return!1;const s=Array.isArray(t)?t:Object.values(t);for(const e of r)if(s.some(t=>t==e))return!1;return!0}checkDistinct(e,t,r){const s=this.validator.getPrimaryAttribute(e);if(!s.includes("*"))return!0;const a=s.indexOf("*"),n=s.substring(0,a-1);let l;Object.hasOwn(this.#e,n)?l=this.#e[n]:(l=JSON.stringify(c(this.validator.getValue(n)??{})),this.#e[n]=l);const u=r.includes("ignore_case"),h=!u&&r.includes("strict"),o=i(String(t));let p=`"${i(s.substring(a)).replaceAll("\\*",'[^."]+')}":`,d=0;return p+=h?"string"==typeof t?`"${o}"`:`${o}`:`(${o}|"${o}")`,p+="[,}]+",d+=l.match(new RegExp(p,"g"+(u?"i":"")))?.length??0,1===d}checkInArray(e,t,r){const s=this.validator.getPrimaryAttribute(r[0]);if(!s.includes("*"))return!1;const i=this.validator.getValue(s.split(".*")[0])??{};return Object.values(c(i)).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("jpg")&&!r.includes("jpeg")&&r.push("jpeg"),r.includes("jpeg")&&!r.includes("jpg")&&r.push("jpg"),r.includes(t.name.split(".").pop().toLowerCase()))}checkExtensions(e,t,r){return this.checkMimes(e,t,r)}async checkImage(e,t,r=[]){const s=["jpg","jpeg","png","gif","bmp","webp"];r.includes("allow_svg")&&s.push("svg");let i=this.checkMimes(e,t,s);return i&&"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(()=>{i=!1}),i):i}async checkDimensions(e,t,r=[]){if(!await 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));s[t]=e/i}else s[t]=parseFloat(r)}const i=this.#t[e],c=i.naturalWidth,a=i.naturalHeight;return!(Object.hasOwn(s,"width")&&s.width!==c||Object.hasOwn(s,"height")&&s.height!==a||Object.hasOwn(s,"min_width")&&s.min_width>c||Object.hasOwn(s,"min_height")&&s.min_height>a||Object.hasOwn(s,"max_width")&&s.max_width<c||Object.hasOwn(s,"max_height")&&s.max_height<a)&&(!Object.hasOwn(s,"ratio")||Math.abs(s.ratio-c/a)<=1/(Math.max(c,a)+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,c;for([i,c]of Object.entries(s))if(t.includes(i))break;const a=t.split(i);if(a.length!==12/c)return!1;for(const e of a)if(!new RegExp("^[0-9a-f]{"+c+"}$","i").test(e))return!1;return!0}checkIpv4(e,t,r){if(/[^\d.]/.test(t))return!1;const s=String(t).split(".").map(e=>parseInt(e,10));if(4!==s.length)return!1;for(const e of s)if(isNaN(e)||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(e instanceof RangeError)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}$/i.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 g{#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)}remove(e){delete this.#r[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 m{static#s;static#i={};static locale(e){this.#s=e}static setMessages(e,t){this.#i[e]=c(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){p(t)?Object.assign(this.#i[this.#s],c(t,e)):"string"==typeof t&&(this.#i[this.#s][e]=t)}}class k{constructor(e){this.validator=e}replace(e,t){return Object.entries(t).forEach(([t,r])=>e=e.replaceAll(":"+t,r)),e}replaceCaseVariants(e,t){return Object.entries(t).flatMap(([e,t])=>[[e,t=String(t)],[e.toLocaleUpperCase(),t.toLocaleUpperCase()],[e.charAt(0).toLocaleUpperCase()+e.substring(1),t.charAt(0).toLocaleUpperCase()+t.substring(1)]]).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.replaceCaseVariants(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)}replaceRequiredIfDeclined(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredUnless(e,t,r,s){return this.replaceCaseVariants(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.replaceCaseVariants(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)}replacePresentIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replacePresentUnless(e,t,r,s){return this.replaceCaseVariants(this.replaceRequiredUnless(e,t,r,s),{value:this.validator.getDisplayableValue(s[0],s[1])})}replacePresentWith(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replacePresentWithAll(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.replacePresentUnless(e,t,r,s)}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.replaceCaseVariants(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:void 0===i?this.validator.getDisplayableAttribute(s[0]):this.validator.getSize(s[0],i)})}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)}replaceDoesntContain(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 A{static#c={};static#a={};static#n=["active_url","bail","can","current_password","encoding","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","present_if","present_unless","present_with","present_with_all","required","required_if","required_if_accepted","required_if_declined","required_unless","required_with","required_with_all","required_without","required_without_all"];#r;#u;#h;#o;#p;#d;#f;#g;#m;#k;#A;#y;static setLocale(e){m.locale(e)}static setMessages(e,t){m.setMessages(e,t)}static addChecker(e,t,r){A.#c[e]=t,r&&m.set(e,r)}static addImplicitChecker(e,t,r){A.addChecker(e,t,r),A.#l.push(e)}static addReplacer(e,t){A.#a[e]=t}static addDummyRule(e){A.#n.push(e)}constructor(e={},t={},r={},i={},c={}){this.#m=[],this.#k={},this.#A=!1,this.#y=!1,this.arrayRules=["array","list"],this.fileRules=["file","image","mimetypes","mimes"],this.stringRules=["string","alpha","alpha_dash","alpha_num","ascii","email"],this.numericRules=["decimal","numeric","integer"],this.sizeRules=["size","between","min","max","gt","lt","gte","lte"],this.setProperties(e,t,r,i,c),this.#d=new f(this),this.#f=new k(this);for(const[e,t]of Object.entries(A.#c))this.#d[s("check_"+e)]=t;for(const[e,t]of Object.entries(A.#a))this.#f[s("replace_"+e)]=t;this.#g=new g}setProperties(e={},t={},r={},s={},i={}){return this.#r=e,this.#u=this.parseRules(t),this.#h=r,this.#o=s,this.#p=c(i),this}setData(e){return this.#r=e,this}setRules(e){return this.#u=this.parseRules(e),this}setCustomMessages(e){return this.#h=e,this}setCustomAttributes(e){return this.#o=e,this}setCustomValues(e){return this.#p=c(e),this}addImplicitAttribute(e,t){return this.#k[e]=t,this}stopOnFirstFailure(e=!0){return this.#A=e,this}alwaysBail(e=!0){return this.#y=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))e.push(this.parseAttributeRule(t));t[r]=e}}return t}parseWildcardAttribute(e){const t=[],r=e.indexOf("*"),s=e.substring(0,r-1),i=e.substring(r+2),c=this.getValue(s);return Array.isArray(c)||p(c)?(Object.entries(c).forEach(([r,c])=>{const a=`${s}.${r}.${i}`.replace(/\.$/,""),n=a.includes("*")?this.parseWildcardAttribute(a):[a];t.push(...n),n.forEach(t=>this.#k[t]=e)}),t):[e]}parseAttributeRules(e){return Array.isArray(e)?e:"function"==typeof e?[e]:String(e).split("|")}parseAttributeRule(e){if("function"==typeof e)return[e,[]];let t,r;if(Array.isArray(e))t=e[0]??"",r=e.slice(1);else{const s=e.indexOf(":");-1===s?(t=e,r=[]):(t=e.substring(0,s),r=function(e){const t=[];let r="",s=!1;for(let i=0;i<e.length;i++){const c=e[i];'"'===c?s&&'"'===e[i+1]?(r+='"',i++):(s=!s,s&&(r=r.trim())):","!==c||s?r+=c:(t.push(r),r="")}return t.push(r),t}(e.substring(s+1)))}return[this.normalizeRuleName(t),r]}normalizeRuleName(e){return{int:"integer",bool:"boolean"}[e]??e}async validate(){this.#d.clearCaches(),this.#g=new g;const e=[],t=new Set;for(const[e,t]of Object.entries(this.#u))for(const[e]of t)if(""!==e&&"function"!=typeof e&&"function"!=typeof this.#d[s("check_"+e)]&&!A.#n.includes(e))throw new Error(`Invalid validation rule: ${e}`);for(const[r,i]of Object.entries(this.#u)){let c=this.getValue(r);const a=e=>i.some(t=>t[0]===e);a("sometimes")&&void 0===c?t.add(r):e.push(async()=>{const e=this.#y||a("bail"),n=a("nullable");let l=!0;for(const[a,u]of i){if(""===a||"function"!=typeof a&&!A.#l.includes(a)&&(void 0===c||"string"==typeof c&&""===c.trim()||n&&null===c)){t.add(r);continue}let i,o,p;const d=(()=>{if("function"==typeof a)return a;{const e=this.#d[s("check_"+a)]??null;return null===e&&A.#n.includes(a)?()=>!0:e}})();if(null===d)throw new Error(`Invalid validation rule: ${a}`);if(i=await d.call(this.#d,r,c,u),"boolean"==typeof i&&(i={success:i}),({success:o,message:p=""}=i),!o&&(l=!1,p=h(p)?this.getMessage(r,a):p,p=this.makeReplacements(p,r,a,u),this.#g.add(r,p),e||A.#l.includes(a)))break}return l})}if(this.#A){for(const t of e)if(!await t())break}else await Promise.allSettled(e.map(e=>e())).then(e=>{for(const t of e)if("rejected"===t.status)throw t.reason}),this.#g.sortByKeys(Object.keys(this.#u));return this.#m=[...t],this.#g}async passes(){return await this.validate(),!this.#g.isNotEmpty()}async fails(){return!await this.passes()}getMessage(e,t){if("function"==typeof t)return"";const r=this.getValue(e);let s;e=this.getPrimaryAttribute(e);for(const r of[`${e}.${t}`,t])if(Object.hasOwn(this.#h,r)){s=this.#h[r];break}if(!s){let i=t;this.sizeRules.includes(i)&&(Array.isArray(r)||p(r)||this.hasRule(e,this.arrayRules)?i+=".array":r instanceof File||this.hasRule(e,this.fileRules)?i+=".file":this.hasRule(e,this.stringRules)?i+=".string":o(r)||this.hasRule(e,this.numericRules)?i+=".numeric":i+=".string"),s=m.get(i)}return s??`validation.${t}`}makeReplacements(e,t,r,i){const c=this.getDisplayableAttribute(t),a=this.getValue(t),n={attribute:c,ATTRIBUTE:c.toLocaleUpperCase(),Attribute:c.charAt(0).toLocaleUpperCase()+c.substring(1),input:this.getDisplayableValue(t,a)};for(const[t,r]of Object.entries(n))e=e.replaceAll(":"+t,r);const l=t.match(/\.(\d+)\.?/),u=null===l?-1:parseInt(l[1],10);if(-1!==u&&(e=e.replaceAll(":index",u).replaceAll(":position",u+1)),"string"==typeof r){const c=this.#f[s("replace_"+r)]??null;c&&(e=c.call(this.#f,e,t,r,i))}return 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(m.has(`attributes.${r}`))return m.get(`attributes.${r}`)}return Object.hasOwn(this.#k,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 Object.hasOwn(this.#p,r)?this.#p[r]:m.has(`values.${r}`)?m.get(`values.${r}`):h(t)?"empty":Array.isArray(t)?"array":"boolean"==typeof t||this.hasRule(e,"boolean")?Number(t)?"true":"false":t}getSize(e,t){return h(t)?0:this.hasRule(e,this.stringRules)?String(t).length:o(t)&&this.hasRule(e,this.numericRules)?parseFloat("string"==typeof t?t.trim():t):t instanceof File?t.size/1024:p(t)?Object.keys(t).length:Object.hasOwn(t,"length")?t.length:t}getRule(e){return e=this.getPrimaryAttribute(e),this.#u[e]??[]}hasRule(e,t){if(e=this.getPrimaryAttribute(e),t="string"==typeof t?[t]:t,!Object.hasOwn(this.#u,e))return!1;for(const r of t)if(this.#u[e].some(e=>e[0]===r))return!0;return!1}getPrimaryAttribute(e){return Object.hasOwn(this.#k,e)?this.#k[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(null==i||!Object.hasOwn(i,e))return r;i=i[e]}return i}(this.#r,e)}errors(){return this.#g}skippedAttributes(){return this.#m}}return e.Checkers=f,e.ErrorBag=g,e.Lang=m,e.Replacers=k,e.Validator=A,e}({});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quival",
3
- "version": "0.5.5",
3
+ "version": "0.5.6",
4
4
  "description": "Data validation à la Laravel Validation",
5
5
  "author": "Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>",
6
6
  "license": "MIT",
@@ -25,7 +25,7 @@
25
25
  "devDependencies": {
26
26
  "@rollup/plugin-node-resolve": "^16.0.1",
27
27
  "@rollup/plugin-swc": "^0.4.0",
28
- "@rollup/plugin-terser": "^0.4.1",
28
+ "@rollup/plugin-terser": "^1.0.0",
29
29
  "mocha": "^11.1.0",
30
30
  "prettier": "^3.2.5",
31
31
  "rollup": "^4.6.1",
package/src/Checkers.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ DATE_FORMAT_PATTERNS,
2
3
  escapeRegExp,
3
4
  flattenObject,
4
5
  getDecimalPlaces,
@@ -32,46 +33,22 @@ export default class Checkers {
32
33
  return parameters.slice(1).some((value) => value == other);
33
34
  }
34
35
 
35
- collectRequiredsThenTest(attribute, value, parameters, callback) {
36
- let result = [];
37
-
38
- for (const other of parameters) {
39
- result.push(this.checkRequired(other, this.validator.getValue(other)));
40
- }
36
+ collectAndTest(checker, attribute, value, parameters, callback) {
37
+ const result = parameters.map((other) => checker(other, this.validator.getValue(other)));
41
38
 
42
- if (callback(result)) {
43
- return this.checkRequired(attribute, value);
44
- }
39
+ return callback(result) ? checker(attribute, value) : true;
40
+ }
45
41
 
46
- return true;
42
+ collectRequiredsThenTest(attribute, value, parameters, callback) {
43
+ return this.collectAndTest(this.checkRequired, attribute, value, parameters, callback);
47
44
  }
48
45
 
49
46
  collectPresentsThenTest(attribute, value, parameters, callback) {
50
- let result = [];
51
-
52
- for (const other of parameters) {
53
- result.push(this.checkPresent(other, this.validator.getValue(other)));
54
- }
55
-
56
- if (callback(result)) {
57
- return this.checkPresent(attribute, value);
58
- }
59
-
60
- return true;
47
+ return this.collectAndTest(this.checkPresent, attribute, value, parameters, callback);
61
48
  }
62
49
 
63
50
  collectMissingsThenTest(attribute, value, parameters, callback) {
64
- let result = [];
65
-
66
- for (const other of parameters) {
67
- result.push(this.checkMissing(other, this.validator.getValue(other)));
68
- }
69
-
70
- if (callback(result)) {
71
- return this.checkMissing(attribute, value);
72
- }
73
-
74
- return true;
51
+ return this.collectAndTest(this.checkMissing, attribute, value, parameters, callback);
75
52
  }
76
53
 
77
54
  testStringUsingRegex(attribute, value, asciiRegex, unicodeRegex, isAscii = false) {
@@ -183,7 +160,7 @@ export default class Checkers {
183
160
 
184
161
  checkInteger(attribute, value, parameters = []) {
185
162
  if (!parameters.includes('strict') && typeof value === 'string') {
186
- value = parseFloat(value);
163
+ value = Number(value);
187
164
  }
188
165
 
189
166
  return Number.isInteger(value);
@@ -629,28 +606,11 @@ export default class Checkers {
629
606
  checkDateFormat(attribute, value, parameters) {
630
607
  const format = parameters[0].split('');
631
608
 
632
- const formats = {
633
- Y: '(\\d{4})',
634
- y: '(\\d{2})',
635
- m: '(\\d{2})',
636
- n: '([1-9]\\d?)',
637
- d: '(\\d{2})',
638
- j: '([1-9]\\d?)',
639
- G: '([1-9]\\d?)',
640
- g: '([1-9]\\d?)',
641
- H: '(\\d{2})',
642
- h: '(\\d{2})',
643
- i: '(\\d{2})',
644
- s: '(\\d{2})',
645
- A: '(AM|PM)',
646
- a: '(am|pm)',
647
- };
648
-
649
609
  let pattern = '^';
650
610
 
651
611
  for (const char of format) {
652
- if (Object.hasOwn(formats, char)) {
653
- pattern += formats[char];
612
+ if (Object.hasOwn(DATE_FORMAT_PATTERNS, char)) {
613
+ pattern += DATE_FORMAT_PATTERNS[char];
654
614
  } else {
655
615
  pattern += '\\' + char;
656
616
  }
@@ -667,8 +627,10 @@ export default class Checkers {
667
627
  return false;
668
628
  }
669
629
 
630
+ const values = Array.isArray(value) ? value : Object.values(value);
631
+
670
632
  for (const parameter of parameters) {
671
- if (!value.includes(parameter)) {
633
+ if (!values.some((item) => item == parameter)) {
672
634
  return false;
673
635
  }
674
636
  }
@@ -681,8 +643,10 @@ export default class Checkers {
681
643
  return false;
682
644
  }
683
645
 
646
+ const values = Array.isArray(value) ? value : Object.values(value);
647
+
684
648
  for (const parameter of parameters) {
685
- if (value.includes(parameter)) {
649
+ if (values.some((item) => item == parameter)) {
686
650
  return false;
687
651
  }
688
652
  }
@@ -837,11 +801,11 @@ export default class Checkers {
837
801
  const [key, value] = parameter.split('=', 2);
838
802
 
839
803
  if (key === 'ratio' && value.includes('/')) {
840
- const [numerator, denominator] = value.split('/', 2).map((part) => parseFloat(part, 10));
804
+ const [numerator, denominator] = value.split('/', 2).map((part) => parseFloat(part));
841
805
 
842
806
  constraints[key] = numerator / denominator;
843
807
  } else {
844
- constraints[key] = parseFloat(value, 10);
808
+ constraints[key] = parseFloat(value);
845
809
  }
846
810
  }
847
811
 
@@ -999,7 +963,7 @@ export default class Checkers {
999
963
  }
1000
964
 
1001
965
  checkUlid(attribute, value, parameters) {
1002
- return /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/.test(value);
966
+ return /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/i.test(value);
1003
967
  }
1004
968
 
1005
969
  checkUuid(attribute, value, parameters) {
package/src/Replacers.js CHANGED
@@ -13,11 +13,15 @@ export default class Replacers {
13
13
 
14
14
  replaceCaseVariants(message, data) {
15
15
  Object.entries(data)
16
- .flatMap(([key, value]) => [
17
- [key, value],
18
- [key.toLocaleUpperCase(), value.toLocaleUpperCase()],
19
- [key.charAt(0).toLocaleUpperCase() + key.substring(1), value.charAt(0).toLocaleUpperCase() + value.substring(1)],
20
- ])
16
+ .flatMap(([key, value]) => {
17
+ value = String(value);
18
+
19
+ return [
20
+ [key, value],
21
+ [key.toLocaleUpperCase(), value.toLocaleUpperCase()],
22
+ [key.charAt(0).toLocaleUpperCase() + key.substring(1), value.charAt(0).toLocaleUpperCase() + value.substring(1)],
23
+ ];
24
+ })
21
25
  .forEach(([key, value]) => (message = message.replaceAll(':' + key, value)));
22
26
 
23
27
  return message;
@@ -221,7 +225,7 @@ export default class Replacers {
221
225
  const value = this.validator.getValue(parameters[0]);
222
226
 
223
227
  return this.replace(message, {
224
- value: value ? this.validator.getSize(parameters[0], value) : this.validator.getDisplayableAttribute(parameters[0]),
228
+ value: typeof value === 'undefined' ? this.validator.getDisplayableAttribute(parameters[0]) : this.validator.getSize(parameters[0], value),
225
229
  });
226
230
  }
227
231
 
package/src/Validator.js CHANGED
@@ -510,7 +510,7 @@ export default class Validator {
510
510
  } else if (this.hasRule(attribute, this.stringRules)) {
511
511
  return String(value).length;
512
512
  } else if (isNumeric(value) && this.hasRule(attribute, this.numericRules)) {
513
- return parseFloat(typeof value === 'string' ? value.trim() : value, 10);
513
+ return parseFloat(typeof value === 'string' ? value.trim() : value);
514
514
  } else if (value instanceof File) {
515
515
  return value.size / 1024;
516
516
  } else if (isPlainObject(value)) {
package/src/helpers.js CHANGED
@@ -145,6 +145,23 @@ export function parseDate(value) {
145
145
  return buildDate(years, months, days, hours, minutes, seconds, meridiem);
146
146
  }
147
147
 
148
+ export const DATE_FORMAT_PATTERNS = {
149
+ Y: '(\\d{4})',
150
+ y: '(\\d{2})',
151
+ m: '(\\d{2})',
152
+ n: '([1-9]\\d?)',
153
+ d: '(\\d{2})',
154
+ j: '([1-9]\\d?)',
155
+ G: '([1-9]\\d?)',
156
+ g: '([1-9]\\d?)',
157
+ H: '(\\d{2})',
158
+ h: '(\\d{2})',
159
+ i: '(\\d{2})',
160
+ s: '(\\d{2})',
161
+ A: '(AM|PM)',
162
+ a: '(am|pm)',
163
+ };
164
+
148
165
  export function parseDateByFormat(value, format) {
149
166
  if (isEmpty(value)) {
150
167
  return new Date('');
@@ -152,23 +169,6 @@ export function parseDateByFormat(value, format) {
152
169
 
153
170
  format = format.split('');
154
171
 
155
- const formats = {
156
- Y: '(\\d{4})',
157
- y: '(\\d{2})',
158
- m: '(\\d{2})',
159
- n: '([1-9]\\d?)',
160
- d: '(\\d{2})',
161
- j: '([1-9]\\d?)',
162
- G: '([1-9]\\d?)',
163
- g: '([1-9]\\d?)',
164
- H: '(\\d{2})',
165
- h: '(\\d{2})',
166
- i: '(\\d{2})',
167
- s: '(\\d{2})',
168
- A: '(AM|PM)',
169
- a: '(am|pm)',
170
- };
171
-
172
172
  let pattern = '^';
173
173
  let indices = {
174
174
  years: -1,
@@ -183,8 +183,8 @@ export function parseDateByFormat(value, format) {
183
183
  let index = 1;
184
184
 
185
185
  for (const char of format) {
186
- if (Object.hasOwn(formats, char)) {
187
- pattern += formats[char];
186
+ if (Object.hasOwn(DATE_FORMAT_PATTERNS, char)) {
187
+ pattern += DATE_FORMAT_PATTERNS[char];
188
188
 
189
189
  if (['Y', 'y'].indexOf(char) !== -1) {
190
190
  indices.years = index++;
@@ -598,17 +598,28 @@ describe('Validation', () => {
598
598
  it(`Passes when the field contains required values`, async () => {
599
599
  const validator = new Validator({ field: ['abc', 'def', 'ghi'] }, rules);
600
600
  assert(await validator.passes());
601
+
602
+ validator.setData({ field: { x: 'abc', y: 'def', z: 'ghi' } });
603
+ assert(await validator.passes());
601
604
  });
602
605
 
603
606
  it(`Fails when the field does not contain required values`, async () => {
604
607
  const validator = new Validator({ field: ['def', 'ghi'] }, rules);
605
608
  assert(await validator.fails());
609
+
610
+ validator.setData({ field: { y: 'def', z: 'ghi' } });
611
+ assert(await validator.fails());
606
612
  });
607
613
 
608
614
  it(`Fails when the field is not an array`, async () => {
609
615
  const validator = new Validator({ field: 'abc' }, rules);
610
616
  assert(await validator.fails());
611
617
  });
618
+
619
+ it(`Passes when the field contains numeric values matching string parameters`, async () => {
620
+ const validator = new Validator({ field: [1, 2, 3] }, { field: 'contains:1,2' });
621
+ assert(await validator.passes());
622
+ });
612
623
  });
613
624
 
614
625
  describe(`Rule 'date'`, () => {
@@ -917,17 +928,28 @@ describe('Validation', () => {
917
928
  it(`Passes when the field does not contain provided values`, async () => {
918
929
  const validator = new Validator({ field: ['ghi', 'jkl', 'mno'] }, rules);
919
930
  assert(await validator.passes());
931
+
932
+ validator.setData({ field: { x: 'ghi', y: 'jkl', z: 'mno' } });
933
+ assert(await validator.passes());
920
934
  });
921
935
 
922
936
  it(`Fails when the field contains provided values`, async () => {
923
937
  const validator = new Validator({ field: ['def', 'ghi'] }, rules);
924
938
  assert(await validator.fails());
939
+
940
+ validator.setData({ field: { y: 'def', z: 'ghi' } });
941
+ assert(await validator.fails());
925
942
  });
926
943
 
927
944
  it(`Fails when the field is not an array`, async () => {
928
945
  const validator = new Validator({ field: 'abc' }, rules);
929
946
  assert(await validator.fails());
930
947
  });
948
+
949
+ it(`Fails when the field contains numeric values matching string parameters`, async () => {
950
+ const validator = new Validator({ field: [1, 2, 3] }, { field: 'doesnt_contain:1,9' });
951
+ assert(await validator.fails());
952
+ });
931
953
  });
932
954
 
933
955
  describe(`Rule 'doesnt_end_with'`, () => {
@@ -1476,6 +1498,12 @@ describe('Validation', () => {
1476
1498
  validator.setData({ field: 'abc' });
1477
1499
  assert(await validator.fails());
1478
1500
 
1501
+ validator.setData({ field: 'abc123' });
1502
+ assert(await validator.fails());
1503
+
1504
+ validator.setData({ field: '123abc' });
1505
+ assert(await validator.fails());
1506
+
1479
1507
  validator.setData({ field: [1, 2, 3] });
1480
1508
  assert(await validator.fails());
1481
1509
  });
@@ -3298,6 +3326,11 @@ describe('Validation', () => {
3298
3326
  assert(await validator.passes());
3299
3327
  });
3300
3328
 
3329
+ it(`Passes when the field is a valid lowercase ULID`, async () => {
3330
+ const validator = new Validator({ field: '01gzpcvrpr6k3kqw5b9esb8ph3' }, rules);
3331
+ assert(await validator.passes());
3332
+ });
3333
+
3301
3334
  it(`Fails when the field is an invalid ULID`, async () => {
3302
3335
  const validator = new Validator({ field: '01GZPCVRPR6K3KOW5B9ESB8PH3' }, rules);
3303
3336
  assert(await validator.fails());