1
1
/*!
2
- * quival v0.4.2 (https://github.com/apih/quival)
2
+ * quival v0.5.0 (https://github.com/apih/quival)
3
3
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
4
4
* Released under the MIT License.
5
5
*/
@@ -240,10 +240,10 @@ var quival = (function (exports) {
240
240
collectMissingsThenTest ( attribute , value , parameters , callback ) {
241
241
let result = [ ] ;
242
242
for ( const other of parameters ) {
243
- result . push ( this . checkMissing ( other ) ) ;
243
+ result . push ( this . checkMissing ( other , this . validator . getValue ( other ) ) ) ;
244
244
}
245
245
if ( callback ( result ) ) {
246
- return this . checkMissing ( attribute ) ;
246
+ return this . checkMissing ( attribute , value ) ;
247
247
}
248
248
return true ;
249
249
}
@@ -447,17 +447,17 @@ var quival = (function (exports) {
447
447
}
448
448
// Missing
449
449
checkMissing ( attribute , value , parameters ) {
450
- return ! this . validator . hasAttribute ( attribute ) ;
450
+ return typeof value === 'undefined' ;
451
451
}
452
452
checkMissingIf ( attribute , value , parameters ) {
453
453
if ( this . isDependent ( parameters ) ) {
454
- return this . checkMissing ( attribute ) ;
454
+ return this . checkMissing ( attribute , value ) ;
455
455
}
456
456
return true ;
457
457
}
458
458
checkMissingUnless ( attribute , value , parameters ) {
459
459
if ( ! this . isDependent ( parameters ) ) {
460
- return this . checkMissing ( attribute ) ;
460
+ return this . checkMissing ( attribute , value ) ;
461
461
}
462
462
return true ;
463
463
}
@@ -751,7 +751,11 @@ var quival = (function (exports) {
751
751
return this . checkMimes ( attribute , value , parameters ) ;
752
752
}
753
753
async checkImage ( attribute , value , parameters ) {
754
- let result = this . checkMimes ( attribute , value , [ 'jpg' , 'jpeg' , 'png' , 'gif' , 'bmp' , 'svg' , 'webp' ] ) ;
754
+ const mimes = [ 'jpg' , 'jpeg' , 'png' , 'gif' , 'bmp' , 'webp' ] ;
755
+ if ( parameters . includes ( 'allow_svg' ) ) {
756
+ mimes . push ( 'svg' ) ;
757
+ }
758
+ let result = this . checkMimes ( attribute , value , mimes ) ;
755
759
if ( ! result || typeof FileReader === 'undefined' ) {
756
760
return result ;
757
761
}
@@ -1437,7 +1441,7 @@ var quival = (function (exports) {
1437
1441
this . #checkers. clearCaches ( ) ;
1438
1442
this . #errors = new ErrorBag ( ) ;
1439
1443
const tasks = [ ] ;
1440
- const skippedAttributes = [ ] ;
1444
+ const skippedAttributes = new Set ( ) ;
1441
1445
for ( const [ attribute , rules ] of Object . entries ( this . #rules) ) {
1442
1446
for ( const [ rule ] of rules ) {
1443
1447
if (
@@ -1454,7 +1458,7 @@ var quival = (function (exports) {
1454
1458
let value = this . getValue ( attribute ) ;
1455
1459
const hasRule = ( ruleName ) => rules . some ( ( rule ) => rule [ 0 ] === ruleName ) ;
1456
1460
if ( hasRule ( 'sometimes' ) && typeof value === 'undefined' ) {
1457
- skippedAttributes . push ( attribute ) ;
1461
+ skippedAttributes . add ( attribute ) ;
1458
1462
continue ;
1459
1463
}
1460
1464
tasks . push ( async ( ) => {
@@ -1468,7 +1472,7 @@ var quival = (function (exports) {
1468
1472
! Validator . #implicitRules. includes ( rule ) &&
1469
1473
( typeof value === 'undefined' || ( typeof value === 'string' && value . trim ( ) === '' ) || ( isNullable && value === null ) ) )
1470
1474
) {
1471
- skippedAttributes . push ( attribute ) ;
1475
+ skippedAttributes . add ( attribute ) ;
1472
1476
continue ;
1473
1477
}
1474
1478
let result , success , message ;
@@ -1520,7 +1524,7 @@ var quival = (function (exports) {
1520
1524
} ) ;
1521
1525
this . #errors. sortByKeys ( Object . keys ( this . #rules) ) ;
1522
1526
}
1523
- this . #skippedAttributes = skippedAttributes . filter ( ( value , index , array ) => array . indexOf ( value ) === index ) ;
1527
+ this . #skippedAttributes = [ ... skippedAttributes ] ;
1524
1528
return this . #errors;
1525
1529
}
1526
1530
async passes ( ) {
0 commit comments