quival 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/locales/en.js +1 -1
- package/dist/locales/en.min.js +1 -1
- package/dist/locales/ms.js +1 -1
- package/dist/locales/ms.min.js +1 -1
- package/dist/quival.js +33 -32
- package/dist/quival.min.js +2 -2
- package/package.json +1 -1
- package/src/Checkers.js +18 -4
- package/src/helpers.js +32 -34
- package/test/helpers.js +8 -0
- package/test/validation.js +13 -0
package/dist/locales/en.js
CHANGED
package/dist/locales/en.min.js
CHANGED
package/dist/locales/ms.js
CHANGED
package/dist/locales/ms.min.js
CHANGED
package/dist/quival.js
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* quival v0.5.
|
|
2
|
+
* quival v0.5.5 (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
6
|
var quival = (function (exports) {
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
const castToIntegers = (value) => (value && /^\d*$/.test(value) ? parseInt(value) : value);
|
|
10
|
+
const buildDate = (years, months, days, hours, minutes, seconds, meridiem) => {
|
|
11
|
+
if (years >= 10 && years < 100) {
|
|
12
|
+
years += 2000;
|
|
13
|
+
}
|
|
14
|
+
if (meridiem !== null) {
|
|
15
|
+
meridiem = meridiem.toLowerCase();
|
|
16
|
+
if (meridiem === 'pm' && hours < 12) {
|
|
17
|
+
hours += 12;
|
|
18
|
+
} else if (meridiem === 'am' && hours === 12) {
|
|
19
|
+
hours = 0;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return new Date(`${years}-${months}-${days} ${hours}:${minutes}:${seconds}`);
|
|
23
|
+
};
|
|
9
24
|
function toCamelCase(string) {
|
|
10
25
|
return string
|
|
11
26
|
.replace(/[-_]/g, ' ')
|
|
@@ -74,37 +89,27 @@ var quival = (function (exports) {
|
|
|
74
89
|
return new Date('');
|
|
75
90
|
}
|
|
76
91
|
let match, years, months, days, hours, minutes, seconds, meridiem;
|
|
77
|
-
const castToIntegers = (value) => (value && /^\d*$/.test(value) ? parseInt(value) : value);
|
|
78
92
|
if ((match = value.match(/^(\d{1,2})[.\/-](\d{1,2})[.\/-](\d{2,4})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)) !== null) {
|
|
79
|
-
[, days, months, years, , hours = 0, minutes = 0, , seconds = 0, meridiem =
|
|
93
|
+
[, days, months, years, , hours = 0, minutes = 0, , seconds = 0, meridiem = null] = match.map(castToIntegers);
|
|
80
94
|
} else if (
|
|
81
95
|
(match = value.match(/^(\d{2,4})[.\/-](\d{1,2})[.\/-](\d{1,2})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)) !== null ||
|
|
82
96
|
(match = value.match(/^(\d{4})(\d{2})(\d{2})\s?((\d{2})(\d{2})((\d{2}))?\s?(am|pm)?)?/i)) !== null
|
|
83
97
|
) {
|
|
84
|
-
[, years, months, days, , hours = 0, minutes = 0, , seconds = 0, meridiem =
|
|
98
|
+
[, years, months, days, , hours = 0, minutes = 0, , seconds = 0, meridiem = null] = match.map(castToIntegers);
|
|
85
99
|
} else if ((match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{4})[.\/-](\d{2})[.\/-](\d{2})/i))) {
|
|
86
|
-
[, hours, minutes, , seconds, meridiem =
|
|
100
|
+
[, hours, minutes, , seconds, meridiem = null, years, months, days] = match.map(castToIntegers);
|
|
87
101
|
} else if ((match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{2})[.\/-](\d{2})[.\/-](\d{4})/i))) {
|
|
88
|
-
[, hours, minutes, , seconds, meridiem =
|
|
102
|
+
[, hours, minutes, , seconds, meridiem = null, days, months, years] = match.map(castToIntegers);
|
|
89
103
|
} else if ((match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?/i))) {
|
|
90
104
|
const current = new Date();
|
|
91
105
|
years = current.getFullYear();
|
|
92
106
|
months = current.getMonth() + 1;
|
|
93
107
|
days = current.getDate();
|
|
94
|
-
[, hours = 0, minutes = 0, , seconds = 0, meridiem =
|
|
108
|
+
[, hours = 0, minutes = 0, , seconds = 0, meridiem = null] = match.map(castToIntegers);
|
|
95
109
|
} else {
|
|
96
110
|
return new Date(value);
|
|
97
111
|
}
|
|
98
|
-
|
|
99
|
-
years += 2000;
|
|
100
|
-
}
|
|
101
|
-
meridiem = meridiem.toLowerCase();
|
|
102
|
-
if (meridiem === 'pm' && hours < 12) {
|
|
103
|
-
hours += 12;
|
|
104
|
-
} else if (meridiem === 'am' && hours === 12) {
|
|
105
|
-
hours = 0;
|
|
106
|
-
}
|
|
107
|
-
return new Date(`${years}-${months}-${days} ${hours}:${minutes}:${seconds}`);
|
|
112
|
+
return buildDate(years, months, days, hours, minutes, seconds, meridiem);
|
|
108
113
|
}
|
|
109
114
|
function parseDateByFormat(value, format) {
|
|
110
115
|
if (isEmpty(value)) {
|
|
@@ -165,7 +170,7 @@ var quival = (function (exports) {
|
|
|
165
170
|
if (match === null) {
|
|
166
171
|
return new Date('');
|
|
167
172
|
}
|
|
168
|
-
match = match.map(
|
|
173
|
+
match = match.map(castToIntegers);
|
|
169
174
|
const current = new Date();
|
|
170
175
|
let years = match[indices.years];
|
|
171
176
|
let months = match[indices.months];
|
|
@@ -173,7 +178,7 @@ var quival = (function (exports) {
|
|
|
173
178
|
let hours = match[indices.hours] ?? 0;
|
|
174
179
|
let minutes = match[indices.minutes] ?? 0;
|
|
175
180
|
let seconds = match[indices.seconds] ?? 0;
|
|
176
|
-
let meridiem = match[indices.meridiem] ??
|
|
181
|
+
let meridiem = match[indices.meridiem] ?? null;
|
|
177
182
|
if (!years && !months && !days) {
|
|
178
183
|
years = current.getFullYear();
|
|
179
184
|
months = current.getMonth() + 1;
|
|
@@ -188,16 +193,10 @@ var quival = (function (exports) {
|
|
|
188
193
|
years = current.getFullYear();
|
|
189
194
|
months = current.getMonth() + 1;
|
|
190
195
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (meridiem === 'pm' && hours < 12) {
|
|
196
|
-
hours += 12;
|
|
197
|
-
} else if (meridiem === 'am' && hours === 12) {
|
|
198
|
-
hours = 0;
|
|
199
|
-
}
|
|
200
|
-
return new Date(`${years}-${months}-${days} ${hours}:${minutes}:${seconds}`);
|
|
196
|
+
return buildDate(years, months, days, hours, minutes, seconds, meridiem);
|
|
197
|
+
}
|
|
198
|
+
function getDecimalPlaces(value) {
|
|
199
|
+
return (String(value).split('.')[1] ?? '').length;
|
|
201
200
|
}
|
|
202
201
|
function isDigits(value) {
|
|
203
202
|
return String(value).search(/[^0-9]/) === -1;
|
|
@@ -375,8 +374,8 @@ var quival = (function (exports) {
|
|
|
375
374
|
if (!isNumeric(value) || !isNumeric(parameters[0])) {
|
|
376
375
|
return false;
|
|
377
376
|
}
|
|
378
|
-
const numerator =
|
|
379
|
-
const denominator =
|
|
377
|
+
const numerator = Number(value);
|
|
378
|
+
const denominator = Number(parameters[0]);
|
|
380
379
|
if (numerator === 0 && denominator === 0) {
|
|
381
380
|
return false;
|
|
382
381
|
} else if (numerator === 0) {
|
|
@@ -384,7 +383,9 @@ var quival = (function (exports) {
|
|
|
384
383
|
} else if (denominator === 0) {
|
|
385
384
|
return false;
|
|
386
385
|
}
|
|
387
|
-
|
|
386
|
+
const decimalPlaces = Math.max(getDecimalPlaces(numerator), getDecimalPlaces(denominator));
|
|
387
|
+
const factor = 10 ** decimalPlaces;
|
|
388
|
+
return Math.round(numerator * factor) % Math.round(denominator * factor) === 0;
|
|
388
389
|
}
|
|
389
390
|
// Agreement
|
|
390
391
|
checkAccepted(attribute, value, parameters) {
|
package/dist/quival.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* quival v0.5.
|
|
2
|
+
* quival v0.5.5 (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";function t(e){return e.replace(/[-_]/g," ").replace(/\s+/g," ").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 c=t?`${t}.${i}`:i;return"object"==typeof e[i]&&null!==e[i]?Object.assign(r,s(e[i],c)):r[c]=e[i],r},{})}function i(e){if(e instanceof Date)return e;if(a(e)||"string"!=typeof e)return new Date("");let t,r,s,i,c,n,l,u;const h=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,,c=0,n=0,,l=0,u="am"]=t.map(h);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,,c=0,n=0,,l=0,u="am"]=t.map(h);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))[,c,n,,l,u="am",r,s,i]=t.map(h);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))[,c,n,,l,u="am",i,s,r]=t.map(h);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(),[,c=0,n=0,,l=0,u="am"]=t.map(h)}}return r>=10&&r<100&&(r+=2e3),u=u.toLowerCase(),"pm"===u&&c<12?c+=12:"am"===u&&12===c&&(c=0),new Date(`${r}-${s}-${i} ${c}:${n}:${l}`)}function c(e,t){if(a(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},c=1;for(const e of t)Object.hasOwn(r,e)?(s+=r[e],-1!==["Y","y"].indexOf(e)?i.years=c++:-1!==["m","n"].indexOf(e)?i.months=c++:-1!==["d","j"].indexOf(e)?i.days=c++:-1!==["G","g","H","h"].indexOf(e)?i.hours=c++:"i"===e?i.minutes=c++:"s"===e?i.seconds=c++:-1!==["A","a"].indexOf(e)&&(i.meridiem=c++)):s+="\\"+e;s+="$";let n=e.match(new RegExp(s));if(null===n)return new Date("");n=n.map(e=>e&&/^\d*$/.test(e)?parseInt(e):e);const l=new Date;let u=n[i.years],h=n[i.months],o=n[i.days],p=n[i.hours]??0,d=n[i.minutes]??0,f=n[i.seconds]??0,g=n[i.meridiem]??"am";return u||h||o?!u||h||o?u||!h||o?u||h||!o||(u=l.getFullYear(),h=l.getMonth()+1):(u=l.getFullYear(),o=1):(h=1,o=1):(u=l.getFullYear(),h=l.getMonth()+1,o=l.getDate()),u>=10&&u<100&&(u+=2e3),g=g.toLowerCase(),"pm"===g&&p<12?p+=12:"am"===g&&12===p&&(p=0),new Date(`${u}-${h}-${o} ${p}:${d}:${f}`)}function a(e){return""===e||null==e}function n(e){const t=Number(e);return null!==e&&"boolean"!=typeof e&&"number"==typeof t&&!isNaN(t)}function l(e){return"[object Object]"===Object.prototype.toString.call(e)}function u(e){return e instanceof Date&&"Invalid Date"!==e.toDateString()}class h{#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(a(t))return!1;const i=r[0]??"";let c=this.validator.getValue(i);return c=void 0===c?n(i)?parseFloat(i):null:this.validator.getSize(i,c),!a(c)&&s(this.validator.getSize(e,t),c)}compareDates(e,t,r,s){const a=this.validator.getRule(e),n=Array.isArray(a)?a.find(([e])=>"date_format"===e):null,l=n?n[1][0]:null;if(!u(t=l?c(t,l):i(t)))return!1;const h=r[0]??"";let o=this.validator.getValue(h);if(void 0===o)o=l?c(h,l):i(h);else{const e=this.validator.getRule(h),t=Array.isArray(e)?e.find(([e])=>"date_format"===e):null,r=t?t[1][0]:null;o=r?c(o,r):i(o)}return!!u(o)&&s(t.getTime(),o.getTime())}checkArray(e,t,r=[]){if(!Array.isArray(t)&&!l(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 u(i(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:n(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(!n(t)||!n(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!a(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&&!n(t))return!1;const i=r.join(",");let[c,l,u]=i.match(/^\/(.*)\/([gimu]*)$/)??[];if(a(c))throw new Error(`Invalid regular expression pattern: ${i}`);u.includes("u")&&(l=l.replace(/\\A/g,"^").replace(/\\z/gi,"$").replace(/\\([pP])([CLMNPSZ])/g,"\\$1{$2}").replace(/\\\x\{([0-9a-f]+)\}/g,"\\u{$1}"));const h=new RegExp(l,u).test(t);return s?!h:h}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,i){const c=this.validator.getPrimaryAttribute(e);if(!c.includes("*"))return!0;const a=c.indexOf("*"),n=c.substring(0,a-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 u=i.includes("ignore_case"),h=!u&&i.includes("strict"),o=r(String(t));let p=`"${r(c.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 i=this.validator.getPrimaryAttribute(r[0]);if(!i.includes("*"))return!1;const c=this.validator.getValue(i.split(".*")[0])??{};return Object.values(s(c)).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 o{#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 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){l(t)?Object.assign(this.#i[this.#s],s(t,e)):"string"==typeof t&&(this.#i[this.#s][e]=t)}}class d{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 f{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){p.locale(e)}static setMessages(e,t){p.setMessages(e,t)}static addChecker(e,t,r){f.#c[e]=t,r&&p.set(e,r)}static addImplicitChecker(e,t,r){f.addChecker(e,t,r),f.#l.push(e)}static addReplacer(e,t){f.#a[e]=t}static addDummyRule(e){f.#n.push(e)}constructor(e={},r={},s={},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,r,s,i,c),this.#d=new h(this),this.#f=new d(this);for(const[e,r]of Object.entries(f.#c))this.#d[t("check_"+e)]=r;for(const[e,r]of Object.entries(f.#a))this.#f[t("replace_"+e)]=r;this.#g=new o}setProperties(e={},t={},r={},i={},c={}){return this.#r=e,this.#u=this.parseRules(t),this.#h=r,this.#o=i,this.#p=s(c),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=s(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)||l(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 o;const e=[],r=new Set;for(const[e,r]of Object.entries(this.#u))for(const[e]of r)if(""!==e&&"function"!=typeof e&&"function"!=typeof this.#d[t("check_"+e)]&&!f.#n.includes(e))throw new Error(`Invalid validation rule: ${e}`);for(const[s,i]of Object.entries(this.#u)){let c=this.getValue(s);const n=e=>i.some(t=>t[0]===e);n("sometimes")&&void 0===c?r.add(s):e.push(async()=>{const e=this.#y||n("bail"),l=n("nullable");let u=!0;for(const[n,h]of i){if(""===n||"function"!=typeof n&&!f.#l.includes(n)&&(void 0===c||"string"==typeof c&&""===c.trim()||l&&null===c)){r.add(s);continue}let i,o,p;const d=(()=>{if("function"==typeof n)return n;{const e=this.#d[t("check_"+n)]??null;return null===e&&f.#n.includes(n)?()=>!0:e}})();if(null===d)throw new Error(`Invalid validation rule: ${n}`);if(i=await d.call(this.#d,s,c,h),"boolean"==typeof i&&(i={success:i}),({success:o,message:p=""}=i),!o&&(u=!1,p=a(p)?this.getMessage(s,n):p,p=this.makeReplacements(p,s,n,h),this.#g.add(s,p),e||f.#l.includes(n)))break}return u})}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=[...r],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)||l(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":n(r)||this.hasRule(e,this.numericRules)?i+=".numeric":i+=".string"),s=p.get(i)}return s??`validation.${t}`}makeReplacements(e,r,s,i){const c=this.getDisplayableAttribute(r),a=this.getValue(r),n={attribute:c,ATTRIBUTE:c.toLocaleUpperCase(),Attribute:c.charAt(0).toLocaleUpperCase()+c.substring(1),input:this.getDisplayableValue(r,a)};for(const[t,r]of Object.entries(n))e=e.replaceAll(":"+t,r);const l=r.match(/\.(\d+)\.?/),u=null===l?-1:parseInt(l[1],10);if(-1!==u&&(e=e.replaceAll(":index",u).replaceAll(":position",u+1)),"string"==typeof s){const c=this.#f[t("replace_"+s)]??null;c&&(e=c.call(this.#f,e,r,s,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(p.has(`attributes.${r}`))return p.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]:p.has(`values.${r}`)?p.get(`values.${r}`):a(t)?"empty":Array.isArray(t)?"array":"boolean"==typeof t||this.hasRule(e,"boolean")?Number(t)?"true":"false":t}getSize(e,t){return a(t)?0:this.hasRule(e,this.stringRules)?String(t).length:n(t)&&this.hasRule(e,this.numericRules)?parseFloat("string"==typeof t?t.trim():t,10):t instanceof File?t.size/1024:l(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=h,e.ErrorBag=o,e.Lang=p,e.Replacers=d,e.Validator=f,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(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}({});
|
package/package.json
CHANGED
package/src/Checkers.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
escapeRegExp,
|
|
3
|
+
flattenObject,
|
|
4
|
+
getDecimalPlaces,
|
|
5
|
+
isDigits,
|
|
6
|
+
isEmpty,
|
|
7
|
+
isNumeric,
|
|
8
|
+
isPlainObject,
|
|
9
|
+
isValidDate,
|
|
10
|
+
parseDate,
|
|
11
|
+
parseDateByFormat,
|
|
12
|
+
} from './helpers.js';
|
|
2
13
|
|
|
3
14
|
export default class Checkers {
|
|
4
15
|
validator;
|
|
@@ -210,8 +221,8 @@ export default class Checkers {
|
|
|
210
221
|
return false;
|
|
211
222
|
}
|
|
212
223
|
|
|
213
|
-
const numerator =
|
|
214
|
-
const denominator =
|
|
224
|
+
const numerator = Number(value);
|
|
225
|
+
const denominator = Number(parameters[0]);
|
|
215
226
|
|
|
216
227
|
if (numerator === 0 && denominator === 0) {
|
|
217
228
|
return false;
|
|
@@ -221,7 +232,10 @@ export default class Checkers {
|
|
|
221
232
|
return false;
|
|
222
233
|
}
|
|
223
234
|
|
|
224
|
-
|
|
235
|
+
const decimalPlaces = Math.max(getDecimalPlaces(numerator), getDecimalPlaces(denominator));
|
|
236
|
+
const factor = 10 ** decimalPlaces;
|
|
237
|
+
|
|
238
|
+
return Math.round(numerator * factor) % Math.round(denominator * factor) === 0;
|
|
225
239
|
}
|
|
226
240
|
|
|
227
241
|
// Agreement
|
package/src/helpers.js
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
const castToIntegers = (value) => (value && /^\d*$/.test(value) ? parseInt(value) : value);
|
|
2
|
+
|
|
3
|
+
const buildDate = (years, months, days, hours, minutes, seconds, meridiem) => {
|
|
4
|
+
if (years >= 10 && years < 100) {
|
|
5
|
+
years += 2000;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (meridiem !== null) {
|
|
9
|
+
meridiem = meridiem.toLowerCase();
|
|
10
|
+
|
|
11
|
+
if (meridiem === 'pm' && hours < 12) {
|
|
12
|
+
hours += 12;
|
|
13
|
+
} else if (meridiem === 'am' && hours === 12) {
|
|
14
|
+
hours = 0;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return new Date(`${years}-${months}-${days} ${hours}:${minutes}:${seconds}`);
|
|
19
|
+
};
|
|
20
|
+
|
|
1
21
|
export function toCamelCase(string) {
|
|
2
22
|
return string
|
|
3
23
|
.replace(/[-_]/g, ' ')
|
|
@@ -99,19 +119,17 @@ export function parseDate(value) {
|
|
|
99
119
|
|
|
100
120
|
let match, years, months, days, hours, minutes, seconds, meridiem;
|
|
101
121
|
|
|
102
|
-
const castToIntegers = (value) => (value && /^\d*$/.test(value) ? parseInt(value) : value);
|
|
103
|
-
|
|
104
122
|
if ((match = value.match(/^(\d{1,2})[.\/-](\d{1,2})[.\/-](\d{2,4})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)) !== null) {
|
|
105
|
-
[, days, months, years, , hours = 0, minutes = 0, , seconds = 0, meridiem =
|
|
123
|
+
[, days, months, years, , hours = 0, minutes = 0, , seconds = 0, meridiem = null] = match.map(castToIntegers);
|
|
106
124
|
} else if (
|
|
107
125
|
(match = value.match(/^(\d{2,4})[.\/-](\d{1,2})[.\/-](\d{1,2})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)) !== null ||
|
|
108
126
|
(match = value.match(/^(\d{4})(\d{2})(\d{2})\s?((\d{2})(\d{2})((\d{2}))?\s?(am|pm)?)?/i)) !== null
|
|
109
127
|
) {
|
|
110
|
-
[, years, months, days, , hours = 0, minutes = 0, , seconds = 0, meridiem =
|
|
128
|
+
[, years, months, days, , hours = 0, minutes = 0, , seconds = 0, meridiem = null] = match.map(castToIntegers);
|
|
111
129
|
} else if ((match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{4})[.\/-](\d{2})[.\/-](\d{2})/i))) {
|
|
112
|
-
[, hours, minutes, , seconds, meridiem =
|
|
130
|
+
[, hours, minutes, , seconds, meridiem = null, years, months, days] = match.map(castToIntegers);
|
|
113
131
|
} else if ((match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{2})[.\/-](\d{2})[.\/-](\d{4})/i))) {
|
|
114
|
-
[, hours, minutes, , seconds, meridiem =
|
|
132
|
+
[, hours, minutes, , seconds, meridiem = null, days, months, years] = match.map(castToIntegers);
|
|
115
133
|
} else if ((match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?/i))) {
|
|
116
134
|
const current = new Date();
|
|
117
135
|
|
|
@@ -119,24 +137,12 @@ export function parseDate(value) {
|
|
|
119
137
|
months = current.getMonth() + 1;
|
|
120
138
|
days = current.getDate();
|
|
121
139
|
|
|
122
|
-
[, hours = 0, minutes = 0, , seconds = 0, meridiem =
|
|
140
|
+
[, hours = 0, minutes = 0, , seconds = 0, meridiem = null] = match.map(castToIntegers);
|
|
123
141
|
} else {
|
|
124
142
|
return new Date(value);
|
|
125
143
|
}
|
|
126
144
|
|
|
127
|
-
|
|
128
|
-
years += 2000;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
meridiem = meridiem.toLowerCase();
|
|
132
|
-
|
|
133
|
-
if (meridiem === 'pm' && hours < 12) {
|
|
134
|
-
hours += 12;
|
|
135
|
-
} else if (meridiem === 'am' && hours === 12) {
|
|
136
|
-
hours = 0;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return new Date(`${years}-${months}-${days} ${hours}:${minutes}:${seconds}`);
|
|
145
|
+
return buildDate(years, months, days, hours, minutes, seconds, meridiem);
|
|
140
146
|
}
|
|
141
147
|
|
|
142
148
|
export function parseDateByFormat(value, format) {
|
|
@@ -208,7 +214,7 @@ export function parseDateByFormat(value, format) {
|
|
|
208
214
|
return new Date('');
|
|
209
215
|
}
|
|
210
216
|
|
|
211
|
-
match = match.map(
|
|
217
|
+
match = match.map(castToIntegers);
|
|
212
218
|
|
|
213
219
|
const current = new Date();
|
|
214
220
|
|
|
@@ -218,7 +224,7 @@ export function parseDateByFormat(value, format) {
|
|
|
218
224
|
let hours = match[indices.hours] ?? 0;
|
|
219
225
|
let minutes = match[indices.minutes] ?? 0;
|
|
220
226
|
let seconds = match[indices.seconds] ?? 0;
|
|
221
|
-
let meridiem = match[indices.meridiem] ??
|
|
227
|
+
let meridiem = match[indices.meridiem] ?? null;
|
|
222
228
|
|
|
223
229
|
if (!years && !months && !days) {
|
|
224
230
|
years = current.getFullYear();
|
|
@@ -235,19 +241,11 @@ export function parseDateByFormat(value, format) {
|
|
|
235
241
|
months = current.getMonth() + 1;
|
|
236
242
|
}
|
|
237
243
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
meridiem = meridiem.toLowerCase();
|
|
243
|
-
|
|
244
|
-
if (meridiem === 'pm' && hours < 12) {
|
|
245
|
-
hours += 12;
|
|
246
|
-
} else if (meridiem === 'am' && hours === 12) {
|
|
247
|
-
hours = 0;
|
|
248
|
-
}
|
|
244
|
+
return buildDate(years, months, days, hours, minutes, seconds, meridiem);
|
|
245
|
+
}
|
|
249
246
|
|
|
250
|
-
|
|
247
|
+
export function getDecimalPlaces(value) {
|
|
248
|
+
return (String(value).split('.')[1] ?? '').length;
|
|
251
249
|
}
|
|
252
250
|
|
|
253
251
|
export function isDigits(value) {
|
package/test/helpers.js
CHANGED
|
@@ -137,6 +137,11 @@ describe('Helpers', () => {
|
|
|
137
137
|
assert.deepEqual(parseDate('2023-08-11 12:30:00 am'), date4);
|
|
138
138
|
assert.deepEqual(parseDate('11-08-2023 12:30:00 am'), date4);
|
|
139
139
|
assert.deepEqual(parseDate('12:30:00 am 2023-08-11'), date4);
|
|
140
|
+
|
|
141
|
+
const date5 = new Date('2026/01/03 12:10:17');
|
|
142
|
+
assert.deepEqual(parseDate('2026-01-03 12:10:17'), date5);
|
|
143
|
+
assert.deepEqual(parseDate('03-01-2026 12:10:17'), date5);
|
|
144
|
+
assert.deepEqual(parseDate('12:10:17 2026-01-03'), date5);
|
|
140
145
|
});
|
|
141
146
|
|
|
142
147
|
it('parseDateByFormat', () => {
|
|
@@ -157,6 +162,9 @@ describe('Helpers', () => {
|
|
|
157
162
|
|
|
158
163
|
const date4 = new Date('2023/08/11 00:30:00');
|
|
159
164
|
assert.deepEqual(parseDateByFormat('08-11-2023 12:30:00 am', 'm-d-Y H:i:s a'), date4);
|
|
165
|
+
|
|
166
|
+
const date5 = new Date('2026/01/03 12:10:17');
|
|
167
|
+
assert.deepEqual(parseDateByFormat('01-03-2026 12:10:17', 'm-d-Y H:i:s'), date5);
|
|
160
168
|
});
|
|
161
169
|
|
|
162
170
|
it('isDigits', () => {
|
package/test/validation.js
CHANGED
|
@@ -2304,6 +2304,19 @@ describe('Validation', () => {
|
|
|
2304
2304
|
validator.setProperties({ field: 58 }, { field: 'multiple_of:11' });
|
|
2305
2305
|
assert(await validator.fails());
|
|
2306
2306
|
});
|
|
2307
|
+
|
|
2308
|
+
it(`Passes when decimal value is multiple of decimal parameter`, async () => {
|
|
2309
|
+
const validator = new Validator({ field: 0.3 }, { field: 'multiple_of:0.1' });
|
|
2310
|
+
assert(await validator.passes());
|
|
2311
|
+
|
|
2312
|
+
validator.setProperties({ field: 5 }, { field: 'multiple_of:2.5' });
|
|
2313
|
+
assert(await validator.passes());
|
|
2314
|
+
});
|
|
2315
|
+
|
|
2316
|
+
it(`Fails when decimal value is not multiple of decimal parameter`, async () => {
|
|
2317
|
+
const validator = new Validator({ field: 0.75 }, { field: 'multiple_of:0.5' });
|
|
2318
|
+
assert(await validator.fails());
|
|
2319
|
+
});
|
|
2307
2320
|
});
|
|
2308
2321
|
|
|
2309
2322
|
describe(`Rule 'not_in'`, () => {
|