quival 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc.json +1 -0
- package/dist/locales/en.js +2 -1
- package/dist/locales/en.min.js +2 -2
- package/dist/locales/ms.js +2 -1
- package/dist/locales/ms.min.js +2 -2
- package/dist/quival.js +161 -140
- package/dist/quival.min.js +2 -2
- package/package.json +5 -6
- package/rollup.config.js +11 -13
- package/src/Checkers.js +4 -0
- package/src/locales/en.js +1 -0
- package/src/locales/ms.js +1 -0
- package/test/test.js +20 -0
package/.prettierrc.json
CHANGED
package/dist/locales/en.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* quival v0.2.
|
|
2
|
+
* quival v0.2.8 (https://github.com/apih/quival)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -75,6 +75,7 @@ this.quival.locales.en = (function () {
|
|
|
75
75
|
ipv4: 'The :attribute field must be a valid IPv4 address.',
|
|
76
76
|
ipv6: 'The :attribute field must be a valid IPv6 address.',
|
|
77
77
|
json: 'The :attribute field must be a valid JSON string.',
|
|
78
|
+
list: 'The :attribute field must be a list.',
|
|
78
79
|
lowercase: 'The :attribute field must be lowercase.',
|
|
79
80
|
lt: {
|
|
80
81
|
array: 'The :attribute field must have less than :value items.',
|
package/dist/locales/en.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* quival v0.2.
|
|
2
|
+
* quival v0.2.8 (https://github.com/apih/quival)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
this.quival=this.quival||{},this.quival.locales=this.quival.locales||{},this.quival.locales.en=function(){"use strict";return{accepted:"The :attribute field must be accepted.",accepted_if:"The :attribute field must be accepted when :other is :value.",active_url:"The :attribute field must be a valid URL.",after:"The :attribute field must be a date after :date.",after_or_equal:"The :attribute field must be a date after or equal to :date.",alpha:"The :attribute field must only contain letters.",alpha_dash:"The :attribute field must only contain letters, numbers, dashes, and underscores.",alpha_num:"The :attribute field must only contain letters and numbers.",array:"The :attribute field must be an array.",ascii:"The :attribute field must only contain single-byte alphanumeric characters and symbols.",before:"The :attribute field must be a date before :date.",before_or_equal:"The :attribute field must be a date before or equal to :date.",between:{array:"The :attribute field must have between :min and :max items.",file:"The :attribute field must be between :min and :max kilobytes.",numeric:"The :attribute field must be between :min and :max.",string:"The :attribute field must be between :min and :max characters."},boolean:"The :attribute field must be true or false.",can:"The :attribute field contains an unauthorized value.",confirmed:"The :attribute field confirmation does not match.",current_password:"The password is incorrect.",date:"The :attribute field must be a valid date.",date_equals:"The :attribute field must be a date equal to :date.",date_format:"The :attribute field must match the format :format.",decimal:"The :attribute field must have :decimal decimal places.",declined:"The :attribute field must be declined.",declined_if:"The :attribute field must be declined when :other is :value.",different:"The :attribute field and :other must be different.",digits:"The :attribute field must be :digits digits.",digits_between:"The :attribute field must be between :min and :max digits.",dimensions:"The :attribute field has invalid image dimensions.",distinct:"The :attribute field has a duplicate value.",doesnt_end_with:"The :attribute field must not end with one of the following: :values.",doesnt_start_with:"The :attribute field must not start with one of the following: :values.",email:"The :attribute field must be a valid email address.",ends_with:"The :attribute field must end with one of the following: :values.",enum:"The selected :attribute is invalid.",exists:"The selected :attribute is invalid.",extensions:"The :attribute field must have one of the following extensions: :values.",file:"The :attribute field must be a file.",filled:"The :attribute field must have a value.",gt:{array:"The :attribute field must have more than :value items.",file:"The :attribute field must be greater than :value kilobytes.",numeric:"The :attribute field must be greater than :value.",string:"The :attribute field must be greater than :value characters."},gte:{array:"The :attribute field must have :value items or more.",file:"The :attribute field must be greater than or equal to :value kilobytes.",numeric:"The :attribute field must be greater than or equal to :value.",string:"The :attribute field must be greater than or equal to :value characters."},hex_color:"The :attribute field must be a valid hexadecimal color.",image:"The :attribute field must be an image.",in:"The selected :attribute is invalid.",in_array:"The :attribute field must exist in :other.",integer:"The :attribute field must be an integer.",ip:"The :attribute field must be a valid IP address.",ipv4:"The :attribute field must be a valid IPv4 address.",ipv6:"The :attribute field must be a valid IPv6 address.",json:"The :attribute field must be a valid JSON string.",lowercase:"The :attribute field must be lowercase.",lt:{array:"The :attribute field must have less than :value items.",file:"The :attribute field must be less than :value kilobytes.",numeric:"The :attribute field must be less than :value.",string:"The :attribute field must be less than :value characters."},lte:{array:"The :attribute field must not have more than :value items.",file:"The :attribute field must be less than or equal to :value kilobytes.",numeric:"The :attribute field must be less than or equal to :value.",string:"The :attribute field must be less than or equal to :value characters."},mac_address:"The :attribute field must be a valid MAC address.",max:{array:"The :attribute field must not have more than :max items.",file:"The :attribute field must not be greater than :max kilobytes.",numeric:"The :attribute field must not be greater than :max.",string:"The :attribute field must not be greater than :max characters."},max_digits:"The :attribute field must not have more than :max digits.",mimes:"The :attribute field must be a file of type: :values.",mimetypes:"The :attribute field must be a file of type: :values.",min:{array:"The :attribute field must have at least :min items.",file:"The :attribute field must be at least :min kilobytes.",numeric:"The :attribute field must be at least :min.",string:"The :attribute field must be at least :min characters."},min_digits:"The :attribute field must have at least :min digits.",missing:"The :attribute field must be missing.",missing_if:"The :attribute field must be missing when :other is :value.",missing_unless:"The :attribute field must be missing unless :other is :value.",missing_with:"The :attribute field must be missing when :values is present.",missing_with_all:"The :attribute field must be missing when :values are present.",multiple_of:"The :attribute field must be a multiple of :value.",not_in:"The selected :attribute is invalid.",not_regex:"The :attribute field format is invalid.",numeric:"The :attribute field must be a number.",password:{letters:"The :attribute field must contain at least one letter.",mixed:"The :attribute field must contain at least one uppercase and one lowercase letter.",numbers:"The :attribute field must contain at least one number.",symbols:"The :attribute field must contain at least one symbol.",uncompromised:"The given :attribute has appeared in a data leak. Please choose a different :attribute."},present:"The :attribute field must be present.",prohibited:"The :attribute field is prohibited.",prohibited_if:"The :attribute field is prohibited when :other is :value.",prohibited_unless:"The :attribute field is prohibited unless :other is in :values.",prohibits:"The :attribute field prohibits :other from being present.",regex:"The :attribute field format is invalid.",required:"The :attribute field is required.",required_array_keys:"The :attribute field must contain entries for: :values.",required_if:"The :attribute field is required when :other is :value.",required_if_accepted:"The :attribute field is required when :other is accepted.",required_unless:"The :attribute field is required unless :other is in :values.",required_with:"The :attribute field is required when :values is present.",required_with_all:"The :attribute field is required when :values are present.",required_without:"The :attribute field is required when :values is not present.",required_without_all:"The :attribute field is required when none of :values are present.",same:"The :attribute field must match :other.",size:{array:"The :attribute field must contain :size items.",file:"The :attribute field must be :size kilobytes.",numeric:"The :attribute field must be :size.",string:"The :attribute field must be :size characters."},starts_with:"The :attribute field must start with one of the following: :values.",string:"The :attribute field must be a string.",timezone:"The :attribute field must be a valid timezone.",unique:"The :attribute has already been taken.",uploaded:"The :attribute failed to upload.",uppercase:"The :attribute field must be uppercase.",url:"The :attribute field must be a valid URL.",ulid:"The :attribute field must be a valid ULID.",uuid:"The :attribute field must be a valid UUID.",custom:{"attribute-name":{"rule-name":"custom-message"}},attributes:{},values:{}}}();
|
|
6
|
+
this.quival=this.quival||{},this.quival.locales=this.quival.locales||{},this.quival.locales.en=function(){"use strict";return{accepted:"The :attribute field must be accepted.",accepted_if:"The :attribute field must be accepted when :other is :value.",active_url:"The :attribute field must be a valid URL.",after:"The :attribute field must be a date after :date.",after_or_equal:"The :attribute field must be a date after or equal to :date.",alpha:"The :attribute field must only contain letters.",alpha_dash:"The :attribute field must only contain letters, numbers, dashes, and underscores.",alpha_num:"The :attribute field must only contain letters and numbers.",array:"The :attribute field must be an array.",ascii:"The :attribute field must only contain single-byte alphanumeric characters and symbols.",before:"The :attribute field must be a date before :date.",before_or_equal:"The :attribute field must be a date before or equal to :date.",between:{array:"The :attribute field must have between :min and :max items.",file:"The :attribute field must be between :min and :max kilobytes.",numeric:"The :attribute field must be between :min and :max.",string:"The :attribute field must be between :min and :max characters."},boolean:"The :attribute field must be true or false.",can:"The :attribute field contains an unauthorized value.",confirmed:"The :attribute field confirmation does not match.",current_password:"The password is incorrect.",date:"The :attribute field must be a valid date.",date_equals:"The :attribute field must be a date equal to :date.",date_format:"The :attribute field must match the format :format.",decimal:"The :attribute field must have :decimal decimal places.",declined:"The :attribute field must be declined.",declined_if:"The :attribute field must be declined when :other is :value.",different:"The :attribute field and :other must be different.",digits:"The :attribute field must be :digits digits.",digits_between:"The :attribute field must be between :min and :max digits.",dimensions:"The :attribute field has invalid image dimensions.",distinct:"The :attribute field has a duplicate value.",doesnt_end_with:"The :attribute field must not end with one of the following: :values.",doesnt_start_with:"The :attribute field must not start with one of the following: :values.",email:"The :attribute field must be a valid email address.",ends_with:"The :attribute field must end with one of the following: :values.",enum:"The selected :attribute is invalid.",exists:"The selected :attribute is invalid.",extensions:"The :attribute field must have one of the following extensions: :values.",file:"The :attribute field must be a file.",filled:"The :attribute field must have a value.",gt:{array:"The :attribute field must have more than :value items.",file:"The :attribute field must be greater than :value kilobytes.",numeric:"The :attribute field must be greater than :value.",string:"The :attribute field must be greater than :value characters."},gte:{array:"The :attribute field must have :value items or more.",file:"The :attribute field must be greater than or equal to :value kilobytes.",numeric:"The :attribute field must be greater than or equal to :value.",string:"The :attribute field must be greater than or equal to :value characters."},hex_color:"The :attribute field must be a valid hexadecimal color.",image:"The :attribute field must be an image.",in:"The selected :attribute is invalid.",in_array:"The :attribute field must exist in :other.",integer:"The :attribute field must be an integer.",ip:"The :attribute field must be a valid IP address.",ipv4:"The :attribute field must be a valid IPv4 address.",ipv6:"The :attribute field must be a valid IPv6 address.",json:"The :attribute field must be a valid JSON string.",list:"The :attribute field must be a list.",lowercase:"The :attribute field must be lowercase.",lt:{array:"The :attribute field must have less than :value items.",file:"The :attribute field must be less than :value kilobytes.",numeric:"The :attribute field must be less than :value.",string:"The :attribute field must be less than :value characters."},lte:{array:"The :attribute field must not have more than :value items.",file:"The :attribute field must be less than or equal to :value kilobytes.",numeric:"The :attribute field must be less than or equal to :value.",string:"The :attribute field must be less than or equal to :value characters."},mac_address:"The :attribute field must be a valid MAC address.",max:{array:"The :attribute field must not have more than :max items.",file:"The :attribute field must not be greater than :max kilobytes.",numeric:"The :attribute field must not be greater than :max.",string:"The :attribute field must not be greater than :max characters."},max_digits:"The :attribute field must not have more than :max digits.",mimes:"The :attribute field must be a file of type: :values.",mimetypes:"The :attribute field must be a file of type: :values.",min:{array:"The :attribute field must have at least :min items.",file:"The :attribute field must be at least :min kilobytes.",numeric:"The :attribute field must be at least :min.",string:"The :attribute field must be at least :min characters."},min_digits:"The :attribute field must have at least :min digits.",missing:"The :attribute field must be missing.",missing_if:"The :attribute field must be missing when :other is :value.",missing_unless:"The :attribute field must be missing unless :other is :value.",missing_with:"The :attribute field must be missing when :values is present.",missing_with_all:"The :attribute field must be missing when :values are present.",multiple_of:"The :attribute field must be a multiple of :value.",not_in:"The selected :attribute is invalid.",not_regex:"The :attribute field format is invalid.",numeric:"The :attribute field must be a number.",password:{letters:"The :attribute field must contain at least one letter.",mixed:"The :attribute field must contain at least one uppercase and one lowercase letter.",numbers:"The :attribute field must contain at least one number.",symbols:"The :attribute field must contain at least one symbol.",uncompromised:"The given :attribute has appeared in a data leak. Please choose a different :attribute."},present:"The :attribute field must be present.",prohibited:"The :attribute field is prohibited.",prohibited_if:"The :attribute field is prohibited when :other is :value.",prohibited_unless:"The :attribute field is prohibited unless :other is in :values.",prohibits:"The :attribute field prohibits :other from being present.",regex:"The :attribute field format is invalid.",required:"The :attribute field is required.",required_array_keys:"The :attribute field must contain entries for: :values.",required_if:"The :attribute field is required when :other is :value.",required_if_accepted:"The :attribute field is required when :other is accepted.",required_unless:"The :attribute field is required unless :other is in :values.",required_with:"The :attribute field is required when :values is present.",required_with_all:"The :attribute field is required when :values are present.",required_without:"The :attribute field is required when :values is not present.",required_without_all:"The :attribute field is required when none of :values are present.",same:"The :attribute field must match :other.",size:{array:"The :attribute field must contain :size items.",file:"The :attribute field must be :size kilobytes.",numeric:"The :attribute field must be :size.",string:"The :attribute field must be :size characters."},starts_with:"The :attribute field must start with one of the following: :values.",string:"The :attribute field must be a string.",timezone:"The :attribute field must be a valid timezone.",unique:"The :attribute has already been taken.",uploaded:"The :attribute failed to upload.",uppercase:"The :attribute field must be uppercase.",url:"The :attribute field must be a valid URL.",ulid:"The :attribute field must be a valid ULID.",uuid:"The :attribute field must be a valid UUID.",custom:{"attribute-name":{"rule-name":"custom-message"}},attributes:{},values:{}}}();
|
package/dist/locales/ms.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* quival v0.2.
|
|
2
|
+
* quival v0.2.8 (https://github.com/apih/quival)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -75,6 +75,7 @@ this.quival.locales.ms = (function () {
|
|
|
75
75
|
ipv4: 'Medan :attribute mesti alamat IPv4 yang sah.',
|
|
76
76
|
ipv6: 'Medan :attribute mesti alamat IPv6 yang sah.',
|
|
77
77
|
json: 'Medan :attribute mesti rentetan JSON yang sah.',
|
|
78
|
+
list: 'Medan :attribute mesti berbentuk senarai.',
|
|
78
79
|
lowercase: 'Medan :attribute mesti dalam huruf kecil.',
|
|
79
80
|
lt: {
|
|
80
81
|
array: 'Medan :attribute mesti mempunyai kurang daripada :value item.',
|
package/dist/locales/ms.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* quival v0.2.
|
|
2
|
+
* quival v0.2.8 (https://github.com/apih/quival)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
this.quival=this.quival||{},this.quival.locales=this.quival.locales||{},this.quival.locales.ms=function(){"use strict";return{accepted:"Medan :attribute mesti diterima.",accepted_if:"Medan :attribute mesti diterima apabila :other ialah :value.",active_url:"Medan :attribute mesti URL yang sah.",after:"Medan :attribute mesti tarikh selepas :date.",after_or_equal:"Medan :attribute mesti tarikh selepas atau sama dengan :date.",alpha:"Medan :attribute hanya boleh mengandungi huruf.",alpha_dash:"Medan :attribute hanya boleh mengandungi huruf, nombor, tanda sengkang, dan garis bawah.",alpha_num:"Medan :attribute hanya boleh mengandungi huruf dan nombor.",array:"Medan :attribute mesti jujukan.",ascii:"Medan :attribute hanya boleh mengandungi abjad, angka dan simbol berjenis bait tunggal.",before:"Medan :attribute mesti tarikh sebelum :date.",before_or_equal:"Medan :attribute mesti tarikh sebelum atau sama dengan :date.",between:{array:"Medan :attribute mesti mempunyai antara :min dan :max item.",file:"Medan :attribute mesti antara :min dan :max kilobait.",numeric:"Medan :attribute mesti antara :min dan :max.",string:"Medan :attribute mesti antara :min dan :max huruf."},boolean:"Medan :attribute mesti benar atau salah.",can:"Medan :attribute field mengandungi nilai yang tidak dibenarkan.",confirmed:"Pengesahan medan :attribute tidak sepadan.",current_password:"Kata laluan tidak sah.",date:"Medan :attribute mesti tarikh yang sah.",date_equals:"Medan :attribute mesti bersamaan dengan :date.",date_format:"Medan :attribute mesti sepadan dengan format :format.",decimal:"Medan :attribute mesti mempunyai :decimal tempat perpuluhan.",declined:"Medan :attribute mesti ditolak.",declined_if:"Medan :attribute mesti ditolak apabila :other adalah :value.",different:"Medan :attribute dan :other mesti berbeza.",digits:"Medan :attribute mesti mengandungi :digits digit.",digits_between:"Medan :attribute mesti mengandungi antara :min dan :max digit.",dimensions:"Medan :attribute mempunyai dimensi imej yang tidak sah.",distinct:"Medan :attribute mempunyai nilai yang berulang.",doesnt_end_with:"Medan :attribute tidak boleh berakhir dengan salah satu daripada berikut: :values.",doesnt_start_with:"Medan :attribute tidak boleh bermula dengan salah satu daripada berikut: :values.",email:"Medan :attribute mesti alamat emel yang sah.",ends_with:"Medan :attribute mesti berakhir dengan salah satu daripada berikut: :values.",enum:"Nilai :attribute yang dipilih tidak sah.",exists:"Nilai :attribute yang dipilih tidak sah.",extensions:"Medan :attribute mesti salah satu daripada sambungan berikut: :values.",file:"Medan :attribute mesti fail.",filled:"Medan :attribute mesti mempunyai nilai.",gt:{array:"Medan :attribute mesti mempunyai lebih daripada :value item.",file:"Medan :attribute mesti lebih besar daripada :value kilobait.",numeric:"Medan :attribute mesti lebih besar daripada :value.",string:"Medan :attribute mesti lebih besar daripada :value huruf."},gte:{array:"Medan :attribute mesti mempunyai :value item atau lebih.",file:"Medan :attribute mesti lebih besar daripada atau sama dengan :value kilobait.",numeric:"Medan :attribute mesti lebih besar daripada atau sama dengan :value.",string:"Medan :attribute mesti lebih besar daripada atau sama dengan :value huruf."},hex_color:"Medan :attribute mesti warna heksadesimal yang sah.",image:"Medan :attribute mesti imej.",in:"Nilai :attribute yang dipilih tidak sah.",in_array:"Medan :attribute mesti wujud dalam :other.",integer:"Medan :attribute mesti nombor bulat.",ip:"Medan :attribute mesti alamat IP yang sah.",ipv4:"Medan :attribute mesti alamat IPv4 yang sah.",ipv6:"Medan :attribute mesti alamat IPv6 yang sah.",json:"Medan :attribute mesti rentetan JSON yang sah.",lowercase:"Medan :attribute mesti dalam huruf kecil.",lt:{array:"Medan :attribute mesti mempunyai kurang daripada :value item.",file:"Medan :attribute mesti kurang daripada :value kilobait.",numeric:"Medan :attribute mesti kurang daripada :value.",string:"Medan :attribute mesti kurang daripada :value huruf."},lte:{array:"Medan :attribute tidak boleh mempunyai lebih daripada :value item.",file:"Medan :attribute mesti kurang daripada atau sama dengan :value kilobait.",numeric:"Medan :attribute mesti kurang daripada atau sama dengan :value.",string:"Medan :attribute mesti kurang daripada atau sama dengan :value huruf."},mac_address:"Medan :attribute mesti alamat MAC yang sah.",max:{array:"Medan :attribute tidak boleh mempunyai lebih daripada :max item.",file:"Medan :attribute tidak boleh lebih besar daripada :max kilobait.",numeric:"Medan :attribute tidak boleh melebihi :max.",string:"Medan :attribute tidak boleh melebihi :max huruf."},max_digits:"Medan :attribute tidak boleh mempunyai lebih daripada :max digit.",mimes:"Medan :attribute mesti jenis fail: :values.",mimetypes:"Medan :attribute mesti jenis fail: :values.",min:{array:"Medan :attribute mesti mempunyai sekurang-kurangnya :min item.",file:"Medan :attribute mesti sekurang-kurangnya :min kilobait.",numeric:"Medan :attribute mesti sekurang-kurangnya :min.",string:"Medan :attribute mesti sekurang-kurangnya :min huruf."},min_digits:"Medan :attribute mesti mempunyai sekurang-kurangnya :min digit.",missing:"Medan :attribute mesti tiada.",missing_if:"Medan :attribute mesti tiada apabila :other adalah :value.",missing_unless:"Medan :attribute mesti tiada kecuali :other adalah :value.",missing_with:"Medan :attribute mesti tiada apabila :values wujud.",missing_with_all:"Medan :attribute mesti tiada apabila :values wujud.",multiple_of:"Medan :attribute mesti gandaan :value.",not_in:"Nilai :attribute yang dipilih tidak sah.",not_regex:"Format medan :attribute tidak sah.",numeric:"Medan :attribute mesti nombor.",password:{letters:"Medan :attribute mesti mengandungi sekurang-kurangnya satu huruf.",mixed:"Medan :attribute mesti mengandungi sekurang-kurangnya satu huruf besar dan satu huruf kecil.",numbers:"Medan :attribute mesti mengandungi sekurang-kurangnya satu nombor.",symbols:"Medan :attribute mesti mengandungi sekurang-kurangnya satu simbol.",uncompromised:"Nilai :attribute yang diberikan telah muncul dalam kebocoran data. Sila pilih :attribute yang berbeza."},present:"Medan :attribute mesti wujud.",prohibited:"Medan :attribute dilarang.",prohibited_if:"Medan :attribute dilarang apabila :other adalah :value.",prohibited_unless:"Medan :attribute dilarang melainkan :other berada dalam :values.",prohibits:"Medan :attribute melarang :other daripada wujud.",regex:"Format medan :attribute tidak sah.",required:"Medan :attribute diperlukan.",required_array_keys:"Medan :attribute mesti mengandungi entri untuk: :values.",required_if:"Medan :attribute diperlukan apabila :other adalah :value.",required_if_accepted:"Medan :attribute diperlukan apabila :other diterima.",required_unless:"Medan :attribute diperlukan melainkan :other berada dalam :values.",required_with:"Medan :attribute diperlukan apabila :values wujud.",required_with_all:"Medan :attribute diperlukan apabila semua :values wujud.",required_without:"Medan :attribute diperlukan apabila :values tidak wujud.",required_without_all:"Medan :attribute diperlukan apabila tiada satu pun daripada :values wujud.",same:"Medan :attribute mesti sepadan dengan :other.",size:{array:"Medan :attribute mesti mengandungi :size item.",file:"Medan :attribute mesti :size kilobait.",numeric:"Medan :attribute mesti :size.",string:"Medan :attribute mesti :size huruf."},starts_with:"Medan :attribute mesti bermula dengan salah satu dari berikut: :values.",string:"Medan :attribute mesti perkataan / rentetan aksara.",timezone:"Medan :attribute mesti zon masa yang sah.",unique:"Medan :attribute telah wujud.",uploaded:"Medan :attribute gagal dimuat naik.",uppercase:"Medan :attribute mesti dalam huruf besar.",url:"Medan :attribute mesti URL yang sah.",ulid:"Medan :attribute mesti ULID yang sah.",uuid:"Medan :attribute mesti UUID yang sah.",custom:{"attribute-name":{"rule-name":"custom-message"}},attributes:{},values:{}}}();
|
|
6
|
+
this.quival=this.quival||{},this.quival.locales=this.quival.locales||{},this.quival.locales.ms=function(){"use strict";return{accepted:"Medan :attribute mesti diterima.",accepted_if:"Medan :attribute mesti diterima apabila :other ialah :value.",active_url:"Medan :attribute mesti URL yang sah.",after:"Medan :attribute mesti tarikh selepas :date.",after_or_equal:"Medan :attribute mesti tarikh selepas atau sama dengan :date.",alpha:"Medan :attribute hanya boleh mengandungi huruf.",alpha_dash:"Medan :attribute hanya boleh mengandungi huruf, nombor, tanda sengkang, dan garis bawah.",alpha_num:"Medan :attribute hanya boleh mengandungi huruf dan nombor.",array:"Medan :attribute mesti jujukan.",ascii:"Medan :attribute hanya boleh mengandungi abjad, angka dan simbol berjenis bait tunggal.",before:"Medan :attribute mesti tarikh sebelum :date.",before_or_equal:"Medan :attribute mesti tarikh sebelum atau sama dengan :date.",between:{array:"Medan :attribute mesti mempunyai antara :min dan :max item.",file:"Medan :attribute mesti antara :min dan :max kilobait.",numeric:"Medan :attribute mesti antara :min dan :max.",string:"Medan :attribute mesti antara :min dan :max huruf."},boolean:"Medan :attribute mesti benar atau salah.",can:"Medan :attribute field mengandungi nilai yang tidak dibenarkan.",confirmed:"Pengesahan medan :attribute tidak sepadan.",current_password:"Kata laluan tidak sah.",date:"Medan :attribute mesti tarikh yang sah.",date_equals:"Medan :attribute mesti bersamaan dengan :date.",date_format:"Medan :attribute mesti sepadan dengan format :format.",decimal:"Medan :attribute mesti mempunyai :decimal tempat perpuluhan.",declined:"Medan :attribute mesti ditolak.",declined_if:"Medan :attribute mesti ditolak apabila :other adalah :value.",different:"Medan :attribute dan :other mesti berbeza.",digits:"Medan :attribute mesti mengandungi :digits digit.",digits_between:"Medan :attribute mesti mengandungi antara :min dan :max digit.",dimensions:"Medan :attribute mempunyai dimensi imej yang tidak sah.",distinct:"Medan :attribute mempunyai nilai yang berulang.",doesnt_end_with:"Medan :attribute tidak boleh berakhir dengan salah satu daripada berikut: :values.",doesnt_start_with:"Medan :attribute tidak boleh bermula dengan salah satu daripada berikut: :values.",email:"Medan :attribute mesti alamat emel yang sah.",ends_with:"Medan :attribute mesti berakhir dengan salah satu daripada berikut: :values.",enum:"Nilai :attribute yang dipilih tidak sah.",exists:"Nilai :attribute yang dipilih tidak sah.",extensions:"Medan :attribute mesti salah satu daripada sambungan berikut: :values.",file:"Medan :attribute mesti fail.",filled:"Medan :attribute mesti mempunyai nilai.",gt:{array:"Medan :attribute mesti mempunyai lebih daripada :value item.",file:"Medan :attribute mesti lebih besar daripada :value kilobait.",numeric:"Medan :attribute mesti lebih besar daripada :value.",string:"Medan :attribute mesti lebih besar daripada :value huruf."},gte:{array:"Medan :attribute mesti mempunyai :value item atau lebih.",file:"Medan :attribute mesti lebih besar daripada atau sama dengan :value kilobait.",numeric:"Medan :attribute mesti lebih besar daripada atau sama dengan :value.",string:"Medan :attribute mesti lebih besar daripada atau sama dengan :value huruf."},hex_color:"Medan :attribute mesti warna heksadesimal yang sah.",image:"Medan :attribute mesti imej.",in:"Nilai :attribute yang dipilih tidak sah.",in_array:"Medan :attribute mesti wujud dalam :other.",integer:"Medan :attribute mesti nombor bulat.",ip:"Medan :attribute mesti alamat IP yang sah.",ipv4:"Medan :attribute mesti alamat IPv4 yang sah.",ipv6:"Medan :attribute mesti alamat IPv6 yang sah.",json:"Medan :attribute mesti rentetan JSON yang sah.",list:"Medan :attribute mesti berbentuk senarai.",lowercase:"Medan :attribute mesti dalam huruf kecil.",lt:{array:"Medan :attribute mesti mempunyai kurang daripada :value item.",file:"Medan :attribute mesti kurang daripada :value kilobait.",numeric:"Medan :attribute mesti kurang daripada :value.",string:"Medan :attribute mesti kurang daripada :value huruf."},lte:{array:"Medan :attribute tidak boleh mempunyai lebih daripada :value item.",file:"Medan :attribute mesti kurang daripada atau sama dengan :value kilobait.",numeric:"Medan :attribute mesti kurang daripada atau sama dengan :value.",string:"Medan :attribute mesti kurang daripada atau sama dengan :value huruf."},mac_address:"Medan :attribute mesti alamat MAC yang sah.",max:{array:"Medan :attribute tidak boleh mempunyai lebih daripada :max item.",file:"Medan :attribute tidak boleh lebih besar daripada :max kilobait.",numeric:"Medan :attribute tidak boleh melebihi :max.",string:"Medan :attribute tidak boleh melebihi :max huruf."},max_digits:"Medan :attribute tidak boleh mempunyai lebih daripada :max digit.",mimes:"Medan :attribute mesti jenis fail: :values.",mimetypes:"Medan :attribute mesti jenis fail: :values.",min:{array:"Medan :attribute mesti mempunyai sekurang-kurangnya :min item.",file:"Medan :attribute mesti sekurang-kurangnya :min kilobait.",numeric:"Medan :attribute mesti sekurang-kurangnya :min.",string:"Medan :attribute mesti sekurang-kurangnya :min huruf."},min_digits:"Medan :attribute mesti mempunyai sekurang-kurangnya :min digit.",missing:"Medan :attribute mesti tiada.",missing_if:"Medan :attribute mesti tiada apabila :other adalah :value.",missing_unless:"Medan :attribute mesti tiada kecuali :other adalah :value.",missing_with:"Medan :attribute mesti tiada apabila :values wujud.",missing_with_all:"Medan :attribute mesti tiada apabila :values wujud.",multiple_of:"Medan :attribute mesti gandaan :value.",not_in:"Nilai :attribute yang dipilih tidak sah.",not_regex:"Format medan :attribute tidak sah.",numeric:"Medan :attribute mesti nombor.",password:{letters:"Medan :attribute mesti mengandungi sekurang-kurangnya satu huruf.",mixed:"Medan :attribute mesti mengandungi sekurang-kurangnya satu huruf besar dan satu huruf kecil.",numbers:"Medan :attribute mesti mengandungi sekurang-kurangnya satu nombor.",symbols:"Medan :attribute mesti mengandungi sekurang-kurangnya satu simbol.",uncompromised:"Nilai :attribute yang diberikan telah muncul dalam kebocoran data. Sila pilih :attribute yang berbeza."},present:"Medan :attribute mesti wujud.",prohibited:"Medan :attribute dilarang.",prohibited_if:"Medan :attribute dilarang apabila :other adalah :value.",prohibited_unless:"Medan :attribute dilarang melainkan :other berada dalam :values.",prohibits:"Medan :attribute melarang :other daripada wujud.",regex:"Format medan :attribute tidak sah.",required:"Medan :attribute diperlukan.",required_array_keys:"Medan :attribute mesti mengandungi entri untuk: :values.",required_if:"Medan :attribute diperlukan apabila :other adalah :value.",required_if_accepted:"Medan :attribute diperlukan apabila :other diterima.",required_unless:"Medan :attribute diperlukan melainkan :other berada dalam :values.",required_with:"Medan :attribute diperlukan apabila :values wujud.",required_with_all:"Medan :attribute diperlukan apabila semua :values wujud.",required_without:"Medan :attribute diperlukan apabila :values tidak wujud.",required_without_all:"Medan :attribute diperlukan apabila tiada satu pun daripada :values wujud.",same:"Medan :attribute mesti sepadan dengan :other.",size:{array:"Medan :attribute mesti mengandungi :size item.",file:"Medan :attribute mesti :size kilobait.",numeric:"Medan :attribute mesti :size.",string:"Medan :attribute mesti :size huruf."},starts_with:"Medan :attribute mesti bermula dengan salah satu dari berikut: :values.",string:"Medan :attribute mesti perkataan / rentetan aksara.",timezone:"Medan :attribute mesti zon masa yang sah.",unique:"Medan :attribute telah wujud.",uploaded:"Medan :attribute gagal dimuat naik.",uppercase:"Medan :attribute mesti dalam huruf besar.",url:"Medan :attribute mesti URL yang sah.",ulid:"Medan :attribute mesti ULID yang sah.",uuid:"Medan :attribute mesti UUID yang sah.",custom:{"attribute-name":{"rule-name":"custom-message"}},attributes:{},values:{}}}();
|
package/dist/quival.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* quival v0.2.
|
|
2
|
+
* quival v0.2.8 (https://github.com/apih/quival)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -7,10 +7,14 @@ var quival = (function (exports) {
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
9
|
function toCamelCase(string) {
|
|
10
|
-
return string
|
|
10
|
+
return string
|
|
11
|
+
.replace(/[-_]/g, ' ')
|
|
12
|
+
.replace(/\s+/, ' ')
|
|
13
|
+
.trim()
|
|
14
|
+
.replace(/(\s\w)/g, (match) => match[1].toUpperCase());
|
|
11
15
|
}
|
|
12
16
|
function toSnakeCase(string) {
|
|
13
|
-
return string.replace(/(.)(?=[A-Z])/g, match => match + '_').toLowerCase();
|
|
17
|
+
return string.replace(/(.)(?=[A-Z])/g, (match) => match + '_').toLowerCase();
|
|
14
18
|
}
|
|
15
19
|
function escapeRegExp(string) {
|
|
16
20
|
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
@@ -26,8 +30,7 @@ var quival = (function (exports) {
|
|
|
26
30
|
}
|
|
27
31
|
return current;
|
|
28
32
|
}
|
|
29
|
-
function flattenObject(obj) {
|
|
30
|
-
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
33
|
+
function flattenObject(obj, prefix = '') {
|
|
31
34
|
return Object.keys(obj).reduce((accumulator, key) => {
|
|
32
35
|
const prefixedKey = prefix ? `${prefix}.${key}` : key;
|
|
33
36
|
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
@@ -71,21 +74,24 @@ var quival = (function (exports) {
|
|
|
71
74
|
return value;
|
|
72
75
|
}
|
|
73
76
|
let match, years, months, days, hours, minutes, seconds, meridiem;
|
|
74
|
-
const castToIntegers = value => value && /^\d*$/.test(value) ? parseInt(value) : value;
|
|
77
|
+
const castToIntegers = (value) => (value && /^\d*$/.test(value) ? parseInt(value) : value);
|
|
75
78
|
if ((match = value.match(/^(\d{1,2})[.\/-](\d{1,2})[.\/-](\d{2,4})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)) !== null) {
|
|
76
|
-
[, days, months, years
|
|
77
|
-
} else if (
|
|
78
|
-
[,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
[, days, months, years, , hours = 0, minutes = 0, , seconds = 0, meridiem = 'am'] = match.map(castToIntegers);
|
|
80
|
+
} else if (
|
|
81
|
+
(match = value.match(/^(\d{2,4})[.\/-](\d{1,2})[.\/-](\d{1,2})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)) !== null ||
|
|
82
|
+
(match = value.match(/^(\d{4})(\d{2})(\d{2})\s?((\d{2})(\d{2})((\d{2}))?\s?(am|pm)?)?/i)) !== null
|
|
83
|
+
) {
|
|
84
|
+
[, years, months, days, , hours = 0, minutes = 0, , seconds = 0, meridiem = 'am'] = match.map(castToIntegers);
|
|
85
|
+
} else if ((match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{4})[.\/-](\d{2})[.\/-](\d{2})/i))) {
|
|
86
|
+
[, hours, minutes, , seconds, meridiem = 'am', years, months, days] = match.map(castToIntegers);
|
|
87
|
+
} else if ((match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{2})[.\/-](\d{2})[.\/-](\d{4})/i))) {
|
|
88
|
+
[, hours, minutes, , seconds, meridiem = 'am', days, months, years] = match.map(castToIntegers);
|
|
89
|
+
} else if ((match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?/i))) {
|
|
84
90
|
const current = new Date();
|
|
85
91
|
years = current.getFullYear();
|
|
86
92
|
months = current.getMonth() + 1;
|
|
87
93
|
days = current.getDate();
|
|
88
|
-
[, hours = 0, minutes = 0
|
|
94
|
+
[, hours = 0, minutes = 0, , seconds = 0, meridiem = 'am'] = match.map(castToIntegers);
|
|
89
95
|
} else {
|
|
90
96
|
return new Date(value);
|
|
91
97
|
}
|
|
@@ -116,7 +122,7 @@ var quival = (function (exports) {
|
|
|
116
122
|
i: '(\\d{2})',
|
|
117
123
|
s: '(\\d{2})',
|
|
118
124
|
A: '(AM|PM)',
|
|
119
|
-
a: '(am|pm)'
|
|
125
|
+
a: '(am|pm)',
|
|
120
126
|
};
|
|
121
127
|
let pattern = '^';
|
|
122
128
|
let indices = {
|
|
@@ -126,7 +132,7 @@ var quival = (function (exports) {
|
|
|
126
132
|
hours: -1,
|
|
127
133
|
minutes: -1,
|
|
128
134
|
seconds: -1,
|
|
129
|
-
meridiem: -1
|
|
135
|
+
meridiem: -1,
|
|
130
136
|
};
|
|
131
137
|
let index = 1;
|
|
132
138
|
for (const char of format) {
|
|
@@ -156,7 +162,7 @@ var quival = (function (exports) {
|
|
|
156
162
|
if (match === null) {
|
|
157
163
|
return new Date('');
|
|
158
164
|
}
|
|
159
|
-
match = match.map(value => value && /^\d*$/.test(value) ? parseInt(value) : value);
|
|
165
|
+
match = match.map((value) => (value && /^\d*$/.test(value) ? parseInt(value) : value));
|
|
160
166
|
const current = new Date();
|
|
161
167
|
let years = match[indices.years];
|
|
162
168
|
let months = match[indices.months];
|
|
@@ -205,13 +211,13 @@ var quival = (function (exports) {
|
|
|
205
211
|
}
|
|
206
212
|
|
|
207
213
|
class Checkers {
|
|
208
|
-
|
|
209
|
-
#
|
|
210
|
-
#imageCache = {};
|
|
214
|
+
#distinctCache;
|
|
215
|
+
#imageCache;
|
|
211
216
|
constructor(validator) {
|
|
217
|
+
this.#distinctCache = {};
|
|
218
|
+
this.#imageCache = {};
|
|
212
219
|
this.validator = validator;
|
|
213
220
|
}
|
|
214
|
-
|
|
215
221
|
// Internal helpers
|
|
216
222
|
clearCaches() {
|
|
217
223
|
this.#distinctCache = {};
|
|
@@ -219,7 +225,7 @@ var quival = (function (exports) {
|
|
|
219
225
|
}
|
|
220
226
|
isDependent(parameters) {
|
|
221
227
|
const other = this.validator.getValue(parameters[0]);
|
|
222
|
-
return parameters.slice(1).some(value => value == other);
|
|
228
|
+
return parameters.slice(1).some((value) => value == other);
|
|
223
229
|
}
|
|
224
230
|
collectRequiredsThenTest(attribute, value, parameters, callback) {
|
|
225
231
|
let result = [];
|
|
@@ -241,8 +247,7 @@ var quival = (function (exports) {
|
|
|
241
247
|
}
|
|
242
248
|
return true;
|
|
243
249
|
}
|
|
244
|
-
testStringUsingRegex(attribute, value, asciiRegex, unicodeRegex) {
|
|
245
|
-
let isAscii = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
250
|
+
testStringUsingRegex(attribute, value, asciiRegex, unicodeRegex, isAscii = false) {
|
|
246
251
|
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
247
252
|
return false;
|
|
248
253
|
}
|
|
@@ -291,7 +296,6 @@ var quival = (function (exports) {
|
|
|
291
296
|
}
|
|
292
297
|
return callback(value.getTime(), otherValue.getTime());
|
|
293
298
|
}
|
|
294
|
-
|
|
295
299
|
// Type
|
|
296
300
|
checkArray(attribute, value, parameters) {
|
|
297
301
|
if (!(Array.isArray(value) || isPlainObject(value))) {
|
|
@@ -306,6 +310,9 @@ var quival = (function (exports) {
|
|
|
306
310
|
}
|
|
307
311
|
return true;
|
|
308
312
|
}
|
|
313
|
+
checkList(attribute, value, parameters) {
|
|
314
|
+
return Array.isArray(value);
|
|
315
|
+
}
|
|
309
316
|
checkBoolean(attribute, value, parameters) {
|
|
310
317
|
return [true, false, 0, 1, '0', '1'].includes(value);
|
|
311
318
|
}
|
|
@@ -324,7 +331,6 @@ var quival = (function (exports) {
|
|
|
324
331
|
checkString(attribute, value, parameters) {
|
|
325
332
|
return typeof value === 'string';
|
|
326
333
|
}
|
|
327
|
-
|
|
328
334
|
// Numeric
|
|
329
335
|
checkDecimal(attribute, value, parameters) {
|
|
330
336
|
if (!this.checkNumeric(attribute, value)) {
|
|
@@ -351,7 +357,6 @@ var quival = (function (exports) {
|
|
|
351
357
|
}
|
|
352
358
|
return numerator % denominator === 0;
|
|
353
359
|
}
|
|
354
|
-
|
|
355
360
|
// Agreement
|
|
356
361
|
checkAccepted(attribute, value, parameters) {
|
|
357
362
|
return ['yes', 'on', '1', 1, true, 'true'].includes(value);
|
|
@@ -371,7 +376,6 @@ var quival = (function (exports) {
|
|
|
371
376
|
}
|
|
372
377
|
return true;
|
|
373
378
|
}
|
|
374
|
-
|
|
375
379
|
// Existence
|
|
376
380
|
checkRequired(attribute, value, parameters) {
|
|
377
381
|
if (isEmpty(value)) {
|
|
@@ -415,16 +419,16 @@ var quival = (function (exports) {
|
|
|
415
419
|
return true;
|
|
416
420
|
}
|
|
417
421
|
checkRequiredWith(attribute, value, parameters) {
|
|
418
|
-
return this.collectRequiredsThenTest(attribute, value, parameters, result => result.includes(true));
|
|
422
|
+
return this.collectRequiredsThenTest(attribute, value, parameters, (result) => result.includes(true));
|
|
419
423
|
}
|
|
420
424
|
checkRequiredWithAll(attribute, value, parameters) {
|
|
421
|
-
return this.collectRequiredsThenTest(attribute, value, parameters, result => !result.includes(false));
|
|
425
|
+
return this.collectRequiredsThenTest(attribute, value, parameters, (result) => !result.includes(false));
|
|
422
426
|
}
|
|
423
427
|
checkRequiredWithout(attribute, value, parameters) {
|
|
424
|
-
return this.collectRequiredsThenTest(attribute, value, parameters, result => result.includes(false));
|
|
428
|
+
return this.collectRequiredsThenTest(attribute, value, parameters, (result) => result.includes(false));
|
|
425
429
|
}
|
|
426
430
|
checkRequiredWithoutAll(attribute, value, parameters) {
|
|
427
|
-
return this.collectRequiredsThenTest(attribute, value, parameters, result => !result.includes(true));
|
|
431
|
+
return this.collectRequiredsThenTest(attribute, value, parameters, (result) => !result.includes(true));
|
|
428
432
|
}
|
|
429
433
|
checkFilled(attribute, value, parameters) {
|
|
430
434
|
if (typeof value !== 'undefined') {
|
|
@@ -435,7 +439,6 @@ var quival = (function (exports) {
|
|
|
435
439
|
checkPresent(attribute, value, parameters) {
|
|
436
440
|
return typeof value !== 'undefined';
|
|
437
441
|
}
|
|
438
|
-
|
|
439
442
|
// Missing
|
|
440
443
|
checkMissing(attribute, value, parameters) {
|
|
441
444
|
return !this.validator.hasAttribute(attribute);
|
|
@@ -453,12 +456,11 @@ var quival = (function (exports) {
|
|
|
453
456
|
return true;
|
|
454
457
|
}
|
|
455
458
|
checkMissingWith(attribute, value, parameters) {
|
|
456
|
-
return this.collectMissingsThenTest(attribute, value, parameters, result => result.includes(false));
|
|
459
|
+
return this.collectMissingsThenTest(attribute, value, parameters, (result) => result.includes(false));
|
|
457
460
|
}
|
|
458
461
|
checkMissingWithAll(attribute, value, parameters) {
|
|
459
|
-
return this.collectMissingsThenTest(attribute, value, parameters, result => !result.includes(true));
|
|
462
|
+
return this.collectMissingsThenTest(attribute, value, parameters, (result) => !result.includes(true));
|
|
460
463
|
}
|
|
461
|
-
|
|
462
464
|
// Prohibition
|
|
463
465
|
checkProhibited(attribute, value, parameters) {
|
|
464
466
|
return !this.checkRequired(attribute, value);
|
|
@@ -485,7 +487,6 @@ var quival = (function (exports) {
|
|
|
485
487
|
}
|
|
486
488
|
return true;
|
|
487
489
|
}
|
|
488
|
-
|
|
489
490
|
// Size
|
|
490
491
|
checkSize(attribute, value, parameters) {
|
|
491
492
|
return this.validator.getSize(attribute, value) === parseFloat(parameters[0]);
|
|
@@ -499,10 +500,8 @@ var quival = (function (exports) {
|
|
|
499
500
|
checkBetween(attribute, value, parameters) {
|
|
500
501
|
return this.checkMin(attribute, value, [parameters[0]]) && this.checkMax(attribute, value, [parameters[1]]);
|
|
501
502
|
}
|
|
502
|
-
|
|
503
503
|
// Digits
|
|
504
|
-
checkDigits(attribute, value, parameters) {
|
|
505
|
-
let callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : (length, value) => length === value;
|
|
504
|
+
checkDigits(attribute, value, parameters, callback = (length, value) => length === value) {
|
|
506
505
|
value = String(value ?? '');
|
|
507
506
|
if (!isDigits(value)) {
|
|
508
507
|
return false;
|
|
@@ -518,7 +517,6 @@ var quival = (function (exports) {
|
|
|
518
517
|
checkDigitsBetween(attribute, value, parameters) {
|
|
519
518
|
return this.checkDigits(attribute, value, parameters, (length, value1, value2) => length >= value1 && length <= value2);
|
|
520
519
|
}
|
|
521
|
-
|
|
522
520
|
// String
|
|
523
521
|
checkAlpha(attribute, value, parameters) {
|
|
524
522
|
return this.testStringUsingRegex(attribute, value, /^[a-z]+$/i, /^[\p{L}\p{M}]+$/u, parameters.includes('ascii'));
|
|
@@ -532,8 +530,7 @@ var quival = (function (exports) {
|
|
|
532
530
|
checkAscii(attribute, value, parameters) {
|
|
533
531
|
return !/[^\x09\x10\x13\x0A\x0D\x20-\x7E]/.test(value);
|
|
534
532
|
}
|
|
535
|
-
checkRegex(attribute, value, parameters) {
|
|
536
|
-
let invert = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
533
|
+
checkRegex(attribute, value, parameters, invert = false) {
|
|
537
534
|
if (!(typeof value === 'string' || isNumeric(value))) {
|
|
538
535
|
return false;
|
|
539
536
|
}
|
|
@@ -543,7 +540,11 @@ var quival = (function (exports) {
|
|
|
543
540
|
throw new Error(`Invalid regular expression pattern: ${expression}`);
|
|
544
541
|
}
|
|
545
542
|
if (flags.includes('u')) {
|
|
546
|
-
pattern = pattern
|
|
543
|
+
pattern = pattern
|
|
544
|
+
.replace(/\\A/g, '^')
|
|
545
|
+
.replace(/\\z/gi, '$')
|
|
546
|
+
.replace(/\\([pP])([CLMNPSZ])/g, '\\$1{$2}')
|
|
547
|
+
.replace(/\\\x\{([0-9a-f]+)\}/g, '\\u{$1}');
|
|
547
548
|
}
|
|
548
549
|
const result = new RegExp(pattern, flags).test(value);
|
|
549
550
|
return invert ? !result : result;
|
|
@@ -581,7 +582,6 @@ var quival = (function (exports) {
|
|
|
581
582
|
checkDoesntEndWith(attribute, value, parameters) {
|
|
582
583
|
return !this.checkEndsWith(attribute, value, parameters);
|
|
583
584
|
}
|
|
584
|
-
|
|
585
585
|
// Compare values
|
|
586
586
|
checkSame(attribute, value, parameters) {
|
|
587
587
|
const other = this.validator.getValue(parameters[0]);
|
|
@@ -611,7 +611,6 @@ var quival = (function (exports) {
|
|
|
611
611
|
checkLte(attribute, value, parameters) {
|
|
612
612
|
return this.compareValues(attribute, value, parameters, (val1, val2) => val1 <= val2);
|
|
613
613
|
}
|
|
614
|
-
|
|
615
614
|
// Dates
|
|
616
615
|
checkAfter(attribute, value, parameters) {
|
|
617
616
|
return this.compareDates(attribute, value, parameters, (val1, val2) => val1 > val2);
|
|
@@ -644,7 +643,7 @@ var quival = (function (exports) {
|
|
|
644
643
|
i: '(\\d{2})',
|
|
645
644
|
s: '(\\d{2})',
|
|
646
645
|
A: '(AM|PM)',
|
|
647
|
-
a: '(am|pm)'
|
|
646
|
+
a: '(am|pm)',
|
|
648
647
|
};
|
|
649
648
|
let pattern = '^';
|
|
650
649
|
for (const char of format) {
|
|
@@ -657,7 +656,6 @@ var quival = (function (exports) {
|
|
|
657
656
|
pattern += '$';
|
|
658
657
|
return new RegExp(pattern).test(value);
|
|
659
658
|
}
|
|
660
|
-
|
|
661
659
|
// Array / Object
|
|
662
660
|
checkDistinct(attribute, value, parameters) {
|
|
663
661
|
const unparsed = this.validator.getPrimaryAttribute(attribute);
|
|
@@ -697,14 +695,14 @@ var quival = (function (exports) {
|
|
|
697
695
|
return false;
|
|
698
696
|
}
|
|
699
697
|
const data = this.validator.getValue(unparsed.split('.*')[0]) ?? {};
|
|
700
|
-
return Object.values(flattenObject(data)).some(item => item == value);
|
|
698
|
+
return Object.values(flattenObject(data)).some((item) => item == value);
|
|
701
699
|
}
|
|
702
700
|
checkIn(attribute, value, parameters) {
|
|
703
701
|
if (!(this.checkArray(attribute, value) && this.validator.hasRule(attribute, 'array'))) {
|
|
704
|
-
return parameters.some(parameter => parameter == value);
|
|
702
|
+
return parameters.some((parameter) => parameter == value);
|
|
705
703
|
}
|
|
706
704
|
for (const item of Object.values(value)) {
|
|
707
|
-
if (!parameters.some(parameter => parameter == item)) {
|
|
705
|
+
if (!parameters.some((parameter) => parameter == item)) {
|
|
708
706
|
return false;
|
|
709
707
|
}
|
|
710
708
|
}
|
|
@@ -713,7 +711,6 @@ var quival = (function (exports) {
|
|
|
713
711
|
checkNotIn(attribute, value, parameters) {
|
|
714
712
|
return !this.checkIn(attribute, value, parameters);
|
|
715
713
|
}
|
|
716
|
-
|
|
717
714
|
// File
|
|
718
715
|
checkMimetypes(attribute, value, parameters) {
|
|
719
716
|
if (this.checkFile(attribute, value)) {
|
|
@@ -737,17 +734,19 @@ var quival = (function (exports) {
|
|
|
737
734
|
}
|
|
738
735
|
await new Promise((resolve, reject) => {
|
|
739
736
|
const reader = new FileReader();
|
|
740
|
-
reader.onload = event => resolve(event.target.result);
|
|
737
|
+
reader.onload = (event) => resolve(event.target.result);
|
|
741
738
|
reader.onerror = reject;
|
|
742
739
|
reader.readAsDataURL(value);
|
|
743
|
-
})
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
740
|
+
})
|
|
741
|
+
.then(async (data) => {
|
|
742
|
+
const image = new Image();
|
|
743
|
+
image.src = data;
|
|
744
|
+
await image.decode();
|
|
745
|
+
this.#imageCache[attribute] = image;
|
|
746
|
+
})
|
|
747
|
+
.catch(() => {
|
|
748
|
+
result = false;
|
|
749
|
+
});
|
|
751
750
|
return result;
|
|
752
751
|
}
|
|
753
752
|
async checkDimensions(attribute, value, parameters) {
|
|
@@ -758,7 +757,7 @@ var quival = (function (exports) {
|
|
|
758
757
|
for (const parameter of parameters) {
|
|
759
758
|
const [key, value] = parameter.split('=', 2);
|
|
760
759
|
if (key === 'ratio' && value.includes('/')) {
|
|
761
|
-
const [numerator, denominator] = value.split('/', 2).map(part => parseFloat(part, 10));
|
|
760
|
+
const [numerator, denominator] = value.split('/', 2).map((part) => parseFloat(part, 10));
|
|
762
761
|
constraints[key] = numerator / denominator;
|
|
763
762
|
} else {
|
|
764
763
|
constraints[key] = parseFloat(value, 10);
|
|
@@ -767,7 +766,14 @@ var quival = (function (exports) {
|
|
|
767
766
|
const image = this.#imageCache[attribute];
|
|
768
767
|
const width = image.naturalWidth;
|
|
769
768
|
const height = image.naturalHeight;
|
|
770
|
-
if (
|
|
769
|
+
if (
|
|
770
|
+
(constraints.hasOwnProperty('width') && constraints.width !== width) ||
|
|
771
|
+
(constraints.hasOwnProperty('height') && constraints.height !== height) ||
|
|
772
|
+
(constraints.hasOwnProperty('min_width') && constraints.min_width > width) ||
|
|
773
|
+
(constraints.hasOwnProperty('min_height') && constraints.min_height > height) ||
|
|
774
|
+
(constraints.hasOwnProperty('max_width') && constraints.max_width < width) ||
|
|
775
|
+
(constraints.hasOwnProperty('max_height') && constraints.max_height < height)
|
|
776
|
+
) {
|
|
771
777
|
return false;
|
|
772
778
|
}
|
|
773
779
|
if (constraints.hasOwnProperty('ratio')) {
|
|
@@ -775,12 +781,13 @@ var quival = (function (exports) {
|
|
|
775
781
|
}
|
|
776
782
|
return true;
|
|
777
783
|
}
|
|
778
|
-
|
|
779
784
|
// Miscellaneous
|
|
780
785
|
checkEmail(attribute, value, parameters) {
|
|
781
|
-
const firstRegex =
|
|
786
|
+
const firstRegex =
|
|
787
|
+
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
782
788
|
if (!firstRegex.test(value)) {
|
|
783
|
-
const secondRegex =
|
|
789
|
+
const secondRegex =
|
|
790
|
+
/^((?:[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]|[^\u0000-\u007F])+@(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?(?:\.(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?)+)*$/;
|
|
784
791
|
return secondRegex.test(value);
|
|
785
792
|
}
|
|
786
793
|
return true;
|
|
@@ -801,7 +808,7 @@ var quival = (function (exports) {
|
|
|
801
808
|
const separators = {
|
|
802
809
|
'-': 2,
|
|
803
810
|
':': 2,
|
|
804
|
-
'.': 4
|
|
811
|
+
'.': 4,
|
|
805
812
|
};
|
|
806
813
|
let separator, digits;
|
|
807
814
|
for ([separator, digits] of Object.entries(separators)) {
|
|
@@ -857,7 +864,7 @@ var quival = (function (exports) {
|
|
|
857
864
|
checkTimezone(attribute, value, parameters) {
|
|
858
865
|
try {
|
|
859
866
|
Intl.DateTimeFormat(undefined, {
|
|
860
|
-
timeZone: value
|
|
867
|
+
timeZone: value,
|
|
861
868
|
});
|
|
862
869
|
} catch (error) {
|
|
863
870
|
if (String(error).toLowerCase().includes('invalid time zone')) {
|
|
@@ -883,7 +890,7 @@ var quival = (function (exports) {
|
|
|
883
890
|
}
|
|
884
891
|
|
|
885
892
|
class ErrorBag {
|
|
886
|
-
#data
|
|
893
|
+
#data;
|
|
887
894
|
keys() {
|
|
888
895
|
return Object.keys(this.#data);
|
|
889
896
|
}
|
|
@@ -927,12 +934,12 @@ var quival = (function (exports) {
|
|
|
927
934
|
}
|
|
928
935
|
all() {
|
|
929
936
|
const result = [];
|
|
930
|
-
this.values().forEach(messages => result.push(...messages));
|
|
937
|
+
this.values().forEach((messages) => result.push(...messages));
|
|
931
938
|
return result;
|
|
932
939
|
}
|
|
933
940
|
count() {
|
|
934
941
|
let count = 0;
|
|
935
|
-
this.values().forEach(messages => count += messages.length);
|
|
942
|
+
this.values().forEach((messages) => (count += messages.length));
|
|
936
943
|
return count;
|
|
937
944
|
}
|
|
938
945
|
isEmpty() {
|
|
@@ -941,6 +948,9 @@ var quival = (function (exports) {
|
|
|
941
948
|
isNotEmpty() {
|
|
942
949
|
return !this.isEmpty();
|
|
943
950
|
}
|
|
951
|
+
constructor() {
|
|
952
|
+
this.#data = {};
|
|
953
|
+
}
|
|
944
954
|
}
|
|
945
955
|
|
|
946
956
|
class Lang {
|
|
@@ -971,45 +981,38 @@ var quival = (function (exports) {
|
|
|
971
981
|
}
|
|
972
982
|
|
|
973
983
|
class Replacers {
|
|
974
|
-
validator;
|
|
975
984
|
constructor(validator) {
|
|
976
985
|
this.validator = validator;
|
|
977
986
|
}
|
|
978
987
|
replace(message, data) {
|
|
979
|
-
Object.entries(data).forEach(
|
|
980
|
-
let [key, value] = _ref;
|
|
981
|
-
return message = message.replaceAll(':' + key, value);
|
|
982
|
-
});
|
|
988
|
+
Object.entries(data).forEach(([key, value]) => (message = message.replaceAll(':' + key, value)));
|
|
983
989
|
return message;
|
|
984
990
|
}
|
|
985
|
-
|
|
986
991
|
// Numeric
|
|
987
992
|
replaceDecimal(message, attribute, rule, parameters) {
|
|
988
993
|
return this.replace(message, {
|
|
989
|
-
decimal: parameters.join('-')
|
|
994
|
+
decimal: parameters.join('-'),
|
|
990
995
|
});
|
|
991
996
|
}
|
|
992
997
|
replaceMultipleOf(message, attribute, rule, parameters) {
|
|
993
998
|
return this.replace(message, {
|
|
994
|
-
value: parameters[0]
|
|
999
|
+
value: parameters[0],
|
|
995
1000
|
});
|
|
996
1001
|
}
|
|
997
|
-
|
|
998
1002
|
// Agreement
|
|
999
1003
|
replaceAcceptedIf(message, attribute, rule, parameters) {
|
|
1000
1004
|
return this.replace(message, {
|
|
1001
1005
|
other: this.validator.getDisplayableAttribute(parameters[0]),
|
|
1002
|
-
value: this.validator.getDisplayableValue(parameters[0], this.validator.getValue(parameters[0]))
|
|
1006
|
+
value: this.validator.getDisplayableValue(parameters[0], this.validator.getValue(parameters[0])),
|
|
1003
1007
|
});
|
|
1004
1008
|
}
|
|
1005
1009
|
replaceDeclinedIf(message, attribute, rule, parameters) {
|
|
1006
1010
|
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
1007
1011
|
}
|
|
1008
|
-
|
|
1009
1012
|
// Existence
|
|
1010
1013
|
replaceRequiredArrayKeys(message, attribute, rule, parameters) {
|
|
1011
1014
|
return this.replace(message, {
|
|
1012
|
-
values: parameters.map(value => this.validator.getDisplayableValue(attribute, value)).join(', ')
|
|
1015
|
+
values: parameters.map((value) => this.validator.getDisplayableValue(attribute, value)).join(', '),
|
|
1013
1016
|
});
|
|
1014
1017
|
}
|
|
1015
1018
|
replaceRequiredIf(message, attribute, rule, parameters) {
|
|
@@ -1021,12 +1024,15 @@ var quival = (function (exports) {
|
|
|
1021
1024
|
replaceRequiredUnless(message, attribute, rule, parameters) {
|
|
1022
1025
|
return this.replace(message, {
|
|
1023
1026
|
other: this.validator.getDisplayableAttribute(parameters[0]),
|
|
1024
|
-
values: parameters
|
|
1027
|
+
values: parameters
|
|
1028
|
+
.slice(1)
|
|
1029
|
+
.map((value) => this.validator.getDisplayableValue(parameters[0], value))
|
|
1030
|
+
.join(', '),
|
|
1025
1031
|
});
|
|
1026
1032
|
}
|
|
1027
1033
|
replaceRequiredWith(message, attribute, rule, parameters) {
|
|
1028
1034
|
return this.replace(message, {
|
|
1029
|
-
values: parameters.map(value => this.validator.getDisplayableAttribute(value)).join(' / ')
|
|
1035
|
+
values: parameters.map((value) => this.validator.getDisplayableAttribute(value)).join(' / '),
|
|
1030
1036
|
});
|
|
1031
1037
|
}
|
|
1032
1038
|
replaceRequiredWithAll(message, attribute, rule, parameters) {
|
|
@@ -1038,14 +1044,13 @@ var quival = (function (exports) {
|
|
|
1038
1044
|
replaceRequiredWithoutAll(message, attribute, rule, parameters) {
|
|
1039
1045
|
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
1040
1046
|
}
|
|
1041
|
-
|
|
1042
1047
|
// Missing
|
|
1043
1048
|
replaceMissingIf(message, attribute, rule, parameters) {
|
|
1044
1049
|
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
1045
1050
|
}
|
|
1046
1051
|
replaceMissingUnless(message, attribute, rule, parameters) {
|
|
1047
1052
|
return this.replace(this.replaceRequiredUnless(message, attribute, rule, parameters), {
|
|
1048
|
-
value: this.validator.getDisplayableValue(parameters[0], parameters[1])
|
|
1053
|
+
value: this.validator.getDisplayableValue(parameters[0], parameters[1]),
|
|
1049
1054
|
});
|
|
1050
1055
|
}
|
|
1051
1056
|
replaceMissingWith(message, attribute, rule, parameters) {
|
|
@@ -1054,7 +1059,6 @@ var quival = (function (exports) {
|
|
|
1054
1059
|
replaceMissingWithAll(message, attribute, rule, parameters) {
|
|
1055
1060
|
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
1056
1061
|
}
|
|
1057
|
-
|
|
1058
1062
|
// Prohibition
|
|
1059
1063
|
replaceProhibitedIf(message, attribute, rule, parameters) {
|
|
1060
1064
|
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
@@ -1064,37 +1068,35 @@ var quival = (function (exports) {
|
|
|
1064
1068
|
}
|
|
1065
1069
|
replaceProhibits(message, attribute, rule, parameters) {
|
|
1066
1070
|
return this.replace(message, {
|
|
1067
|
-
other: parameters.map(value => this.validator.getDisplayableAttribute(value)).join(' / ')
|
|
1071
|
+
other: parameters.map((value) => this.validator.getDisplayableAttribute(value)).join(' / '),
|
|
1068
1072
|
});
|
|
1069
1073
|
}
|
|
1070
|
-
|
|
1071
1074
|
// Size
|
|
1072
1075
|
replaceSize(message, attribute, rule, parameters) {
|
|
1073
1076
|
return this.replace(message, {
|
|
1074
|
-
size: parameters[0]
|
|
1077
|
+
size: parameters[0],
|
|
1075
1078
|
});
|
|
1076
1079
|
}
|
|
1077
1080
|
replaceMin(message, attribute, rule, parameters) {
|
|
1078
1081
|
return this.replace(message, {
|
|
1079
|
-
min: parameters[0]
|
|
1082
|
+
min: parameters[0],
|
|
1080
1083
|
});
|
|
1081
1084
|
}
|
|
1082
1085
|
replaceMax(message, attribute, rule, parameters) {
|
|
1083
1086
|
return this.replace(message, {
|
|
1084
|
-
max: parameters[0]
|
|
1087
|
+
max: parameters[0],
|
|
1085
1088
|
});
|
|
1086
1089
|
}
|
|
1087
1090
|
replaceBetween(message, attribute, rule, parameters) {
|
|
1088
1091
|
return this.replace(message, {
|
|
1089
1092
|
min: parameters[0],
|
|
1090
|
-
max: parameters[1]
|
|
1093
|
+
max: parameters[1],
|
|
1091
1094
|
});
|
|
1092
1095
|
}
|
|
1093
|
-
|
|
1094
1096
|
// Digits
|
|
1095
1097
|
replaceDigits(message, attribute, rule, parameters) {
|
|
1096
1098
|
return this.replace(message, {
|
|
1097
|
-
digits: parameters[0]
|
|
1099
|
+
digits: parameters[0],
|
|
1098
1100
|
});
|
|
1099
1101
|
}
|
|
1100
1102
|
replaceMinDigits(message, attribute, rule, parameters) {
|
|
@@ -1106,7 +1108,6 @@ var quival = (function (exports) {
|
|
|
1106
1108
|
replaceDigitsBetween(message, attribute, rule, parameters) {
|
|
1107
1109
|
return this.replaceBetween(message, attribute, rule, parameters);
|
|
1108
1110
|
}
|
|
1109
|
-
|
|
1110
1111
|
// String
|
|
1111
1112
|
replaceStartsWith(message, attribute, rule, parameters) {
|
|
1112
1113
|
return this.replaceRequiredArrayKeys(message, attribute, rule, parameters);
|
|
@@ -1120,7 +1121,6 @@ var quival = (function (exports) {
|
|
|
1120
1121
|
replaceDoesntEndWith(message, attribute, rule, parameters) {
|
|
1121
1122
|
return this.replaceRequiredArrayKeys(message, attribute, rule, parameters);
|
|
1122
1123
|
}
|
|
1123
|
-
|
|
1124
1124
|
// Compare values
|
|
1125
1125
|
replaceSame(message, attribute, rule, parameters) {
|
|
1126
1126
|
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
@@ -1131,7 +1131,7 @@ var quival = (function (exports) {
|
|
|
1131
1131
|
replaceGt(message, attribute, rule, parameters) {
|
|
1132
1132
|
const value = this.validator.getValue(parameters[0]);
|
|
1133
1133
|
return this.replace(message, {
|
|
1134
|
-
value: value ? this.validator.getSize(parameters[0], value) : this.validator.getDisplayableAttribute(parameters[0])
|
|
1134
|
+
value: value ? this.validator.getSize(parameters[0], value) : this.validator.getDisplayableAttribute(parameters[0]),
|
|
1135
1135
|
});
|
|
1136
1136
|
}
|
|
1137
1137
|
replaceGte(message, attribute, rule, parameters) {
|
|
@@ -1143,12 +1143,11 @@ var quival = (function (exports) {
|
|
|
1143
1143
|
replaceLte(message, attribute, rule, parameters) {
|
|
1144
1144
|
return this.replaceGt(message, attribute, rule, parameters);
|
|
1145
1145
|
}
|
|
1146
|
-
|
|
1147
1146
|
// Dates
|
|
1148
1147
|
replaceAfter(message, attribute, rule, parameters) {
|
|
1149
1148
|
const other = parameters[0];
|
|
1150
1149
|
return this.replace(message, {
|
|
1151
|
-
date: this.validator.hasAttribute(other) ? this.validator.getDisplayableAttribute(other) : other
|
|
1150
|
+
date: this.validator.hasAttribute(other) ? this.validator.getDisplayableAttribute(other) : other,
|
|
1152
1151
|
});
|
|
1153
1152
|
}
|
|
1154
1153
|
replaceAfterOrEqual(message, attribute, rule, parameters) {
|
|
@@ -1165,10 +1164,9 @@ var quival = (function (exports) {
|
|
|
1165
1164
|
}
|
|
1166
1165
|
replaceDateFormat(message, attribute, rule, parameters) {
|
|
1167
1166
|
return this.replace(message, {
|
|
1168
|
-
format: parameters[0]
|
|
1167
|
+
format: parameters[0],
|
|
1169
1168
|
});
|
|
1170
1169
|
}
|
|
1171
|
-
|
|
1172
1170
|
// Array
|
|
1173
1171
|
replaceInArray(message, attribute, rule, parameters) {
|
|
1174
1172
|
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
@@ -1179,11 +1177,10 @@ var quival = (function (exports) {
|
|
|
1179
1177
|
replaceNotIn(message, attribute, rule, parameters) {
|
|
1180
1178
|
return this.replaceRequiredArrayKeys(message, attribute, rule, parameters);
|
|
1181
1179
|
}
|
|
1182
|
-
|
|
1183
1180
|
// File
|
|
1184
1181
|
replaceMimetypes(message, attribute, rule, parameters) {
|
|
1185
1182
|
return this.replace(message, {
|
|
1186
|
-
values: parameters.join(', ')
|
|
1183
|
+
values: parameters.join(', '),
|
|
1187
1184
|
});
|
|
1188
1185
|
}
|
|
1189
1186
|
replaceMimes(message, attribute, rule, parameters) {
|
|
@@ -1197,8 +1194,43 @@ var quival = (function (exports) {
|
|
|
1197
1194
|
class Validator {
|
|
1198
1195
|
static #customCheckers = {};
|
|
1199
1196
|
static #customReplacers = {};
|
|
1200
|
-
static #dummyRules = [
|
|
1201
|
-
|
|
1197
|
+
static #dummyRules = [
|
|
1198
|
+
'active_url',
|
|
1199
|
+
'bail',
|
|
1200
|
+
'can',
|
|
1201
|
+
'current_password',
|
|
1202
|
+
'enum',
|
|
1203
|
+
'exclude',
|
|
1204
|
+
'exclude_if',
|
|
1205
|
+
'exclude_unless',
|
|
1206
|
+
'exclude_with',
|
|
1207
|
+
'exclude_without',
|
|
1208
|
+
'exists',
|
|
1209
|
+
'nullable',
|
|
1210
|
+
'sometimes',
|
|
1211
|
+
'unique',
|
|
1212
|
+
];
|
|
1213
|
+
static #implicitRules = [
|
|
1214
|
+
'accepted',
|
|
1215
|
+
'accepted_if',
|
|
1216
|
+
'declined',
|
|
1217
|
+
'declined_if',
|
|
1218
|
+
'filled',
|
|
1219
|
+
'missing',
|
|
1220
|
+
'missing_if',
|
|
1221
|
+
'missing_unless',
|
|
1222
|
+
'missing_with',
|
|
1223
|
+
'missing_with_all',
|
|
1224
|
+
'present',
|
|
1225
|
+
'required',
|
|
1226
|
+
'required_if',
|
|
1227
|
+
'required_if_accepted',
|
|
1228
|
+
'required_unless',
|
|
1229
|
+
'required_with',
|
|
1230
|
+
'required_with_all',
|
|
1231
|
+
'required_without',
|
|
1232
|
+
'required_without_all',
|
|
1233
|
+
];
|
|
1202
1234
|
#data;
|
|
1203
1235
|
#rules;
|
|
1204
1236
|
#customMessages;
|
|
@@ -1207,12 +1239,9 @@ var quival = (function (exports) {
|
|
|
1207
1239
|
#checkers;
|
|
1208
1240
|
#replacers;
|
|
1209
1241
|
#errors;
|
|
1210
|
-
#implicitAttributes
|
|
1211
|
-
#stopOnFirstFailure
|
|
1212
|
-
#alwaysBail
|
|
1213
|
-
fileRules = ['file', 'image', 'mimetypes', 'mimes'];
|
|
1214
|
-
numericRules = ['decimal', 'numeric', 'integer'];
|
|
1215
|
-
sizeRules = ['size', 'between', 'min', 'max', 'gt', 'lt', 'gte', 'lte'];
|
|
1242
|
+
#implicitAttributes;
|
|
1243
|
+
#stopOnFirstFailure;
|
|
1244
|
+
#alwaysBail;
|
|
1216
1245
|
static setLocale(locale) {
|
|
1217
1246
|
Lang.locale(locale);
|
|
1218
1247
|
}
|
|
@@ -1235,12 +1264,13 @@ var quival = (function (exports) {
|
|
|
1235
1264
|
static addDummyRule(rule) {
|
|
1236
1265
|
Validator.#dummyRules.push(rule);
|
|
1237
1266
|
}
|
|
1238
|
-
constructor() {
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1267
|
+
constructor(data = {}, rules = {}, messages = {}, attributes = {}, values = {}) {
|
|
1268
|
+
this.#implicitAttributes = {};
|
|
1269
|
+
this.#stopOnFirstFailure = false;
|
|
1270
|
+
this.#alwaysBail = false;
|
|
1271
|
+
this.fileRules = ['file', 'image', 'mimetypes', 'mimes'];
|
|
1272
|
+
this.numericRules = ['decimal', 'numeric', 'integer'];
|
|
1273
|
+
this.sizeRules = ['size', 'between', 'min', 'max', 'gt', 'lt', 'gte', 'lte'];
|
|
1244
1274
|
this.setProperties(data, rules, messages, attributes, values);
|
|
1245
1275
|
this.#checkers = new Checkers(this);
|
|
1246
1276
|
this.#replacers = new Replacers(this);
|
|
@@ -1252,12 +1282,7 @@ var quival = (function (exports) {
|
|
|
1252
1282
|
}
|
|
1253
1283
|
this.#errors = new ErrorBag();
|
|
1254
1284
|
}
|
|
1255
|
-
setProperties() {
|
|
1256
|
-
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1257
|
-
let rules = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1258
|
-
let messages = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
1259
|
-
let attributes = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1260
|
-
let values = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
1285
|
+
setProperties(data = {}, rules = {}, messages = {}, attributes = {}, values = {}) {
|
|
1261
1286
|
this.#data = data;
|
|
1262
1287
|
this.#rules = this.parseRules(rules);
|
|
1263
1288
|
this.#customMessages = messages;
|
|
@@ -1289,13 +1314,11 @@ var quival = (function (exports) {
|
|
|
1289
1314
|
this.#implicitAttributes[implicitAttribute] = attribute;
|
|
1290
1315
|
return this;
|
|
1291
1316
|
}
|
|
1292
|
-
stopOnFirstFailure() {
|
|
1293
|
-
let flag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
1317
|
+
stopOnFirstFailure(flag = true) {
|
|
1294
1318
|
this.#stopOnFirstFailure = flag;
|
|
1295
1319
|
return this;
|
|
1296
1320
|
}
|
|
1297
|
-
alwaysBail() {
|
|
1298
|
-
let flag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
1321
|
+
alwaysBail(flag = true) {
|
|
1299
1322
|
this.#alwaysBail = flag;
|
|
1300
1323
|
return this;
|
|
1301
1324
|
}
|
|
@@ -1323,12 +1346,11 @@ var quival = (function (exports) {
|
|
|
1323
1346
|
if (!(Array.isArray(data) || isPlainObject(data))) {
|
|
1324
1347
|
return [attribute];
|
|
1325
1348
|
}
|
|
1326
|
-
Object.entries(data).forEach(
|
|
1327
|
-
let [key, value] = _ref;
|
|
1349
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
1328
1350
|
const implicitAttribute = `${parentPath}.${key}.${childPath}`.replace(/\.$/, '');
|
|
1329
1351
|
const implicitAttributes = implicitAttribute.includes('*') ? this.parseWildcardAttribute(implicitAttribute) : [implicitAttribute];
|
|
1330
1352
|
attributes.push(...implicitAttributes);
|
|
1331
|
-
implicitAttributes.forEach(value => this.#implicitAttributes[value] = attribute);
|
|
1353
|
+
implicitAttributes.forEach((value) => (this.#implicitAttributes[value] = attribute));
|
|
1332
1354
|
});
|
|
1333
1355
|
return attributes;
|
|
1334
1356
|
}
|
|
@@ -1365,7 +1387,10 @@ var quival = (function (exports) {
|
|
|
1365
1387
|
if (rule === '') {
|
|
1366
1388
|
continue;
|
|
1367
1389
|
}
|
|
1368
|
-
if (
|
|
1390
|
+
if (
|
|
1391
|
+
!Validator.#implicitRules.includes(rule) &&
|
|
1392
|
+
(typeof value === 'undefined' || (typeof value === 'string' && value.trim() === '') || (isNullable && value === null))
|
|
1393
|
+
) {
|
|
1369
1394
|
continue;
|
|
1370
1395
|
}
|
|
1371
1396
|
let result, status, message;
|
|
@@ -1380,10 +1405,7 @@ var quival = (function (exports) {
|
|
|
1380
1405
|
if (typeof result === 'boolean') {
|
|
1381
1406
|
status = result;
|
|
1382
1407
|
} else {
|
|
1383
|
-
({
|
|
1384
|
-
status,
|
|
1385
|
-
message
|
|
1386
|
-
} = result);
|
|
1408
|
+
({ status, message } = result);
|
|
1387
1409
|
}
|
|
1388
1410
|
if (!status) {
|
|
1389
1411
|
hasError = true;
|
|
@@ -1451,7 +1473,7 @@ var quival = (function (exports) {
|
|
|
1451
1473
|
attribute: attributeName,
|
|
1452
1474
|
ATTRIBUTE: attributeName.toLocaleUpperCase(),
|
|
1453
1475
|
Attribute: attributeName.charAt(0).toLocaleUpperCase() + attributeName.substring(1),
|
|
1454
|
-
input: this.getDisplayableValue(attribute, value)
|
|
1476
|
+
input: this.getDisplayableValue(attribute, value),
|
|
1455
1477
|
};
|
|
1456
1478
|
for (const [key, value] of Object.entries(data)) {
|
|
1457
1479
|
message = message.replaceAll(':' + key, value);
|
|
@@ -1547,5 +1569,4 @@ var quival = (function (exports) {
|
|
|
1547
1569
|
exports.Validator = Validator;
|
|
1548
1570
|
|
|
1549
1571
|
return exports;
|
|
1550
|
-
|
|
1551
1572
|
})({});
|
package/dist/quival.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* quival v0.2.
|
|
2
|
+
* quival v0.2.8 (https://github.com/apih/quival)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
var quival=function(e){"use strict";function t(e){return e.replace(/[-_]/g," ").replace(/\s+/," ").trim().replace(/(\s\w)/g,(e=>e[1].toUpperCase()))}function r(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function s(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return Object.keys(e).reduce(((r,i)=>{const a=t?`${t}.${i}`:i;return"object"==typeof e[i]&&null!==e[i]?Object.assign(r,s(e[i],a)):r[a]=e[i],r}),{})}function i(e){const t=[];let r="",s=!1;for(let i=0;i<e.length;i++){const a=e[i];'"'===a?s&&'"'===e[i+1]?(r+='"',i++):(s=!s,s&&(r=r.trim())):","!==a||s?r+=a:(t.push(r),r="")}return t.push(r),t}function a(e){if(n(e)||"string"!=typeof e)return new Date("");if(e instanceof Date)return e;let t,r,s,i,a,c,l,h;const u=e=>e&&/^\d*$/.test(e)?parseInt(e):e;if(null!==(t=e.match(/^(\d{1,2})[.\/-](\d{1,2})[.\/-](\d{2,4})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)))[,i,s,r,,a=0,c=0,,l=0,h="am"]=t.map(u);else if(null!==(t=e.match(/^(\d{2,4})[.\/-](\d{1,2})[.\/-](\d{1,2})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i))||null!==(t=e.match(/^(\d{4})(\d{2})(\d{2})\s?((\d{2})(\d{2})((\d{2}))?\s?(am|pm)?)?/i)))[,r,s,i,,a=0,c=0,,l=0,h="am"]=t.map(u);else if(t=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{4})[.\/-](\d{2})[.\/-](\d{2})/i))[,a,c,,l,h="am",r,s,i]=t.map(u);else if(t=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{2})[.\/-](\d{2})[.\/-](\d{4})/i))[,a,c,,l,h="am",i,s,r]=t.map(u);else{if(!(t=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?/i)))return new Date(e);{const e=new Date;r=e.getFullYear(),s=e.getMonth()+1,i=e.getDate(),[,a=0,c=0,,l=0,h="am"]=t.map(u)}}return r>=10&&r<100&&(r+=2e3),"pm"===h.toLowerCase()&&a<12&&(a+=12),new Date(`${r}-${s}-${i} ${a}:${c}:${l}`)}function c(e,t){if(n(e))return new Date("");t=t.split("");const r={Y:"(\\d{4})",y:"(\\d{2})",m:"(\\d{2})",n:"([1-9]\\d?)",d:"(\\d{2})",j:"([1-9]\\d?)",G:"([1-9]\\d?)",g:"([1-9]\\d?)",H:"(\\d{2})",h:"(\\d{2})",i:"(\\d{2})",s:"(\\d{2})",A:"(AM|PM)",a:"(am|pm)"};let s="^",i={years:-1,months:-1,days:-1,hours:-1,minutes:-1,seconds:-1,meridiem:-1},a=1;for(const e of t)r.hasOwnProperty(e)?(s+=r[e],-1!==["Y","y"].indexOf(e)?i.years=a++:-1!==["m","n"].indexOf(e)?i.months=a++:-1!==["d","j"].indexOf(e)?i.days=a++:-1!==["G","g","H","h"].indexOf(e)?i.hours=a++:"i"===e?i.minutes=a++:"s"===e?i.seconds=a++:-1!==["A","a"].indexOf(e)&&(i.meridiem=a++)):s+="\\"+e;s+="$";let c=e.match(new RegExp(s));if(null===c)return new Date("");c=c.map((e=>e&&/^\d*$/.test(e)?parseInt(e):e));const l=new Date;let h=c[i.years],u=c[i.months],o=c[i.days],p=c[i.hours]??0,d=c[i.minutes]??0,g=c[i.seconds]??0,f=c[i.meridiem]??"am";return h||u||o?!h||u||o?h||!u||o?h||u||!o||(h=l.getFullYear(),u=l.getMonth()+1):(h=l.getFullYear(),o=1):(u=1,o=1):(h=l.getFullYear(),u=l.getMonth()+1,o=l.getDate()),h>=10&&h<100&&(h+=2e3),"pm"===f.toLowerCase()&&p<12&&(p+=12),new Date(`${h}-${u}-${o} ${p}:${d}:${g}`)}function n(e){return""===e||null==e}function l(e){const t=Number(e);return null!==e&&"boolean"!=typeof e&&"number"==typeof t&&!isNaN(t)}function h(e){return"[object Object]"===Object.prototype.toString.call(e)}function u(e){return e instanceof Date&&"Invalid Date"!==e.toDateString()}class o{validator;#e={};#t={};constructor(e){this.validator=e}clearCaches(){this.#e={},this.#t={}}isDependent(e){const t=this.validator.getValue(e[0]);return e.slice(1).some((e=>e==t))}collectRequiredsThenTest(e,t,r,s){let i=[];for(const e of r)i.push(this.checkRequired(e,this.validator.getValue(e)));return!s(i)||this.checkRequired(e,t)}collectMissingsThenTest(e,t,r,s){let i=[];for(const e of r)i.push(this.checkMissing(e));return!s(i)||this.checkMissing(e)}testStringUsingRegex(e,t,r,s){let i=arguments.length>4&&void 0!==arguments[4]&&arguments[4];return("string"==typeof t||"number"==typeof t)&&(t=String(t),i||this.validator.hasRule(e,"ascii")?r.test(t):s.test(t))}compareValues(e,t,r,s){if(n(t))return!1;const i=r[0]??"";let a=this.validator.getValue(i);return a=void 0===a?l(i)?parseFloat(i,10):null:this.validator.getSize(i,a),!n(a)&&s(this.validator.getSize(e,t),a)}compareDates(e,t,r,s){const i=this.validator.getRule(e);if(!u(t=i.hasOwnProperty("date_format")?c(t,i.date_format[0]):a(t)))return!1;const n=r[0]??"";let l=this.validator.getValue(n);if(void 0===l)l=a(n);else{const e=this.validator.getRule(n);l=e.hasOwnProperty("date_format")?c(l,e.date_format[0]):a(l)}return!!u(l)&&s(t.getTime(),l.getTime())}checkArray(e,t,r){if(!Array.isArray(t)&&!h(t))return!1;if(r&&r.length>0)for(const e of Object.keys(t))if(!r.includes(e))return!1;return!0}checkBoolean(e,t,r){return[!0,!1,0,1,"0","1"].includes(t)}checkDate(e,t,r){return u(a(t))}checkFile(e,t,r){return t instanceof File}checkInteger(e,t,r){return String(parseInt(t,10))===String(t)}checkNumeric(e,t,r){return l(t)}checkString(e,t,r){return"string"==typeof t}checkDecimal(e,t,r){if(!this.checkNumeric(e,t))return!1;const s=(String(t).split(".")[1]??"").length;return 1===r.length?s==r[0]:s>=r[0]&&s<=r[1]}checkMultipleOf(e,t,r){if(!l(t)||!l(r[0]))return!1;const s=parseInt(t,10),i=parseInt(r[0],10);return(0!==s||0!==i)&&(0===s||0!==i&&s%i==0)}checkAccepted(e,t,r){return["yes","on","1",1,!0,"true"].includes(t)}checkAcceptedIf(e,t,r){return!this.isDependent(r)||this.checkAccepted(e,t,r)}checkDeclined(e,t,r){return["no","off","0",0,!1,"false"].includes(t)}checkDeclinedIf(e,t,r){return!this.isDependent(r)||this.checkDeclined(e,t,r)}checkRequired(e,t,r){return!n(t)&&(Array.isArray(t)?t.length>0:t instanceof File?t.size>0:(t=String(t).replace(/\s/g,"")).length>0)}checkRequiredArrayKeys(e,t,r){if(!this.checkArray(e,t))return!1;const s=Object.keys(t);for(const e of r)if(!s.includes(e))return!1;return!0}checkRequiredIf(e,t,r){return!this.isDependent(r)||this.checkRequired(e,t)}checkRequiredIfAccepted(e,t,r){return!this.checkAccepted(r[0],this.validator.getValue(r[0]))||this.checkRequired(e,t)}checkRequiredUnless(e,t,r){return!!this.isDependent(r)||this.checkRequired(e,t)}checkRequiredWith(e,t,r){return this.collectRequiredsThenTest(e,t,r,(e=>e.includes(!0)))}checkRequiredWithAll(e,t,r){return this.collectRequiredsThenTest(e,t,r,(e=>!e.includes(!1)))}checkRequiredWithout(e,t,r){return this.collectRequiredsThenTest(e,t,r,(e=>e.includes(!1)))}checkRequiredWithoutAll(e,t,r){return this.collectRequiredsThenTest(e,t,r,(e=>!e.includes(!0)))}checkFilled(e,t,r){return void 0===t||this.checkRequired(e,t)}checkPresent(e,t,r){return void 0!==t}checkMissing(e,t,r){return!this.validator.hasAttribute(e)}checkMissingIf(e,t,r){return!this.isDependent(r)||this.checkMissing(e)}checkMissingUnless(e,t,r){return!!this.isDependent(r)||this.checkMissing(e)}checkMissingWith(e,t,r){return this.collectMissingsThenTest(e,t,r,(e=>e.includes(!1)))}checkMissingWithAll(e,t,r){return this.collectMissingsThenTest(e,t,r,(e=>!e.includes(!0)))}checkProhibited(e,t,r){return!this.checkRequired(e,t)}checkProhibitedIf(e,t,r){return!this.isDependent(r)||!this.checkRequired(e,t)}checkProhibitedUnless(e,t,r){return!!this.isDependent(r)||!this.checkRequired(e,t)}checkProhibits(e,t,r){if(this.checkRequired(e,t))for(const e of r)if(this.checkRequired(e,this.validator.getValue(e)))return!1;return!0}checkSize(e,t,r){return this.validator.getSize(e,t)===parseFloat(r[0])}checkMin(e,t,r){return this.validator.getSize(e,t)>=parseFloat(r[0])}checkMax(e,t,r){return this.validator.getSize(e,t)<=parseFloat(r[0])}checkBetween(e,t,r){return this.checkMin(e,t,[r[0]])&&this.checkMax(e,t,[r[1]])}checkDigits(e,t,r){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:(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){let s=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if("string"!=typeof t&&!l(t))return!1;const i=r.join(",");let[a,c,h]=i.match(/^\/(.*)\/([gimu]*)$/)??[];if(n(a))throw new Error(`Invalid regular expression pattern: ${i}`);h.includes("u")&&(c=c.replace(/\\A/g,"^").replace(/\\z/gi,"$").replace(/\\([pP])([CLMNPSZ])/g,"\\$1{$2}").replace(/\\\x\{([0-9a-f]+)\}/g,"\\u{$1}"));const u=new RegExp(c,h).test(t);return s?!u:u}checkNotRegex(e,t,r){return this.checkRegex(e,t,r,!0)}checkLowercase(e,t,r){return t===String(t).toLocaleLowerCase()}checkUppercase(e,t,r){return t===String(t).toLocaleUpperCase()}checkStartsWith(e,t,r){t=String(t);for(const e of r)if(t.startsWith(e))return!0;return!1}checkDoesntStartWith(e,t,r){return!this.checkStartsWith(e,t,r)}checkEndsWith(e,t,r){t=String(t);for(const e of r)if(t.endsWith(e))return!0;return!1}checkDoesntEndWith(e,t,r){return!this.checkEndsWith(e,t,r)}checkSame(e,t,r){return t===this.validator.getValue(r[0])}checkDifferent(e,t,r){for(const e of r){const r=this.validator.getValue(e);if(void 0!==r&&t===r)return!1}return!0}checkConfirmed(e,t,r){return this.checkSame(e,t,[e+"_confirmation"])}checkGt(e,t,r){return this.compareValues(e,t,r,((e,t)=>e>t))}checkGte(e,t,r){return this.compareValues(e,t,r,((e,t)=>e>=t))}checkLt(e,t,r){return this.compareValues(e,t,r,((e,t)=>e<t))}checkLte(e,t,r){return this.compareValues(e,t,r,((e,t)=>e<=t))}checkAfter(e,t,r){return this.compareDates(e,t,r,((e,t)=>e>t))}checkAfterOrEqual(e,t,r){return this.compareDates(e,t,r,((e,t)=>e>=t))}checkBefore(e,t,r){return this.compareDates(e,t,r,((e,t)=>e<t))}checkBeforeOrEqual(e,t,r){return this.compareDates(e,t,r,((e,t)=>e<=t))}checkDateEquals(e,t,r){return this.compareDates(e,t,r,((e,t)=>e===t))}checkDateFormat(e,t,r){const s=r[0].split(""),i={Y:"(\\d{4})",y:"(\\d{2})",m:"(\\d{2})",n:"([1-9]\\d?)",d:"(\\d{2})",j:"([1-9]\\d?)",G:"([1-9]\\d?)",g:"([1-9]\\d?)",H:"(\\d{2})",h:"(\\d{2})",i:"(\\d{2})",s:"(\\d{2})",A:"(AM|PM)",a:"(am|pm)"};let a="^";for(const e of s)i.hasOwnProperty(e)?a+=i[e]:a+="\\"+e;return a+="$",new RegExp(a).test(t)}checkDistinct(e,t,i){const a=this.validator.getPrimaryAttribute(e);if(!a.includes("*"))return!0;const c=a.indexOf("*"),n=a.substring(0,c-1);let l;this.#e.hasOwnProperty(n)?l=this.#e[n]:(l=JSON.stringify(s(this.validator.getValue(n)??{})),this.#e[n]=l);const h=i.includes("ignore_case"),u=!h&&i.includes("strict"),o=r(String(t));let p=`"${r(a.substring(c)).replaceAll("\\*",'[^."]+')}":`,d=0;return p+=u?"string"==typeof t?`"${o}"`:`${o}`:`(${o}|"${o}")`,p+="[,}]+",d+=l.match(new RegExp(p,"g"+(h?"i":"")))?.length??0,1===d}checkInArray(e,t,r){const i=this.validator.getPrimaryAttribute(r[0]);if(!i.includes("*"))return!1;const a=this.validator.getValue(i.split(".*")[0])??{};return Object.values(s(a)).some((e=>e==t))}checkIn(e,t,r){if(!this.checkArray(e,t)||!this.validator.hasRule(e,"array"))return r.some((e=>e==t));for(const e of Object.values(t))if(!r.some((t=>t==e)))return!1;return!0}checkNotIn(e,t,r){return!this.checkIn(e,t,r)}checkMimetypes(e,t,r){return!!this.checkFile(e,t)&&r.includes(t.type)}checkMimes(e,t,r){return!!this.checkFile(e,t)&&r.includes(t.name.split(".").pop().toLowerCase())}checkExtensions(e,t,r){return this.checkMimes(e,t,r)}async checkImage(e,t,r){let s=this.checkMimes(e,t,["jpg","jpeg","png","gif","bmp","svg","webp"]);return s&&"undefined"!=typeof FileReader?(await new Promise(((e,r)=>{const s=new FileReader;s.onload=t=>e(t.target.result),s.onerror=r,s.readAsDataURL(t)})).then((async t=>{const r=new Image;r.src=t,await r.decode(),this.#t[e]=r})).catch((()=>{s=!1})),s):s}async checkDimensions(e,t,r){if(!this.checkImage(e,t)||!this.#t.hasOwnProperty(e))return!1;const s={};for(const e of r){const[t,r]=e.split("=",2);if("ratio"===t&&r.includes("/")){const[e,i]=r.split("/",2).map((e=>parseFloat(e,10)));s[t]=e/i}else s[t]=parseFloat(r,10)}const i=this.#t[e],a=i.naturalWidth,c=i.naturalHeight;return!(s.hasOwnProperty("width")&&s.width!==a||s.hasOwnProperty("height")&&s.height!==c||s.hasOwnProperty("min_width")&&s.min_width>a||s.hasOwnProperty("min_height")&&s.min_height>c||s.hasOwnProperty("max_width")&&s.max_width<a||s.hasOwnProperty("max_height")&&s.max_height<c)&&(!s.hasOwnProperty("ratio")||Math.abs(s.ratio-a/c)<=1/(Math.max(a,c)+1))}checkEmail(e,t,r){if(!/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(t)){return/^((?:[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]|[^\u0000-\u007F])+@(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?(?:\.(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?)+)*$/.test(t)}return!0}checkJson(e,t,r){try{JSON.parse(t)}catch(e){return!1}return!0}checkHexColor(e,t,r){return/^#(?:(?:[0-9a-f]{3}){1,2}|(?:[0-9a-f]{4}){1,2})$/i.test(t)}checkMacAddress(e,t,r){t=String(t);const s={"-":2,":":2,".":4};let i,a;for([i,a]of Object.entries(s))if(t.includes(i))break;const c=t.split(i);if(c.length!==12/a)return!1;for(const e of c)if(!new RegExp("^[0-9a-f]{"+a+"}$","i").test(e))return!1;return!0}checkIpv4(e,t,r){if(/[^\d.]/.test(t))return!1;const s=String(t).split(".");if(4!==s.length)return!1;for(const e of s)if(e<0||e>255)return!1;return!0}checkIpv6(e,t,r){if((t=String(t)).includes(":::")||t.split("::").length>2)return!1;const s=t.split(":");if(s.length<3||s.length>8)return!1;for(const e of s)if(""!==e&&!/^[0-9a-f]{1,4}$/i.test(e))return!1;return!0}checkIp(e,t,r){return this.checkIpv4(e,t,r)||this.checkIpv6(e,t,r)}checkTimezone(e,t,r){try{Intl.DateTimeFormat(void 0,{timeZone:t})}catch(e){if(String(e).toLowerCase().includes("invalid time zone"))return!1}return!0}checkUrl(e,t,r){try{new URL(t)}catch(e){return!1}return!0}checkUlid(e,t,r){return/[0-7][0-9A-HJKMNP-TV-Z]{25}/.test(t)}checkUuid(e,t,r){return/[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/.test(t)}}class p{#r={};keys(){return Object.keys(this.#r)}values(){return Object.values(this.#r)}entries(){return Object.entries(this.#r)}add(e,t){this.#r.hasOwnProperty(e)?this.#r[e].push(t):this.#r[e]=[t]}get(e){if(!e.includes("*"))return this.#r.hasOwnProperty(e)?this.#r[e]:{};const t=new RegExp("^"+e.replaceAll("*",".*?")+"$"),r={};for(const[e,s]of this.entries())t.test(e)&&(r[e]=s);return r}first(e){for(const t of Object.values(this.get(e)))return Array.isArray(t)?t[0]:t;return""}has(e){return""!==this.first(e)}messages(){return this.#r}all(){const e=[];return this.values().forEach((t=>e.push(...t))),e}count(){let e=0;return this.values().forEach((t=>e+=t.length)),e}isEmpty(){return 0===this.keys().length}isNotEmpty(){return!this.isEmpty()}}class d{static#s;static#i={};static locale(e){this.#s=e}static setMessages(e,t){this.#i[e]=s(t)}static get(e){if(this.#i[this.#s]&&this.#i[this.#s][e])return this.#i[this.#s][e]}static has(e){return void 0!==this.get(e)}static set(e,t){h(t)?Object.assign(this.#i[this.#s],s(t,e)):"string"==typeof t&&(this.#i[this.#s][e]=t)}}class g{validator;constructor(e){this.validator=e}replace(e,t){return Object.entries(t).forEach((t=>{let[r,s]=t;return e=e.replaceAll(":"+r,s)})),e}replaceDecimal(e,t,r,s){return this.replace(e,{decimal:s.join("-")})}replaceMultipleOf(e,t,r,s){return this.replace(e,{value:s[0]})}replaceAcceptedIf(e,t,r,s){return this.replace(e,{other:this.validator.getDisplayableAttribute(s[0]),value:this.validator.getDisplayableValue(s[0],this.validator.getValue(s[0]))})}replaceDeclinedIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredArrayKeys(e,t,r,s){return this.replace(e,{values:s.map((e=>this.validator.getDisplayableValue(t,e))).join(", ")})}replaceRequiredIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredIfAccepted(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredUnless(e,t,r,s){return this.replace(e,{other:this.validator.getDisplayableAttribute(s[0]),values:s.slice(1).map((e=>this.validator.getDisplayableValue(s[0],e))).join(", ")})}replaceRequiredWith(e,t,r,s){return this.replace(e,{values:s.map((e=>this.validator.getDisplayableAttribute(e))).join(" / ")})}replaceRequiredWithAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceRequiredWithout(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceRequiredWithoutAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceMissingIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceMissingUnless(e,t,r,s){return this.replace(this.replaceRequiredUnless(e,t,r,s),{value:this.validator.getDisplayableValue(s[0],s[1])})}replaceMissingWith(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceMissingWithAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceProhibitedIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceProhibitedUnless(e,t,r,s){return this.replaceRequiredUnless(e,t,r,s)}replaceProhibits(e,t,r,s){return this.replace(e,{other:s.map((e=>this.validator.getDisplayableAttribute(e))).join(" / ")})}replaceSize(e,t,r,s){return this.replace(e,{size:s[0]})}replaceMin(e,t,r,s){return this.replace(e,{min:s[0]})}replaceMax(e,t,r,s){return this.replace(e,{max:s[0]})}replaceBetween(e,t,r,s){return this.replace(e,{min:s[0],max:s[1]})}replaceDigits(e,t,r,s){return this.replace(e,{digits:s[0]})}replaceMinDigits(e,t,r,s){return this.replaceMin(e,t,r,s)}replaceMaxDigits(e,t,r,s){return this.replaceMax(e,t,r,s)}replaceDigitsBetween(e,t,r,s){return this.replaceBetween(e,t,r,s)}replaceStartsWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceDoesntStartWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceEndsWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceDoesntEndWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceSame(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceDifferent(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceGt(e,t,r,s){const i=this.validator.getValue(s[0]);return this.replace(e,{value:i?this.validator.getSize(s[0],i):this.validator.getDisplayableAttribute(s[0])})}replaceGte(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceLt(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceLte(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceAfter(e,t,r,s){const i=s[0];return this.replace(e,{date:this.validator.hasAttribute(i)?this.validator.getDisplayableAttribute(i):i})}replaceAfterOrEqual(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceBefore(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceBeforeOrEqual(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceDateEquals(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceDateFormat(e,t,r,s){return this.replace(e,{format:s[0]})}replaceInArray(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceIn(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceNotIn(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceMimetypes(e,t,r,s){return this.replace(e,{values:s.join(", ")})}replaceMimes(e,t,r,s){return this.replaceMimetypes(e,t,r,s)}replaceExtensions(e,t,r,s){return this.replaceMimetypes(e,t,r,s)}}class f{static#a={};static#c={};static#n=["active_url","bail","can","current_password","enum","exclude","exclude_if","exclude_unless","exclude_with","exclude_without","exists","nullable","sometimes","unique"];static#l=["accepted","accepted_if","declined","declined_if","filled","missing","missing_if","missing_unless","missing_with","missing_with_all","present","required","required_if","required_if_accepted","required_unless","required_with","required_with_all","required_without","required_without_all"];#r;#h;#u;#o;#p;#d;#g;#f;#m={};#y=!1;#k=!1;fileRules=["file","image","mimetypes","mimes"];numericRules=["decimal","numeric","integer"];sizeRules=["size","between","min","max","gt","lt","gte","lte"];static setLocale(e){d.locale(e)}static setMessages(e,t){d.setMessages(e,t)}static addChecker(e,t,r){f.#a[e]=t,r&&d.set(e,r)}static addImplicitChecker(e,t,r){f.addChecker(e,t,r),f.#l.push(e)}static addReplacer(e,t){f.#c[e]=t}static addDummyRule(e){f.#n.push(e)}constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};this.setProperties(e,r,s,i,a),this.#d=new o(this),this.#g=new g(this);for(const[e,r]of Object.entries(f.#a))this.#d[t("check_"+e)]=r;for(const[e,r]of Object.entries(f.#c))this.#g[t("replace_"+e)]=r;this.#f=new p}setProperties(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};return this.#r=e,this.#h=this.parseRules(t),this.#u=r,this.#o=i,this.#p=s(a),this}setData(e){return this.#r=e,this}setRules(e){return this.#h=this.parseRules(e),this}setCustomMessages(e){return this.#u=e,this}setCustomAttributes(e){return this.#o=e,this}setCustomValues(e){return this.#p=s(e),this}addImplicitAttribute(e,t){return this.#m[e]=t,this}stopOnFirstFailure(){let e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this.#y=e,this}alwaysBail(){let e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this.#k=e,this}parseRules(e){const t={};for(const[r,s]of Object.entries(e)){const e=r.includes("*")?this.parseWildcardAttribute(r):[r];for(const r of e){const e={};for(const t of this.parseAttributeRules(s)){const[r,s]=this.parseAttributeRule(t);e[r]=s}t[r]=e}}return t}parseWildcardAttribute(e){const t=[],r=e.indexOf("*"),s=e.substring(0,r-1),i=e.substring(r+2),a=this.getValue(s);return Array.isArray(a)||h(a)?(Object.entries(a).forEach((r=>{let[a,c]=r;const n=`${s}.${a}.${i}`.replace(/\.$/,""),l=n.includes("*")?this.parseWildcardAttribute(n):[n];t.push(...l),l.forEach((t=>this.#m[t]=e))})),t):[e]}parseAttributeRules(e){return Array.isArray(e)?e:String(e).split("|")}parseAttributeRule(e){if(Array.isArray(e))return[e.shift()??"",e];const t=e.indexOf(":");return-1===t?[e,[]]:[e.substring(0,t),i(e.substring(t+1))]}async validate(){this.#d.clearCaches(),this.#f=new p;for(const[e,r]of Object.entries(this.#h)){let s=this.getValue(e);if(r.hasOwnProperty("sometimes")&&void 0===s)continue;const i=this.#k||r.hasOwnProperty("bail"),a=r.hasOwnProperty("nullable");let c=!1;for(const[l,h]of Object.entries(r)){if(""===l)continue;if(!f.#l.includes(l)&&(void 0===s||"string"==typeof s&&""===s.trim()||a&&null===s))continue;let r,u,o;const p=t("check_"+l);if("function"==typeof this.#d[p])r=await this.#d[p](e,s,h);else{if(!f.#n.includes(l))throw new Error(`Invalid validation rule: ${l}`);r=!0}if("boolean"==typeof r?u=r:({status:u,message:o}=r),!u&&(c=!0,o=n(o)?this.getMessage(e,l):o,o=this.makeReplacements(o,e,l,h),this.#f.add(e,o),i||f.#l.includes(l)))break}if(this.#y&&c)break}if(this.#f.isNotEmpty())throw this.#f}async passes(){try{await this.validate()}catch(e){if(e instanceof Error)throw e;return!1}return!0}async fails(){return!await this.passes()}getMessage(e,t){const r=this.getValue(e);let s;e=this.getPrimaryAttribute(e);for(const r of[`${e}.${t}`,t])if(this.#u.hasOwnProperty(r)){s=this.#u[r];break}if(!s){let i=t;this.sizeRules.includes(i)&&(Array.isArray(r)||h(r)||this.hasRule(e,"array")?i+=".array":r instanceof File||this.hasRule(e,this.fileRules)?i+=".file":"number"==typeof r||this.hasRule(e,this.numericRules)?i+=".numeric":i+=".string"),s=d.get(i)}return s??`validation.${t}`}makeReplacements(e,r,s,i){const a=this.getDisplayableAttribute(r),c=this.getValue(r),n={attribute:a,ATTRIBUTE:a.toLocaleUpperCase(),Attribute:a.charAt(0).toLocaleUpperCase()+a.substring(1),input:this.getDisplayableValue(r,c)};for(const[t,r]of Object.entries(n))e=e.replaceAll(":"+t,r);const l=r.match(/\.(\d+)\.?/),h=null===l?-1:parseInt(l[1],10);-1!==h&&(e=e.replaceAll(":index",h).replaceAll(":position",h+1));const u=t("replace_"+s);return"function"==typeof this.#g[u]&&(e=this.#g[u](e,r,s,i)),e}getDisplayableAttribute(e){const t=this.getPrimaryAttribute(e);for(const r of[e,t]){if(this.#o.hasOwnProperty(r))return this.#o[r];if(d.has(`attributes.${r}`))return d.get(`attributes.${r}`)}return this.#m.hasOwnProperty(e)?e:(r=e,r.replace(/(.)(?=[A-Z])/g,(e=>e+"_")).toLowerCase()).replaceAll("_"," ");var r}getDisplayableValue(e,t){const r=`${e=this.getPrimaryAttribute(e)}.${t}`;return n(t)?"empty":"boolean"==typeof t||this.hasRule(e,"boolean")?Number(t)?"true":"false":this.#p.hasOwnProperty(r)?this.#p[r]:d.has(`values.${r}`)?d.get(`values.${r}`):t}getSize(e,t){return n(t)?0:l(t)&&this.hasRule(e,this.numericRules)?parseFloat("string"==typeof t?t.trim():t,10):t instanceof File?t.size/1024:h(t)?Object.keys(t).length:t.hasOwnProperty("length")?t.length:t}getRule(e){return e=this.getPrimaryAttribute(e),this.#h[e]??{}}hasRule(e,t){if(e=this.getPrimaryAttribute(e),t="string"==typeof t?[t]:t,!this.#h.hasOwnProperty(e))return!1;for(const r of t)if(this.#h[e].hasOwnProperty(r))return!0;return!1}getPrimaryAttribute(e){return this.#m.hasOwnProperty(e)?this.#m[e]:e}hasAttribute(e){return void 0!==this.getValue(e)}getValue(e){return function(e,t,r){const s=t.split(".");let i=e;for(const e of s){if(!i.hasOwnProperty(e))return r;i=i[e]}return i}(this.#r,e)}errors(){return this.#f}}return e.Checkers=o,e.ErrorBag=p,e.Lang=d,e.Replacers=g,e.Validator=f,e}({});
|
|
6
|
+
var quival=function(e){"use strict";function t(e){return e.replace(/[-_]/g," ").replace(/\s+/," ").trim().replace(/(\s\w)/g,(e=>e[1].toUpperCase()))}function r(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function s(e,t=""){return Object.keys(e).reduce(((r,i)=>{const a=t?`${t}.${i}`:i;return"object"==typeof e[i]&&null!==e[i]?Object.assign(r,s(e[i],a)):r[a]=e[i],r}),{})}function i(e){const t=[];let r="",s=!1;for(let i=0;i<e.length;i++){const a=e[i];'"'===a?s&&'"'===e[i+1]?(r+='"',i++):(s=!s,s&&(r=r.trim())):","!==a||s?r+=a:(t.push(r),r="")}return t.push(r),t}function a(e){if(n(e)||"string"!=typeof e)return new Date("");if(e instanceof Date)return e;let t,r,s,i,a,c,u,h;const l=e=>e&&/^\d*$/.test(e)?parseInt(e):e;if(null!==(t=e.match(/^(\d{1,2})[.\/-](\d{1,2})[.\/-](\d{2,4})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)))[,i,s,r,,a=0,c=0,,u=0,h="am"]=t.map(l);else if(null!==(t=e.match(/^(\d{2,4})[.\/-](\d{1,2})[.\/-](\d{1,2})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i))||null!==(t=e.match(/^(\d{4})(\d{2})(\d{2})\s?((\d{2})(\d{2})((\d{2}))?\s?(am|pm)?)?/i)))[,r,s,i,,a=0,c=0,,u=0,h="am"]=t.map(l);else if(t=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{4})[.\/-](\d{2})[.\/-](\d{2})/i))[,a,c,,u,h="am",r,s,i]=t.map(l);else if(t=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{2})[.\/-](\d{2})[.\/-](\d{4})/i))[,a,c,,u,h="am",i,s,r]=t.map(l);else{if(!(t=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?/i)))return new Date(e);{const e=new Date;r=e.getFullYear(),s=e.getMonth()+1,i=e.getDate(),[,a=0,c=0,,u=0,h="am"]=t.map(l)}}return r>=10&&r<100&&(r+=2e3),"pm"===h.toLowerCase()&&a<12&&(a+=12),new Date(`${r}-${s}-${i} ${a}:${c}:${u}`)}function c(e,t){if(n(e))return new Date("");t=t.split("");const r={Y:"(\\d{4})",y:"(\\d{2})",m:"(\\d{2})",n:"([1-9]\\d?)",d:"(\\d{2})",j:"([1-9]\\d?)",G:"([1-9]\\d?)",g:"([1-9]\\d?)",H:"(\\d{2})",h:"(\\d{2})",i:"(\\d{2})",s:"(\\d{2})",A:"(AM|PM)",a:"(am|pm)"};let s="^",i={years:-1,months:-1,days:-1,hours:-1,minutes:-1,seconds:-1,meridiem:-1},a=1;for(const e of t)r.hasOwnProperty(e)?(s+=r[e],-1!==["Y","y"].indexOf(e)?i.years=a++:-1!==["m","n"].indexOf(e)?i.months=a++:-1!==["d","j"].indexOf(e)?i.days=a++:-1!==["G","g","H","h"].indexOf(e)?i.hours=a++:"i"===e?i.minutes=a++:"s"===e?i.seconds=a++:-1!==["A","a"].indexOf(e)&&(i.meridiem=a++)):s+="\\"+e;s+="$";let c=e.match(new RegExp(s));if(null===c)return new Date("");c=c.map((e=>e&&/^\d*$/.test(e)?parseInt(e):e));const u=new Date;let h=c[i.years],l=c[i.months],o=c[i.days],p=c[i.hours]??0,d=c[i.minutes]??0,f=c[i.seconds]??0,g=c[i.meridiem]??"am";return h||l||o?!h||l||o?h||!l||o?h||l||!o||(h=u.getFullYear(),l=u.getMonth()+1):(h=u.getFullYear(),o=1):(l=1,o=1):(h=u.getFullYear(),l=u.getMonth()+1,o=u.getDate()),h>=10&&h<100&&(h+=2e3),"pm"===g.toLowerCase()&&p<12&&(p+=12),new Date(`${h}-${l}-${o} ${p}:${d}:${f}`)}function n(e){return""===e||null==e}function u(e){const t=Number(e);return null!==e&&"boolean"!=typeof e&&"number"==typeof t&&!isNaN(t)}function h(e){return"[object Object]"===Object.prototype.toString.call(e)}function l(e){return e instanceof Date&&"Invalid Date"!==e.toDateString()}class o{#e;#t;constructor(e){this.#e={},this.#t={},this.validator=e}clearCaches(){this.#e={},this.#t={}}isDependent(e){const t=this.validator.getValue(e[0]);return e.slice(1).some((e=>e==t))}collectRequiredsThenTest(e,t,r,s){let i=[];for(const e of r)i.push(this.checkRequired(e,this.validator.getValue(e)));return!s(i)||this.checkRequired(e,t)}collectMissingsThenTest(e,t,r,s){let i=[];for(const e of r)i.push(this.checkMissing(e));return!s(i)||this.checkMissing(e)}testStringUsingRegex(e,t,r,s,i=!1){return("string"==typeof t||"number"==typeof t)&&(t=String(t),i||this.validator.hasRule(e,"ascii")?r.test(t):s.test(t))}compareValues(e,t,r,s){if(n(t))return!1;const i=r[0]??"";let a=this.validator.getValue(i);return a=void 0===a?u(i)?parseFloat(i,10):null:this.validator.getSize(i,a),!n(a)&&s(this.validator.getSize(e,t),a)}compareDates(e,t,r,s){const i=this.validator.getRule(e);if(!l(t=i.hasOwnProperty("date_format")?c(t,i.date_format[0]):a(t)))return!1;const n=r[0]??"";let u=this.validator.getValue(n);if(void 0===u)u=a(n);else{const e=this.validator.getRule(n);u=e.hasOwnProperty("date_format")?c(u,e.date_format[0]):a(u)}return!!l(u)&&s(t.getTime(),u.getTime())}checkArray(e,t,r){if(!Array.isArray(t)&&!h(t))return!1;if(r&&r.length>0)for(const e of Object.keys(t))if(!r.includes(e))return!1;return!0}checkList(e,t,r){return Array.isArray(t)}checkBoolean(e,t,r){return[!0,!1,0,1,"0","1"].includes(t)}checkDate(e,t,r){return l(a(t))}checkFile(e,t,r){return t instanceof File}checkInteger(e,t,r){return String(parseInt(t,10))===String(t)}checkNumeric(e,t,r){return u(t)}checkString(e,t,r){return"string"==typeof t}checkDecimal(e,t,r){if(!this.checkNumeric(e,t))return!1;const s=(String(t).split(".")[1]??"").length;return 1===r.length?s==r[0]:s>=r[0]&&s<=r[1]}checkMultipleOf(e,t,r){if(!u(t)||!u(r[0]))return!1;const s=parseInt(t,10),i=parseInt(r[0],10);return(0!==s||0!==i)&&(0===s||0!==i&&s%i==0)}checkAccepted(e,t,r){return["yes","on","1",1,!0,"true"].includes(t)}checkAcceptedIf(e,t,r){return!this.isDependent(r)||this.checkAccepted(e,t,r)}checkDeclined(e,t,r){return["no","off","0",0,!1,"false"].includes(t)}checkDeclinedIf(e,t,r){return!this.isDependent(r)||this.checkDeclined(e,t,r)}checkRequired(e,t,r){return!n(t)&&(Array.isArray(t)?t.length>0:t instanceof File?t.size>0:(t=String(t).replace(/\s/g,"")).length>0)}checkRequiredArrayKeys(e,t,r){if(!this.checkArray(e,t))return!1;const s=Object.keys(t);for(const e of r)if(!s.includes(e))return!1;return!0}checkRequiredIf(e,t,r){return!this.isDependent(r)||this.checkRequired(e,t)}checkRequiredIfAccepted(e,t,r){return!this.checkAccepted(r[0],this.validator.getValue(r[0]))||this.checkRequired(e,t)}checkRequiredUnless(e,t,r){return!!this.isDependent(r)||this.checkRequired(e,t)}checkRequiredWith(e,t,r){return this.collectRequiredsThenTest(e,t,r,(e=>e.includes(!0)))}checkRequiredWithAll(e,t,r){return this.collectRequiredsThenTest(e,t,r,(e=>!e.includes(!1)))}checkRequiredWithout(e,t,r){return this.collectRequiredsThenTest(e,t,r,(e=>e.includes(!1)))}checkRequiredWithoutAll(e,t,r){return this.collectRequiredsThenTest(e,t,r,(e=>!e.includes(!0)))}checkFilled(e,t,r){return void 0===t||this.checkRequired(e,t)}checkPresent(e,t,r){return void 0!==t}checkMissing(e,t,r){return!this.validator.hasAttribute(e)}checkMissingIf(e,t,r){return!this.isDependent(r)||this.checkMissing(e)}checkMissingUnless(e,t,r){return!!this.isDependent(r)||this.checkMissing(e)}checkMissingWith(e,t,r){return this.collectMissingsThenTest(e,t,r,(e=>e.includes(!1)))}checkMissingWithAll(e,t,r){return this.collectMissingsThenTest(e,t,r,(e=>!e.includes(!0)))}checkProhibited(e,t,r){return!this.checkRequired(e,t)}checkProhibitedIf(e,t,r){return!this.isDependent(r)||!this.checkRequired(e,t)}checkProhibitedUnless(e,t,r){return!!this.isDependent(r)||!this.checkRequired(e,t)}checkProhibits(e,t,r){if(this.checkRequired(e,t))for(const e of r)if(this.checkRequired(e,this.validator.getValue(e)))return!1;return!0}checkSize(e,t,r){return this.validator.getSize(e,t)===parseFloat(r[0])}checkMin(e,t,r){return this.validator.getSize(e,t)>=parseFloat(r[0])}checkMax(e,t,r){return this.validator.getSize(e,t)<=parseFloat(r[0])}checkBetween(e,t,r){return this.checkMin(e,t,[r[0]])&&this.checkMax(e,t,[r[1]])}checkDigits(e,t,r,s=((e,t)=>e===t)){return!!function(e){return-1===String(e).search(/[^0-9]/)}(t=String(t??""))&&s(t.length,parseInt(r[0],10),parseInt(r[1]??0,10))}checkMinDigits(e,t,r){return this.checkDigits(e,t,r,((e,t)=>e>=t))}checkMaxDigits(e,t,r){return this.checkDigits(e,t,r,((e,t)=>e<=t))}checkDigitsBetween(e,t,r){return this.checkDigits(e,t,r,((e,t,r)=>e>=t&&e<=r))}checkAlpha(e,t,r){return this.testStringUsingRegex(e,t,/^[a-z]+$/i,/^[\p{L}\p{M}]+$/u,r.includes("ascii"))}checkAlphaDash(e,t,r){return this.testStringUsingRegex(e,t,/^[a-z0-9_-]+$/i,/^[\p{L}\p{M}\p{N}_-]+$/u,r.includes("ascii"))}checkAlphaNum(e,t,r){return this.testStringUsingRegex(e,t,/^[a-z0-9]+$/i,/^[\p{L}\p{M}\p{N}]+$/u,r.includes("ascii"))}checkAscii(e,t,r){return!/[^\x09\x10\x13\x0A\x0D\x20-\x7E]/.test(t)}checkRegex(e,t,r,s=!1){if("string"!=typeof t&&!u(t))return!1;const i=r.join(",");let[a,c,h]=i.match(/^\/(.*)\/([gimu]*)$/)??[];if(n(a))throw new Error(`Invalid regular expression pattern: ${i}`);h.includes("u")&&(c=c.replace(/\\A/g,"^").replace(/\\z/gi,"$").replace(/\\([pP])([CLMNPSZ])/g,"\\$1{$2}").replace(/\\\x\{([0-9a-f]+)\}/g,"\\u{$1}"));const l=new RegExp(c,h).test(t);return s?!l:l}checkNotRegex(e,t,r){return this.checkRegex(e,t,r,!0)}checkLowercase(e,t,r){return t===String(t).toLocaleLowerCase()}checkUppercase(e,t,r){return t===String(t).toLocaleUpperCase()}checkStartsWith(e,t,r){t=String(t);for(const e of r)if(t.startsWith(e))return!0;return!1}checkDoesntStartWith(e,t,r){return!this.checkStartsWith(e,t,r)}checkEndsWith(e,t,r){t=String(t);for(const e of r)if(t.endsWith(e))return!0;return!1}checkDoesntEndWith(e,t,r){return!this.checkEndsWith(e,t,r)}checkSame(e,t,r){return t===this.validator.getValue(r[0])}checkDifferent(e,t,r){for(const e of r){const r=this.validator.getValue(e);if(void 0!==r&&t===r)return!1}return!0}checkConfirmed(e,t,r){return this.checkSame(e,t,[e+"_confirmation"])}checkGt(e,t,r){return this.compareValues(e,t,r,((e,t)=>e>t))}checkGte(e,t,r){return this.compareValues(e,t,r,((e,t)=>e>=t))}checkLt(e,t,r){return this.compareValues(e,t,r,((e,t)=>e<t))}checkLte(e,t,r){return this.compareValues(e,t,r,((e,t)=>e<=t))}checkAfter(e,t,r){return this.compareDates(e,t,r,((e,t)=>e>t))}checkAfterOrEqual(e,t,r){return this.compareDates(e,t,r,((e,t)=>e>=t))}checkBefore(e,t,r){return this.compareDates(e,t,r,((e,t)=>e<t))}checkBeforeOrEqual(e,t,r){return this.compareDates(e,t,r,((e,t)=>e<=t))}checkDateEquals(e,t,r){return this.compareDates(e,t,r,((e,t)=>e===t))}checkDateFormat(e,t,r){const s=r[0].split(""),i={Y:"(\\d{4})",y:"(\\d{2})",m:"(\\d{2})",n:"([1-9]\\d?)",d:"(\\d{2})",j:"([1-9]\\d?)",G:"([1-9]\\d?)",g:"([1-9]\\d?)",H:"(\\d{2})",h:"(\\d{2})",i:"(\\d{2})",s:"(\\d{2})",A:"(AM|PM)",a:"(am|pm)"};let a="^";for(const e of s)i.hasOwnProperty(e)?a+=i[e]:a+="\\"+e;return a+="$",new RegExp(a).test(t)}checkDistinct(e,t,i){const a=this.validator.getPrimaryAttribute(e);if(!a.includes("*"))return!0;const c=a.indexOf("*"),n=a.substring(0,c-1);let u;this.#e.hasOwnProperty(n)?u=this.#e[n]:(u=JSON.stringify(s(this.validator.getValue(n)??{})),this.#e[n]=u);const h=i.includes("ignore_case"),l=!h&&i.includes("strict"),o=r(String(t));let p=`"${r(a.substring(c)).replaceAll("\\*",'[^."]+')}":`,d=0;return p+=l?"string"==typeof t?`"${o}"`:`${o}`:`(${o}|"${o}")`,p+="[,}]+",d+=u.match(new RegExp(p,"g"+(h?"i":"")))?.length??0,1===d}checkInArray(e,t,r){const i=this.validator.getPrimaryAttribute(r[0]);if(!i.includes("*"))return!1;const a=this.validator.getValue(i.split(".*")[0])??{};return Object.values(s(a)).some((e=>e==t))}checkIn(e,t,r){if(!this.checkArray(e,t)||!this.validator.hasRule(e,"array"))return r.some((e=>e==t));for(const e of Object.values(t))if(!r.some((t=>t==e)))return!1;return!0}checkNotIn(e,t,r){return!this.checkIn(e,t,r)}checkMimetypes(e,t,r){return!!this.checkFile(e,t)&&r.includes(t.type)}checkMimes(e,t,r){return!!this.checkFile(e,t)&&r.includes(t.name.split(".").pop().toLowerCase())}checkExtensions(e,t,r){return this.checkMimes(e,t,r)}async checkImage(e,t,r){let s=this.checkMimes(e,t,["jpg","jpeg","png","gif","bmp","svg","webp"]);return s&&"undefined"!=typeof FileReader?(await new Promise(((e,r)=>{const s=new FileReader;s.onload=t=>e(t.target.result),s.onerror=r,s.readAsDataURL(t)})).then((async t=>{const r=new Image;r.src=t,await r.decode(),this.#t[e]=r})).catch((()=>{s=!1})),s):s}async checkDimensions(e,t,r){if(!this.checkImage(e,t)||!this.#t.hasOwnProperty(e))return!1;const s={};for(const e of r){const[t,r]=e.split("=",2);if("ratio"===t&&r.includes("/")){const[e,i]=r.split("/",2).map((e=>parseFloat(e,10)));s[t]=e/i}else s[t]=parseFloat(r,10)}const i=this.#t[e],a=i.naturalWidth,c=i.naturalHeight;return!(s.hasOwnProperty("width")&&s.width!==a||s.hasOwnProperty("height")&&s.height!==c||s.hasOwnProperty("min_width")&&s.min_width>a||s.hasOwnProperty("min_height")&&s.min_height>c||s.hasOwnProperty("max_width")&&s.max_width<a||s.hasOwnProperty("max_height")&&s.max_height<c)&&(!s.hasOwnProperty("ratio")||Math.abs(s.ratio-a/c)<=1/(Math.max(a,c)+1))}checkEmail(e,t,r){if(!/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(t)){return/^((?:[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]|[^\u0000-\u007F])+@(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?(?:\.(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?)+)*$/.test(t)}return!0}checkJson(e,t,r){try{JSON.parse(t)}catch(e){return!1}return!0}checkHexColor(e,t,r){return/^#(?:(?:[0-9a-f]{3}){1,2}|(?:[0-9a-f]{4}){1,2})$/i.test(t)}checkMacAddress(e,t,r){t=String(t);const s={"-":2,":":2,".":4};let i,a;for([i,a]of Object.entries(s))if(t.includes(i))break;const c=t.split(i);if(c.length!==12/a)return!1;for(const e of c)if(!new RegExp("^[0-9a-f]{"+a+"}$","i").test(e))return!1;return!0}checkIpv4(e,t,r){if(/[^\d.]/.test(t))return!1;const s=String(t).split(".");if(4!==s.length)return!1;for(const e of s)if(e<0||e>255)return!1;return!0}checkIpv6(e,t,r){if((t=String(t)).includes(":::")||t.split("::").length>2)return!1;const s=t.split(":");if(s.length<3||s.length>8)return!1;for(const e of s)if(""!==e&&!/^[0-9a-f]{1,4}$/i.test(e))return!1;return!0}checkIp(e,t,r){return this.checkIpv4(e,t,r)||this.checkIpv6(e,t,r)}checkTimezone(e,t,r){try{Intl.DateTimeFormat(void 0,{timeZone:t})}catch(e){if(String(e).toLowerCase().includes("invalid time zone"))return!1}return!0}checkUrl(e,t,r){try{new URL(t)}catch(e){return!1}return!0}checkUlid(e,t,r){return/[0-7][0-9A-HJKMNP-TV-Z]{25}/.test(t)}checkUuid(e,t,r){return/[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/.test(t)}}class p{#r;keys(){return Object.keys(this.#r)}values(){return Object.values(this.#r)}entries(){return Object.entries(this.#r)}add(e,t){this.#r.hasOwnProperty(e)?this.#r[e].push(t):this.#r[e]=[t]}get(e){if(!e.includes("*"))return this.#r.hasOwnProperty(e)?this.#r[e]:{};const t=new RegExp("^"+e.replaceAll("*",".*?")+"$"),r={};for(const[e,s]of this.entries())t.test(e)&&(r[e]=s);return r}first(e){for(const t of Object.values(this.get(e)))return Array.isArray(t)?t[0]:t;return""}has(e){return""!==this.first(e)}messages(){return this.#r}all(){const e=[];return this.values().forEach((t=>e.push(...t))),e}count(){let e=0;return this.values().forEach((t=>e+=t.length)),e}isEmpty(){return 0===this.keys().length}isNotEmpty(){return!this.isEmpty()}constructor(){this.#r={}}}class d{static#s;static#i={};static locale(e){this.#s=e}static setMessages(e,t){this.#i[e]=s(t)}static get(e){if(this.#i[this.#s]&&this.#i[this.#s][e])return this.#i[this.#s][e]}static has(e){return void 0!==this.get(e)}static set(e,t){h(t)?Object.assign(this.#i[this.#s],s(t,e)):"string"==typeof t&&(this.#i[this.#s][e]=t)}}class f{constructor(e){this.validator=e}replace(e,t){return Object.entries(t).forEach((([t,r])=>e=e.replaceAll(":"+t,r))),e}replaceDecimal(e,t,r,s){return this.replace(e,{decimal:s.join("-")})}replaceMultipleOf(e,t,r,s){return this.replace(e,{value:s[0]})}replaceAcceptedIf(e,t,r,s){return this.replace(e,{other:this.validator.getDisplayableAttribute(s[0]),value:this.validator.getDisplayableValue(s[0],this.validator.getValue(s[0]))})}replaceDeclinedIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredArrayKeys(e,t,r,s){return this.replace(e,{values:s.map((e=>this.validator.getDisplayableValue(t,e))).join(", ")})}replaceRequiredIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredIfAccepted(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredUnless(e,t,r,s){return this.replace(e,{other:this.validator.getDisplayableAttribute(s[0]),values:s.slice(1).map((e=>this.validator.getDisplayableValue(s[0],e))).join(", ")})}replaceRequiredWith(e,t,r,s){return this.replace(e,{values:s.map((e=>this.validator.getDisplayableAttribute(e))).join(" / ")})}replaceRequiredWithAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceRequiredWithout(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceRequiredWithoutAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceMissingIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceMissingUnless(e,t,r,s){return this.replace(this.replaceRequiredUnless(e,t,r,s),{value:this.validator.getDisplayableValue(s[0],s[1])})}replaceMissingWith(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceMissingWithAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceProhibitedIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceProhibitedUnless(e,t,r,s){return this.replaceRequiredUnless(e,t,r,s)}replaceProhibits(e,t,r,s){return this.replace(e,{other:s.map((e=>this.validator.getDisplayableAttribute(e))).join(" / ")})}replaceSize(e,t,r,s){return this.replace(e,{size:s[0]})}replaceMin(e,t,r,s){return this.replace(e,{min:s[0]})}replaceMax(e,t,r,s){return this.replace(e,{max:s[0]})}replaceBetween(e,t,r,s){return this.replace(e,{min:s[0],max:s[1]})}replaceDigits(e,t,r,s){return this.replace(e,{digits:s[0]})}replaceMinDigits(e,t,r,s){return this.replaceMin(e,t,r,s)}replaceMaxDigits(e,t,r,s){return this.replaceMax(e,t,r,s)}replaceDigitsBetween(e,t,r,s){return this.replaceBetween(e,t,r,s)}replaceStartsWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceDoesntStartWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceEndsWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceDoesntEndWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceSame(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceDifferent(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceGt(e,t,r,s){const i=this.validator.getValue(s[0]);return this.replace(e,{value:i?this.validator.getSize(s[0],i):this.validator.getDisplayableAttribute(s[0])})}replaceGte(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceLt(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceLte(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceAfter(e,t,r,s){const i=s[0];return this.replace(e,{date:this.validator.hasAttribute(i)?this.validator.getDisplayableAttribute(i):i})}replaceAfterOrEqual(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceBefore(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceBeforeOrEqual(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceDateEquals(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceDateFormat(e,t,r,s){return this.replace(e,{format:s[0]})}replaceInArray(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceIn(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceNotIn(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceMimetypes(e,t,r,s){return this.replace(e,{values:s.join(", ")})}replaceMimes(e,t,r,s){return this.replaceMimetypes(e,t,r,s)}replaceExtensions(e,t,r,s){return this.replaceMimetypes(e,t,r,s)}}class g{static#a={};static#c={};static#n=["active_url","bail","can","current_password","enum","exclude","exclude_if","exclude_unless","exclude_with","exclude_without","exists","nullable","sometimes","unique"];static#u=["accepted","accepted_if","declined","declined_if","filled","missing","missing_if","missing_unless","missing_with","missing_with_all","present","required","required_if","required_if_accepted","required_unless","required_with","required_with_all","required_without","required_without_all"];#r;#h;#l;#o;#p;#d;#f;#g;#m;#y;#k;static setLocale(e){d.locale(e)}static setMessages(e,t){d.setMessages(e,t)}static addChecker(e,t,r){g.#a[e]=t,r&&d.set(e,r)}static addImplicitChecker(e,t,r){g.addChecker(e,t,r),g.#u.push(e)}static addReplacer(e,t){g.#c[e]=t}static addDummyRule(e){g.#n.push(e)}constructor(e={},r={},s={},i={},a={}){this.#m={},this.#y=!1,this.#k=!1,this.fileRules=["file","image","mimetypes","mimes"],this.numericRules=["decimal","numeric","integer"],this.sizeRules=["size","between","min","max","gt","lt","gte","lte"],this.setProperties(e,r,s,i,a),this.#d=new o(this),this.#f=new f(this);for(const[e,r]of Object.entries(g.#a))this.#d[t("check_"+e)]=r;for(const[e,r]of Object.entries(g.#c))this.#f[t("replace_"+e)]=r;this.#g=new p}setProperties(e={},t={},r={},i={},a={}){return this.#r=e,this.#h=this.parseRules(t),this.#l=r,this.#o=i,this.#p=s(a),this}setData(e){return this.#r=e,this}setRules(e){return this.#h=this.parseRules(e),this}setCustomMessages(e){return this.#l=e,this}setCustomAttributes(e){return this.#o=e,this}setCustomValues(e){return this.#p=s(e),this}addImplicitAttribute(e,t){return this.#m[e]=t,this}stopOnFirstFailure(e=!0){return this.#y=e,this}alwaysBail(e=!0){return this.#k=e,this}parseRules(e){const t={};for(const[r,s]of Object.entries(e)){const e=r.includes("*")?this.parseWildcardAttribute(r):[r];for(const r of e){const e={};for(const t of this.parseAttributeRules(s)){const[r,s]=this.parseAttributeRule(t);e[r]=s}t[r]=e}}return t}parseWildcardAttribute(e){const t=[],r=e.indexOf("*"),s=e.substring(0,r-1),i=e.substring(r+2),a=this.getValue(s);return Array.isArray(a)||h(a)?(Object.entries(a).forEach((([r,a])=>{const c=`${s}.${r}.${i}`.replace(/\.$/,""),n=c.includes("*")?this.parseWildcardAttribute(c):[c];t.push(...n),n.forEach((t=>this.#m[t]=e))})),t):[e]}parseAttributeRules(e){return Array.isArray(e)?e:String(e).split("|")}parseAttributeRule(e){if(Array.isArray(e))return[e.shift()??"",e];const t=e.indexOf(":");return-1===t?[e,[]]:[e.substring(0,t),i(e.substring(t+1))]}async validate(){this.#d.clearCaches(),this.#g=new p;for(const[e,r]of Object.entries(this.#h)){let s=this.getValue(e);if(r.hasOwnProperty("sometimes")&&void 0===s)continue;const i=this.#k||r.hasOwnProperty("bail"),a=r.hasOwnProperty("nullable");let c=!1;for(const[u,h]of Object.entries(r)){if(""===u)continue;if(!g.#u.includes(u)&&(void 0===s||"string"==typeof s&&""===s.trim()||a&&null===s))continue;let r,l,o;const p=t("check_"+u);if("function"==typeof this.#d[p])r=await this.#d[p](e,s,h);else{if(!g.#n.includes(u))throw new Error(`Invalid validation rule: ${u}`);r=!0}if("boolean"==typeof r?l=r:({status:l,message:o}=r),!l&&(c=!0,o=n(o)?this.getMessage(e,u):o,o=this.makeReplacements(o,e,u,h),this.#g.add(e,o),i||g.#u.includes(u)))break}if(this.#y&&c)break}if(this.#g.isNotEmpty())throw this.#g}async passes(){try{await this.validate()}catch(e){if(e instanceof Error)throw e;return!1}return!0}async fails(){return!await this.passes()}getMessage(e,t){const r=this.getValue(e);let s;e=this.getPrimaryAttribute(e);for(const r of[`${e}.${t}`,t])if(this.#l.hasOwnProperty(r)){s=this.#l[r];break}if(!s){let i=t;this.sizeRules.includes(i)&&(Array.isArray(r)||h(r)||this.hasRule(e,"array")?i+=".array":r instanceof File||this.hasRule(e,this.fileRules)?i+=".file":"number"==typeof r||this.hasRule(e,this.numericRules)?i+=".numeric":i+=".string"),s=d.get(i)}return s??`validation.${t}`}makeReplacements(e,r,s,i){const a=this.getDisplayableAttribute(r),c=this.getValue(r),n={attribute:a,ATTRIBUTE:a.toLocaleUpperCase(),Attribute:a.charAt(0).toLocaleUpperCase()+a.substring(1),input:this.getDisplayableValue(r,c)};for(const[t,r]of Object.entries(n))e=e.replaceAll(":"+t,r);const u=r.match(/\.(\d+)\.?/),h=null===u?-1:parseInt(u[1],10);-1!==h&&(e=e.replaceAll(":index",h).replaceAll(":position",h+1));const l=t("replace_"+s);return"function"==typeof this.#f[l]&&(e=this.#f[l](e,r,s,i)),e}getDisplayableAttribute(e){const t=this.getPrimaryAttribute(e);for(const r of[e,t]){if(this.#o.hasOwnProperty(r))return this.#o[r];if(d.has(`attributes.${r}`))return d.get(`attributes.${r}`)}return this.#m.hasOwnProperty(e)?e:(r=e,r.replace(/(.)(?=[A-Z])/g,(e=>e+"_")).toLowerCase()).replaceAll("_"," ");var r}getDisplayableValue(e,t){const r=`${e=this.getPrimaryAttribute(e)}.${t}`;return n(t)?"empty":"boolean"==typeof t||this.hasRule(e,"boolean")?Number(t)?"true":"false":this.#p.hasOwnProperty(r)?this.#p[r]:d.has(`values.${r}`)?d.get(`values.${r}`):t}getSize(e,t){return n(t)?0:u(t)&&this.hasRule(e,this.numericRules)?parseFloat("string"==typeof t?t.trim():t,10):t instanceof File?t.size/1024:h(t)?Object.keys(t).length:t.hasOwnProperty("length")?t.length:t}getRule(e){return e=this.getPrimaryAttribute(e),this.#h[e]??{}}hasRule(e,t){if(e=this.getPrimaryAttribute(e),t="string"==typeof t?[t]:t,!this.#h.hasOwnProperty(e))return!1;for(const r of t)if(this.#h[e].hasOwnProperty(r))return!0;return!1}getPrimaryAttribute(e){return this.#m.hasOwnProperty(e)?this.#m[e]:e}hasAttribute(e){return void 0!==this.getValue(e)}getValue(e){return function(e,t,r){const s=t.split(".");let i=e;for(const e of s){if(!i.hasOwnProperty(e))return r;i=i[e]}return i}(this.#r,e)}errors(){return this.#g}}return e.Checkers=o,e.ErrorBag=p,e.Lang=d,e.Replacers=f,e.Validator=g,e}({});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quival",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "Data validation à la Laravel Validation",
|
|
5
5
|
"author": "Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,15 +23,14 @@
|
|
|
23
23
|
"url": "https://github.com/apih/quival"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@babel/core": "^7.21.8",
|
|
27
|
-
"@babel/preset-env": "^7.21.5",
|
|
28
|
-
"@rollup/plugin-babel": "^6.0.3",
|
|
29
26
|
"@rollup/plugin-node-resolve": "^15.0.2",
|
|
27
|
+
"@rollup/plugin-swc": "^0.3.0",
|
|
30
28
|
"@rollup/plugin-terser": "^0.4.1",
|
|
31
29
|
"eslint": "^8.39.0",
|
|
32
30
|
"mocha": "^10.2.0",
|
|
33
|
-
"prettier": "^3.
|
|
34
|
-
"rollup": "^4.6.1"
|
|
31
|
+
"prettier": "^3.2.5",
|
|
32
|
+
"rollup": "^4.6.1",
|
|
33
|
+
"rollup-plugin-prettier": "^4.1.1"
|
|
35
34
|
},
|
|
36
35
|
"scripts": {
|
|
37
36
|
"build": "rollup --config",
|
package/rollup.config.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import
|
|
3
|
+
import swc from '@rollup/plugin-swc';
|
|
4
4
|
import resolve from '@rollup/plugin-node-resolve';
|
|
5
5
|
import terser from '@rollup/plugin-terser';
|
|
6
|
+
import prettier from 'rollup-plugin-prettier';
|
|
6
7
|
|
|
7
8
|
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
|
|
8
9
|
const banner = `/*!
|
|
@@ -20,6 +21,7 @@ const options = [
|
|
|
20
21
|
format: 'iife',
|
|
21
22
|
name: 'quival',
|
|
22
23
|
banner,
|
|
24
|
+
plugins: [prettier(JSON.parse(fs.readFileSync('.prettierrc.json')))],
|
|
23
25
|
},
|
|
24
26
|
{
|
|
25
27
|
file: 'dist/quival.min.js',
|
|
@@ -31,19 +33,15 @@ const options = [
|
|
|
31
33
|
],
|
|
32
34
|
plugins: [
|
|
33
35
|
resolve(),
|
|
34
|
-
|
|
36
|
+
swc({
|
|
37
|
+
swc: {
|
|
38
|
+
env: {
|
|
39
|
+
targets: 'last 1 year',
|
|
40
|
+
mode: 'entry',
|
|
41
|
+
coreJs: '3.22',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
35
44
|
exclude: 'node_modules/**',
|
|
36
|
-
babelHelpers: 'bundled',
|
|
37
|
-
presets: [
|
|
38
|
-
[
|
|
39
|
-
'@babel/preset-env',
|
|
40
|
-
{
|
|
41
|
-
targets: {
|
|
42
|
-
browsers: 'last 1 year',
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
],
|
|
47
45
|
}),
|
|
48
46
|
],
|
|
49
47
|
},
|
package/src/Checkers.js
CHANGED
|
@@ -132,6 +132,10 @@ export default class Checkers {
|
|
|
132
132
|
return true;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
checkList(attribute, value, parameters) {
|
|
136
|
+
return Array.isArray(value);
|
|
137
|
+
}
|
|
138
|
+
|
|
135
139
|
checkBoolean(attribute, value, parameters) {
|
|
136
140
|
return [true, false, 0, 1, '0', '1'].includes(value);
|
|
137
141
|
}
|
package/src/locales/en.js
CHANGED
|
@@ -65,6 +65,7 @@ export default {
|
|
|
65
65
|
ipv4: 'The :attribute field must be a valid IPv4 address.',
|
|
66
66
|
ipv6: 'The :attribute field must be a valid IPv6 address.',
|
|
67
67
|
json: 'The :attribute field must be a valid JSON string.',
|
|
68
|
+
list: 'The :attribute field must be a list.',
|
|
68
69
|
lowercase: 'The :attribute field must be lowercase.',
|
|
69
70
|
lt: {
|
|
70
71
|
array: 'The :attribute field must have less than :value items.',
|
package/src/locales/ms.js
CHANGED
|
@@ -65,6 +65,7 @@ export default {
|
|
|
65
65
|
ipv4: 'Medan :attribute mesti alamat IPv4 yang sah.',
|
|
66
66
|
ipv6: 'Medan :attribute mesti alamat IPv6 yang sah.',
|
|
67
67
|
json: 'Medan :attribute mesti rentetan JSON yang sah.',
|
|
68
|
+
list: 'Medan :attribute mesti berbentuk senarai.',
|
|
68
69
|
lowercase: 'Medan :attribute mesti dalam huruf kecil.',
|
|
69
70
|
lt: {
|
|
70
71
|
array: 'Medan :attribute mesti mempunyai kurang daripada :value item.',
|
package/test/test.js
CHANGED
|
@@ -1487,6 +1487,26 @@ describe('Validation', () => {
|
|
|
1487
1487
|
});
|
|
1488
1488
|
});
|
|
1489
1489
|
|
|
1490
|
+
describe(`Rule 'list'`, () => {
|
|
1491
|
+
const rules = { field: 'list' };
|
|
1492
|
+
|
|
1493
|
+
it(`Passes when the field is a list`, async () => {
|
|
1494
|
+
const validator = new Validator({ field: [1, 2, 3] }, rules);
|
|
1495
|
+
assert(await validator.passes());
|
|
1496
|
+
});
|
|
1497
|
+
|
|
1498
|
+
it(`Fails when the field is not a list`, async () => {
|
|
1499
|
+
const validator = new Validator({ field: { a: 1, b: 2, c: 3} }, rules);
|
|
1500
|
+
assert(await validator.fails());
|
|
1501
|
+
|
|
1502
|
+
validator.setData({ field: 123 });
|
|
1503
|
+
assert(await validator.fails());
|
|
1504
|
+
|
|
1505
|
+
validator.setData({ field: 'abc' });
|
|
1506
|
+
assert(await validator.fails());
|
|
1507
|
+
});
|
|
1508
|
+
});
|
|
1509
|
+
|
|
1490
1510
|
describe(`Rule 'lowercase'`, () => {
|
|
1491
1511
|
const rules = { field: 'lowercase' };
|
|
1492
1512
|
|