quival 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/locales/en.js +5 -1
- package/dist/locales/en.min.js +2 -2
- package/dist/locales/ms.js +5 -1
- package/dist/locales/ms.min.js +2 -2
- package/dist/quival.js +85 -25
- package/dist/quival.min.js +2 -2
- package/package.json +1 -1
- package/src/Checkers.js +53 -9
- package/src/Replacers.js +20 -3
- package/src/Validator.js +13 -5
- package/src/helpers.js +16 -8
- package/src/locales/en.js +4 -0
- package/src/locales/ms.js +4 -0
- package/test/helpers.js +26 -0
- package/test/validation.js +246 -0
package/dist/locales/en.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* quival v0.5.
|
|
2
|
+
* quival v0.5.4 (git+https://github.com/apih/quival.git)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -126,6 +126,10 @@ this.quival.locales.en = (function () {
|
|
|
126
126
|
uncompromised: 'The given :attribute has appeared in a data leak. Please choose a different :attribute.',
|
|
127
127
|
},
|
|
128
128
|
present: 'The :attribute field must be present.',
|
|
129
|
+
present_if: 'The :attribute field must be present when :other is :value.',
|
|
130
|
+
present_unless: 'The :attribute field must be present unless :other is :value.',
|
|
131
|
+
present_with: 'The :attribute field must be present when :values is present.',
|
|
132
|
+
present_with_all: 'The :attribute field must be present when :values are present.',
|
|
129
133
|
prohibited: 'The :attribute field is prohibited.',
|
|
130
134
|
prohibited_if: 'The :attribute field is prohibited when :other is :value.',
|
|
131
135
|
prohibited_unless: 'The :attribute field is prohibited unless :other is in :values.',
|
package/dist/locales/en.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* quival v0.5.
|
|
2
|
+
* quival v0.5.4 (git+https://github.com/apih/quival.git)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
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.",contains:"The :attribute field is missing a required value.",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_contain:"The :attribute field must not contain any of the following: :values.",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.",encoding:"The :attribute field must be encoded in :encoding.",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_if_declined:"The :attribute field is required when :other is declined.",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.",contains:"The :attribute field is missing a required value.",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_contain:"The :attribute field must not contain any of the following: :values.",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.",encoding:"The :attribute field must be encoded in :encoding.",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.",present_if:"The :attribute field must be present when :other is :value.",present_unless:"The :attribute field must be present unless :other is :value.",present_with:"The :attribute field must be present when :values is present.",present_with_all:"The :attribute field must be present when :values are 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_if_declined:"The :attribute field is required when :other is declined.",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.5.
|
|
2
|
+
* quival v0.5.4 (git+https://github.com/apih/quival.git)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -126,6 +126,10 @@ this.quival.locales.ms = (function () {
|
|
|
126
126
|
uncompromised: 'Nilai :attribute yang diberikan telah muncul dalam kebocoran data. Sila pilih :attribute yang berbeza.',
|
|
127
127
|
},
|
|
128
128
|
present: 'Medan :attribute mesti wujud.',
|
|
129
|
+
present_if: 'Medan :attribute mesti wujud apabila :other adalah :value.',
|
|
130
|
+
present_unless: 'Medan :attribute mesti wujud melainkan :other adalah :value.',
|
|
131
|
+
present_with: 'Medan :attribute mesti wujud apabila :values wujud.',
|
|
132
|
+
present_with_all: 'Medan :attribute mesti wujud apabila :values wujud.',
|
|
129
133
|
prohibited: 'Medan :attribute dilarang.',
|
|
130
134
|
prohibited_if: 'Medan :attribute dilarang apabila :other adalah :value.',
|
|
131
135
|
prohibited_unless: 'Medan :attribute dilarang melainkan :other berada dalam :values.',
|
package/dist/locales/ms.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* quival v0.5.
|
|
2
|
+
* quival v0.5.4 (git+https://github.com/apih/quival.git)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
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.",contains:"Medan :attribute tiada nilai yang diperlukan.",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_contain:"Medan :attribute tidak boleh mengandungi salah satu daripada berikut: :values.",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.",encoding:"Medan :attribute mesti dikodkan dalam :encoding.",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_if_declined:"Medan :attribute diperlukan apabila :other ditolak.",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.",contains:"Medan :attribute tiada nilai yang diperlukan.",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_contain:"Medan :attribute tidak boleh mengandungi salah satu daripada berikut: :values.",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.",encoding:"Medan :attribute mesti dikodkan dalam :encoding.",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.",present_if:"Medan :attribute mesti wujud apabila :other adalah :value.",present_unless:"Medan :attribute mesti wujud melainkan :other adalah :value.",present_with:"Medan :attribute mesti wujud apabila :values wujud.",present_with_all:"Medan :attribute mesti wujud apabila :values 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_if_declined:"Medan :attribute diperlukan apabila :other ditolak.",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.5.
|
|
2
|
+
* quival v0.5.4 (git+https://github.com/apih/quival.git)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -9,7 +9,7 @@ var quival = (function (exports) {
|
|
|
9
9
|
function toCamelCase(string) {
|
|
10
10
|
return string
|
|
11
11
|
.replace(/[-_]/g, ' ')
|
|
12
|
-
.replace(/\s
|
|
12
|
+
.replace(/\s+/g, ' ')
|
|
13
13
|
.trim()
|
|
14
14
|
.replace(/(\s\w)/g, (match) => match[1].toUpperCase());
|
|
15
15
|
}
|
|
@@ -23,7 +23,7 @@ var quival = (function (exports) {
|
|
|
23
23
|
const keys = path.split('.');
|
|
24
24
|
let current = obj;
|
|
25
25
|
for (const key of keys) {
|
|
26
|
-
if (!Object.hasOwn(current, key)) {
|
|
26
|
+
if (current === null || current === undefined || !Object.hasOwn(current, key)) {
|
|
27
27
|
return defaultValue;
|
|
28
28
|
}
|
|
29
29
|
current = current[key];
|
|
@@ -68,10 +68,10 @@ var quival = (function (exports) {
|
|
|
68
68
|
return result;
|
|
69
69
|
}
|
|
70
70
|
function parseDate(value) {
|
|
71
|
-
if (
|
|
72
|
-
return new Date('');
|
|
73
|
-
} else if (value instanceof Date) {
|
|
71
|
+
if (value instanceof Date) {
|
|
74
72
|
return value;
|
|
73
|
+
} else if (isEmpty(value) || typeof value !== 'string') {
|
|
74
|
+
return new Date('');
|
|
75
75
|
}
|
|
76
76
|
let match, years, months, days, hours, minutes, seconds, meridiem;
|
|
77
77
|
const castToIntegers = (value) => (value && /^\d*$/.test(value) ? parseInt(value) : value);
|
|
@@ -98,8 +98,11 @@ var quival = (function (exports) {
|
|
|
98
98
|
if (years >= 10 && years < 100) {
|
|
99
99
|
years += 2000;
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
meridiem = meridiem.toLowerCase();
|
|
102
|
+
if (meridiem === 'pm' && hours < 12) {
|
|
102
103
|
hours += 12;
|
|
104
|
+
} else if (meridiem === 'am' && hours === 12) {
|
|
105
|
+
hours = 0;
|
|
103
106
|
}
|
|
104
107
|
return new Date(`${years}-${months}-${days} ${hours}:${minutes}:${seconds}`);
|
|
105
108
|
}
|
|
@@ -188,8 +191,11 @@ var quival = (function (exports) {
|
|
|
188
191
|
if (years >= 10 && years < 100) {
|
|
189
192
|
years = years + 2000;
|
|
190
193
|
}
|
|
191
|
-
|
|
194
|
+
meridiem = meridiem.toLowerCase();
|
|
195
|
+
if (meridiem === 'pm' && hours < 12) {
|
|
192
196
|
hours += 12;
|
|
197
|
+
} else if (meridiem === 'am' && hours === 12) {
|
|
198
|
+
hours = 0;
|
|
193
199
|
}
|
|
194
200
|
return new Date(`${years}-${months}-${days} ${hours}:${minutes}:${seconds}`);
|
|
195
201
|
}
|
|
@@ -237,6 +243,16 @@ var quival = (function (exports) {
|
|
|
237
243
|
}
|
|
238
244
|
return true;
|
|
239
245
|
}
|
|
246
|
+
collectPresentsThenTest(attribute, value, parameters, callback) {
|
|
247
|
+
let result = [];
|
|
248
|
+
for (const other of parameters) {
|
|
249
|
+
result.push(this.checkPresent(other, this.validator.getValue(other)));
|
|
250
|
+
}
|
|
251
|
+
if (callback(result)) {
|
|
252
|
+
return this.checkPresent(attribute, value);
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
240
256
|
collectMissingsThenTest(attribute, value, parameters, callback) {
|
|
241
257
|
let result = [];
|
|
242
258
|
for (const other of parameters) {
|
|
@@ -278,18 +294,22 @@ var quival = (function (exports) {
|
|
|
278
294
|
return callback(this.validator.getSize(attribute, value), otherValue);
|
|
279
295
|
}
|
|
280
296
|
compareDates(attribute, value, parameters, callback) {
|
|
281
|
-
const
|
|
282
|
-
|
|
297
|
+
const rules = this.validator.getRule(attribute);
|
|
298
|
+
const dateFormatRule = Array.isArray(rules) ? rules.find(([name]) => name === 'date_format') : null;
|
|
299
|
+
const format = dateFormatRule ? dateFormatRule[1][0] : null;
|
|
300
|
+
value = format ? parseDateByFormat(value, format) : parseDate(value);
|
|
283
301
|
if (!isValidDate(value)) {
|
|
284
302
|
return false;
|
|
285
303
|
}
|
|
286
304
|
const other = parameters[0] ?? '';
|
|
287
305
|
let otherValue = this.validator.getValue(other);
|
|
288
306
|
if (typeof otherValue === 'undefined') {
|
|
289
|
-
otherValue = parseDate(other);
|
|
307
|
+
otherValue = format ? parseDateByFormat(other, format) : parseDate(other);
|
|
290
308
|
} else {
|
|
291
|
-
const
|
|
292
|
-
|
|
309
|
+
const otherRules = this.validator.getRule(other);
|
|
310
|
+
const otherDateFormatRule = Array.isArray(otherRules) ? otherRules.find(([name]) => name === 'date_format') : null;
|
|
311
|
+
const otherFormat = otherDateFormatRule ? otherDateFormatRule[1][0] : null;
|
|
312
|
+
otherValue = otherFormat ? parseDateByFormat(otherValue, otherFormat) : parseDate(otherValue);
|
|
293
313
|
}
|
|
294
314
|
if (!isValidDate(otherValue)) {
|
|
295
315
|
return false;
|
|
@@ -454,6 +474,24 @@ var quival = (function (exports) {
|
|
|
454
474
|
checkPresent(attribute, value, parameters) {
|
|
455
475
|
return typeof value !== 'undefined';
|
|
456
476
|
}
|
|
477
|
+
checkPresentIf(attribute, value, parameters) {
|
|
478
|
+
if (this.isDependent(parameters)) {
|
|
479
|
+
return this.checkPresent(attribute, value);
|
|
480
|
+
}
|
|
481
|
+
return true;
|
|
482
|
+
}
|
|
483
|
+
checkPresentUnless(attribute, value, parameters) {
|
|
484
|
+
if (!this.isDependent(parameters)) {
|
|
485
|
+
return this.checkPresent(attribute, value);
|
|
486
|
+
}
|
|
487
|
+
return true;
|
|
488
|
+
}
|
|
489
|
+
checkPresentWith(attribute, value, parameters) {
|
|
490
|
+
return this.collectPresentsThenTest(attribute, value, parameters, (result) => result.includes(true));
|
|
491
|
+
}
|
|
492
|
+
checkPresentWithAll(attribute, value, parameters) {
|
|
493
|
+
return this.collectPresentsThenTest(attribute, value, parameters, (result) => !result.includes(false));
|
|
494
|
+
}
|
|
457
495
|
// Missing
|
|
458
496
|
checkMissing(attribute, value, parameters) {
|
|
459
497
|
return typeof value === 'undefined';
|
|
@@ -878,12 +916,14 @@ var quival = (function (exports) {
|
|
|
878
916
|
if (/[^\d.]/.test(value)) {
|
|
879
917
|
return false;
|
|
880
918
|
}
|
|
881
|
-
const blocks = String(value)
|
|
919
|
+
const blocks = String(value)
|
|
920
|
+
.split('.')
|
|
921
|
+
.map((block) => parseInt(block, 10));
|
|
882
922
|
if (blocks.length !== 4) {
|
|
883
923
|
return false;
|
|
884
924
|
}
|
|
885
925
|
for (const block of blocks) {
|
|
886
|
-
if (block < 0 || block > 255) {
|
|
926
|
+
if (isNaN(block) || block < 0 || block > 255) {
|
|
887
927
|
return false;
|
|
888
928
|
}
|
|
889
929
|
}
|
|
@@ -929,10 +969,10 @@ var quival = (function (exports) {
|
|
|
929
969
|
return true;
|
|
930
970
|
}
|
|
931
971
|
checkUlid(attribute, value, parameters) {
|
|
932
|
-
return
|
|
972
|
+
return /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/.test(value);
|
|
933
973
|
}
|
|
934
974
|
checkUuid(attribute, value, parameters) {
|
|
935
|
-
return
|
|
975
|
+
return /^[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}$/.test(value);
|
|
936
976
|
}
|
|
937
977
|
}
|
|
938
978
|
|
|
@@ -1116,15 +1156,28 @@ var quival = (function (exports) {
|
|
|
1116
1156
|
replaceRequiredWithoutAll(message, attribute, rule, parameters) {
|
|
1117
1157
|
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
1118
1158
|
}
|
|
1119
|
-
//
|
|
1120
|
-
|
|
1159
|
+
// Present
|
|
1160
|
+
replacePresentIf(message, attribute, rule, parameters) {
|
|
1121
1161
|
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
1122
1162
|
}
|
|
1123
|
-
|
|
1163
|
+
replacePresentUnless(message, attribute, rule, parameters) {
|
|
1124
1164
|
return this.replaceCaseVariants(this.replaceRequiredUnless(message, attribute, rule, parameters), {
|
|
1125
1165
|
value: this.validator.getDisplayableValue(parameters[0], parameters[1]),
|
|
1126
1166
|
});
|
|
1127
1167
|
}
|
|
1168
|
+
replacePresentWith(message, attribute, rule, parameters) {
|
|
1169
|
+
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
1170
|
+
}
|
|
1171
|
+
replacePresentWithAll(message, attribute, rule, parameters) {
|
|
1172
|
+
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
1173
|
+
}
|
|
1174
|
+
// Missing
|
|
1175
|
+
replaceMissingIf(message, attribute, rule, parameters) {
|
|
1176
|
+
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
1177
|
+
}
|
|
1178
|
+
replaceMissingUnless(message, attribute, rule, parameters) {
|
|
1179
|
+
return this.replacePresentUnless(message, attribute, rule, parameters);
|
|
1180
|
+
}
|
|
1128
1181
|
replaceMissingWith(message, attribute, rule, parameters) {
|
|
1129
1182
|
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
1130
1183
|
}
|
|
@@ -1298,6 +1351,10 @@ var quival = (function (exports) {
|
|
|
1298
1351
|
'missing_with',
|
|
1299
1352
|
'missing_with_all',
|
|
1300
1353
|
'present',
|
|
1354
|
+
'present_if',
|
|
1355
|
+
'present_unless',
|
|
1356
|
+
'present_with',
|
|
1357
|
+
'present_with_all',
|
|
1301
1358
|
'required',
|
|
1302
1359
|
'required_if',
|
|
1303
1360
|
'required_if_accepted',
|
|
@@ -1645,14 +1702,17 @@ var quival = (function (exports) {
|
|
|
1645
1702
|
getDisplayableValue(attribute, value) {
|
|
1646
1703
|
attribute = this.getPrimaryAttribute(attribute);
|
|
1647
1704
|
const path = `${attribute}.${value}`;
|
|
1705
|
+
if (Object.hasOwn(this.#customValues, path)) {
|
|
1706
|
+
return this.#customValues[path];
|
|
1707
|
+
} else if (Lang.has(`values.${path}`)) {
|
|
1708
|
+
return Lang.get(`values.${path}`);
|
|
1709
|
+
}
|
|
1648
1710
|
if (isEmpty(value)) {
|
|
1649
1711
|
return 'empty';
|
|
1712
|
+
} else if (Array.isArray(value)) {
|
|
1713
|
+
return 'array';
|
|
1650
1714
|
} else if (typeof value === 'boolean' || this.hasRule(attribute, 'boolean')) {
|
|
1651
1715
|
return Number(value) ? 'true' : 'false';
|
|
1652
|
-
} else if (Object.hasOwn(this.#customValues, path)) {
|
|
1653
|
-
return this.#customValues[path];
|
|
1654
|
-
} else if (Lang.has(`values.${path}`)) {
|
|
1655
|
-
return Lang.get(`values.${path}`);
|
|
1656
1716
|
}
|
|
1657
1717
|
return value;
|
|
1658
1718
|
}
|
|
@@ -1674,7 +1734,7 @@ var quival = (function (exports) {
|
|
|
1674
1734
|
}
|
|
1675
1735
|
getRule(attribute) {
|
|
1676
1736
|
attribute = this.getPrimaryAttribute(attribute);
|
|
1677
|
-
return this.#rules[attribute] ??
|
|
1737
|
+
return this.#rules[attribute] ?? [];
|
|
1678
1738
|
}
|
|
1679
1739
|
hasRule(attribute, rules) {
|
|
1680
1740
|
attribute = this.getPrimaryAttribute(attribute);
|
package/dist/quival.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* quival v0.5.
|
|
2
|
+
* quival v0.5.4 (git+https://github.com/apih/quival.git)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
var quival=function(e){"use strict";function t(e){return e.replace(/[-_]/g," ").replace(/\s+/," ").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){if(c(e)||"string"!=typeof e)return new Date("");if(e instanceof Date)return e;let t,r,s,i,a,n,l,u;const h=e=>e&&/^\d*$/.test(e)?parseInt(e):e;if(null!==(t=e.match(/^(\d{1,2})[.\/-](\d{1,2})[.\/-](\d{2,4})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)))[,i,s,r,,a=0,n=0,,l=0,u="am"]=t.map(h);else if(null!==(t=e.match(/^(\d{2,4})[.\/-](\d{1,2})[.\/-](\d{1,2})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i))||null!==(t=e.match(/^(\d{4})(\d{2})(\d{2})\s?((\d{2})(\d{2})((\d{2}))?\s?(am|pm)?)?/i)))[,r,s,i,,a=0,n=0,,l=0,u="am"]=t.map(h);else if(t=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{4})[.\/-](\d{2})[.\/-](\d{2})/i))[,a,n,,l,u="am",r,s,i]=t.map(h);else if(t=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{2})[.\/-](\d{2})[.\/-](\d{4})/i))[,a,n,,l,u="am",i,s,r]=t.map(h);else{if(!(t=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?/i)))return new Date(e);{const e=new Date;r=e.getFullYear(),s=e.getMonth()+1,i=e.getDate(),[,a=0,n=0,,l=0,u="am"]=t.map(h)}}return r>=10&&r<100&&(r+=2e3),"pm"===u.toLowerCase()&&a<12&&(a+=12),new Date(`${r}-${s}-${i} ${a}:${n}:${l}`)}function a(e,t){if(c(e))return new Date("");t=t.split("");const r={Y:"(\\d{4})",y:"(\\d{2})",m:"(\\d{2})",n:"([1-9]\\d?)",d:"(\\d{2})",j:"([1-9]\\d?)",G:"([1-9]\\d?)",g:"([1-9]\\d?)",H:"(\\d{2})",h:"(\\d{2})",i:"(\\d{2})",s:"(\\d{2})",A:"(AM|PM)",a:"(am|pm)"};let s="^",i={years:-1,months:-1,days:-1,hours:-1,minutes:-1,seconds:-1,meridiem:-1},a=1;for(const e of t)Object.hasOwn(r,e)?(s+=r[e],-1!==["Y","y"].indexOf(e)?i.years=a++:-1!==["m","n"].indexOf(e)?i.months=a++:-1!==["d","j"].indexOf(e)?i.days=a++:-1!==["G","g","H","h"].indexOf(e)?i.hours=a++:"i"===e?i.minutes=a++:"s"===e?i.seconds=a++:-1!==["A","a"].indexOf(e)&&(i.meridiem=a++)):s+="\\"+e;s+="$";let n=e.match(new RegExp(s));if(null===n)return new Date("");n=n.map(e=>e&&/^\d*$/.test(e)?parseInt(e):e);const l=new Date;let u=n[i.years],h=n[i.months],o=n[i.days],p=n[i.hours]??0,d=n[i.minutes]??0,f=n[i.seconds]??0,g=n[i.meridiem]??"am";return u||h||o?!u||h||o?u||!h||o?u||h||!o||(u=l.getFullYear(),h=l.getMonth()+1):(u=l.getFullYear(),o=1):(h=1,o=1):(u=l.getFullYear(),h=l.getMonth()+1,o=l.getDate()),u>=10&&u<100&&(u+=2e3),"pm"===g.toLowerCase()&&p<12&&(p+=12),new Date(`${u}-${h}-${o} ${p}:${d}:${f}`)}function c(e){return""===e||null==e}function n(e){const t=Number(e);return null!==e&&"boolean"!=typeof e&&"number"==typeof t&&!isNaN(t)}function l(e){return"[object Object]"===Object.prototype.toString.call(e)}function u(e){return e instanceof Date&&"Invalid Date"!==e.toDateString()}class h{#e;#t;constructor(e){this.#e={},this.#t={},this.validator=e}clearCaches(){this.#e={},this.#t={}}isDependent(e){const t=this.validator.getValue(e[0]);return e.slice(1).some(e=>e==t)}collectRequiredsThenTest(e,t,r,s){let i=[];for(const e of r)i.push(this.checkRequired(e,this.validator.getValue(e)));return!s(i)||this.checkRequired(e,t)}collectMissingsThenTest(e,t,r,s){let i=[];for(const e of r)i.push(this.checkMissing(e,this.validator.getValue(e)));return!s(i)||this.checkMissing(e,t)}testStringUsingRegex(e,t,r,s,i=!1){return("string"==typeof t||"number"==typeof t)&&(t=String(t),i||this.validator.hasRule(e,"ascii")?r.test(t):s.test(t))}compareValues(e,t,r,s){if(c(t))return!1;const i=r[0]??"";let a=this.validator.getValue(i);return a=void 0===a?n(i)?parseFloat(i):null:this.validator.getSize(i,a),!c(a)&&s(this.validator.getSize(e,t),a)}compareDates(e,t,r,s){const c=this.validator.getRule(e);if(!u(t=Object.hasOwn(c,"date_format")?a(t,c.date_format[0]):i(t)))return!1;const n=r[0]??"";let l=this.validator.getValue(n);if(void 0===l)l=i(n);else{const e=this.validator.getRule(n);l=Object.hasOwn(e,"date_format")?a(l,e.date_format[0]):i(l)}return!!u(l)&&s(t.getTime(),l.getTime())}checkArray(e,t,r=[]){if(!Array.isArray(t)&&!l(t))return!1;if(r.length>0)for(const e of Object.keys(t))if(!r.includes(e))return!1;return!0}checkList(e,t,r){return Array.isArray(t)}checkBoolean(e,t,r=[]){return r.includes("strict")?[!0,!1].includes(t):[!0,!1,0,1,"0","1"].includes(t)}checkDate(e,t,r){return u(i(t))}checkFile(e,t,r){return t instanceof File}checkInteger(e,t,r=[]){return r.includes("strict")||"string"!=typeof t||(t=parseFloat(t)),Number.isInteger(t)}checkNumeric(e,t,r=[]){return r.includes("strict")?"number"==typeof t:n(t)}checkString(e,t,r){return"string"==typeof t}checkDecimal(e,t,r=[]){if(!this.checkNumeric(e,t))return!1;const s=(String(t).split(".")[1]??"").length;return 1===r.length?s==r[0]:s>=r[0]&&s<=r[1]}checkMultipleOf(e,t,r){if(!n(t)||!n(r[0]))return!1;const s=parseInt(t,10),i=parseInt(r[0],10);return(0!==s||0!==i)&&(0===s||0!==i&&s%i===0)}checkAccepted(e,t,r){return["yes","on","1",1,!0,"true"].includes(t)}checkAcceptedIf(e,t,r){return!this.isDependent(r)||this.checkAccepted(e,t,r)}checkDeclined(e,t,r){return["no","off","0",0,!1,"false"].includes(t)}checkDeclinedIf(e,t,r){return!this.isDependent(r)||this.checkDeclined(e,t,r)}checkRequired(e,t,r){return!c(t)&&(Array.isArray(t)?t.length>0:t instanceof File?t.size>0:(t=String(t).replace(/\s/g,"")).length>0)}checkRequiredArrayKeys(e,t,r=[]){if(!this.checkArray(e,t))return!1;const s=Object.keys(t);for(const e of r)if(!s.includes(e))return!1;return!0}checkRequiredIf(e,t,r){return!this.isDependent(r)||this.checkRequired(e,t)}checkRequiredIfAccepted(e,t,r){return!this.checkAccepted(r[0],this.validator.getValue(r[0]))||this.checkRequired(e,t)}checkRequiredIfDeclined(e,t,r){return!this.checkDeclined(r[0],this.validator.getValue(r[0]))||this.checkRequired(e,t)}checkRequiredUnless(e,t,r){return!!this.isDependent(r)||this.checkRequired(e,t)}checkRequiredWith(e,t,r){return this.collectRequiredsThenTest(e,t,r,e=>e.includes(!0))}checkRequiredWithAll(e,t,r){return this.collectRequiredsThenTest(e,t,r,e=>!e.includes(!1))}checkRequiredWithout(e,t,r){return this.collectRequiredsThenTest(e,t,r,e=>e.includes(!1))}checkRequiredWithoutAll(e,t,r){return this.collectRequiredsThenTest(e,t,r,e=>!e.includes(!0))}checkFilled(e,t,r){return void 0===t||this.checkRequired(e,t)}checkPresent(e,t,r){return void 0!==t}checkMissing(e,t,r){return void 0===t}checkMissingIf(e,t,r){return!this.isDependent(r)||this.checkMissing(e,t)}checkMissingUnless(e,t,r){return!!this.isDependent(r)||this.checkMissing(e,t)}checkMissingWith(e,t,r){return this.collectMissingsThenTest(e,t,r,e=>e.includes(!1))}checkMissingWithAll(e,t,r){return this.collectMissingsThenTest(e,t,r,e=>!e.includes(!0))}checkProhibited(e,t,r){return!this.checkRequired(e,t)}checkProhibitedIf(e,t,r){return!this.isDependent(r)||!this.checkRequired(e,t)}checkProhibitedUnless(e,t,r){return!!this.isDependent(r)||!this.checkRequired(e,t)}checkProhibits(e,t,r=[]){if(this.checkRequired(e,t))for(const e of r)if(this.checkRequired(e,this.validator.getValue(e)))return!1;return!0}checkSize(e,t,r){return this.validator.getSize(e,t)===parseFloat(r[0])}checkMin(e,t,r){return this.validator.getSize(e,t)>=parseFloat(r[0])}checkMax(e,t,r){return this.validator.getSize(e,t)<=parseFloat(r[0])}checkBetween(e,t,r){return this.checkMin(e,t,[r[0]])&&this.checkMax(e,t,[r[1]])}checkDigits(e,t,r,s=(e,t)=>e===t){return!!function(e){return-1===String(e).search(/[^0-9]/)}(t=String(t??""))&&s(t.length,parseInt(r[0],10),parseInt(r[1]??0,10))}checkMinDigits(e,t,r){return this.checkDigits(e,t,r,(e,t)=>e>=t)}checkMaxDigits(e,t,r){return this.checkDigits(e,t,r,(e,t)=>e<=t)}checkDigitsBetween(e,t,r){return this.checkDigits(e,t,r,(e,t,r)=>e>=t&&e<=r)}checkAlpha(e,t,r){return this.testStringUsingRegex(e,t,/^[a-z]+$/i,/^[\p{L}\p{M}]+$/u,r.includes("ascii"))}checkAlphaDash(e,t,r){return this.testStringUsingRegex(e,t,/^[a-z0-9_-]+$/i,/^[\p{L}\p{M}\p{N}_-]+$/u,r.includes("ascii"))}checkAlphaNum(e,t,r){return this.testStringUsingRegex(e,t,/^[a-z0-9]+$/i,/^[\p{L}\p{M}\p{N}]+$/u,r.includes("ascii"))}checkAscii(e,t,r){return!/[^\x09\x10\x13\x0A\x0D\x20-\x7E]/.test(t)}checkRegex(e,t,r,s=!1){if("string"!=typeof t&&!n(t))return!1;const i=r.join(",");let[a,l,u]=i.match(/^\/(.*)\/([gimu]*)$/)??[];if(c(a))throw new Error(`Invalid regular expression pattern: ${i}`);u.includes("u")&&(l=l.replace(/\\A/g,"^").replace(/\\z/gi,"$").replace(/\\([pP])([CLMNPSZ])/g,"\\$1{$2}").replace(/\\\x\{([0-9a-f]+)\}/g,"\\u{$1}"));const h=new RegExp(l,u).test(t);return s?!h:h}checkNotRegex(e,t,r){return this.checkRegex(e,t,r,!0)}checkLowercase(e,t,r){return t===String(t).toLocaleLowerCase()}checkUppercase(e,t,r){return t===String(t).toLocaleUpperCase()}checkStartsWith(e,t,r=[]){t=String(t);for(const e of r)if(t.startsWith(e))return!0;return!1}checkDoesntStartWith(e,t,r){return!this.checkStartsWith(e,t,r)}checkEndsWith(e,t,r=[]){t=String(t);for(const e of r)if(t.endsWith(e))return!0;return!1}checkDoesntEndWith(e,t,r){return!this.checkEndsWith(e,t,r)}checkSame(e,t,r){return t===this.validator.getValue(r[0])}checkDifferent(e,t,r=[]){for(const e of r){const r=this.validator.getValue(e);if(void 0!==r&&t===r)return!1}return!0}checkConfirmed(e,t,r){return this.checkSame(e,t,[r[0]??e+"_confirmation"])}checkGt(e,t,r){return this.compareValues(e,t,r,(e,t)=>e>t)}checkGte(e,t,r){return this.compareValues(e,t,r,(e,t)=>e>=t)}checkLt(e,t,r){return this.compareValues(e,t,r,(e,t)=>e<t)}checkLte(e,t,r){return this.compareValues(e,t,r,(e,t)=>e<=t)}checkAfter(e,t,r){return this.compareDates(e,t,r,(e,t)=>e>t)}checkAfterOrEqual(e,t,r){return this.compareDates(e,t,r,(e,t)=>e>=t)}checkBefore(e,t,r){return this.compareDates(e,t,r,(e,t)=>e<t)}checkBeforeOrEqual(e,t,r){return this.compareDates(e,t,r,(e,t)=>e<=t)}checkDateEquals(e,t,r){return this.compareDates(e,t,r,(e,t)=>e===t)}checkDateFormat(e,t,r){const s=r[0].split(""),i={Y:"(\\d{4})",y:"(\\d{2})",m:"(\\d{2})",n:"([1-9]\\d?)",d:"(\\d{2})",j:"([1-9]\\d?)",G:"([1-9]\\d?)",g:"([1-9]\\d?)",H:"(\\d{2})",h:"(\\d{2})",i:"(\\d{2})",s:"(\\d{2})",A:"(AM|PM)",a:"(am|pm)"};let a="^";for(const e of s)Object.hasOwn(i,e)?a+=i[e]:a+="\\"+e;return a+="$",new RegExp(a).test(t)}checkContains(e,t,r=[]){if(!this.checkArray(e,t))return!1;for(const e of r)if(!t.includes(e))return!1;return!0}checkDoesntContain(e,t,r=[]){if(!this.checkArray(e,t))return!1;for(const e of r)if(t.includes(e))return!1;return!0}checkDistinct(e,t,i){const a=this.validator.getPrimaryAttribute(e);if(!a.includes("*"))return!0;const c=a.indexOf("*"),n=a.substring(0,c-1);let l;Object.hasOwn(this.#e,n)?l=this.#e[n]:(l=JSON.stringify(s(this.validator.getValue(n)??{})),this.#e[n]=l);const u=i.includes("ignore_case"),h=!u&&i.includes("strict"),o=r(String(t));let p=`"${r(a.substring(c)).replaceAll("\\*",'[^."]+')}":`,d=0;return p+=h?"string"==typeof t?`"${o}"`:`${o}`:`(${o}|"${o}")`,p+="[,}]+",d+=l.match(new RegExp(p,"g"+(u?"i":"")))?.length??0,1===d}checkInArray(e,t,r){const i=this.validator.getPrimaryAttribute(r[0]);if(!i.includes("*"))return!1;const 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("jpg")&&!r.includes("jpeg")&&r.push("jpeg"),r.includes("jpeg")&&!r.includes("jpg")&&r.push("jpg"),r.includes(t.name.split(".").pop().toLowerCase()))}checkExtensions(e,t,r){return this.checkMimes(e,t,r)}async checkImage(e,t,r=[]){const s=["jpg","jpeg","png","gif","bmp","webp"];r.includes("allow_svg")&&s.push("svg");let i=this.checkMimes(e,t,s);return i&&"undefined"!=typeof FileReader?(await new Promise((e,r)=>{const s=new FileReader;s.onload=t=>e(t.target.result),s.onerror=r,s.readAsDataURL(t)}).then(async t=>{const r=new Image;r.src=t,await r.decode(),this.#t[e]=r}).catch(()=>{i=!1}),i):i}async checkDimensions(e,t,r=[]){if(!await this.checkImage(e,t)||!Object.hasOwn(this.#t,e))return!1;const s={};for(const e of r){const[t,r]=e.split("=",2);if("ratio"===t&&r.includes("/")){const[e,i]=r.split("/",2).map(e=>parseFloat(e,10));s[t]=e/i}else s[t]=parseFloat(r,10)}const i=this.#t[e],a=i.naturalWidth,c=i.naturalHeight;return!(Object.hasOwn(s,"width")&&s.width!==a||Object.hasOwn(s,"height")&&s.height!==c||Object.hasOwn(s,"min_width")&&s.min_width>a||Object.hasOwn(s,"min_height")&&s.min_height>c||Object.hasOwn(s,"max_width")&&s.max_width<a||Object.hasOwn(s,"max_height")&&s.max_height<c)&&(!Object.hasOwn(s,"ratio")||Math.abs(s.ratio-a/c)<=1/(Math.max(a,c)+1))}checkEmail(e,t,r){if(!/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(t)){return/^((?:[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]|[^\u0000-\u007F])+@(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?(?:\.(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?)+)*$/.test(t)}return!0}checkJson(e,t,r){try{JSON.parse(t)}catch(e){return!1}return!0}checkHexColor(e,t,r){return/^#(?:(?:[0-9a-f]{3}){1,2}|(?:[0-9a-f]{4}){1,2})$/i.test(t)}checkMacAddress(e,t,r){t=String(t);const s={"-":2,":":2,".":4};let i,a;for([i,a]of Object.entries(s))if(t.includes(i))break;const c=t.split(i);if(c.length!==12/a)return!1;for(const e of c)if(!new RegExp("^[0-9a-f]{"+a+"}$","i").test(e))return!1;return!0}checkIpv4(e,t,r){if(/[^\d.]/.test(t))return!1;const s=String(t).split(".");if(4!==s.length)return!1;for(const e of s)if(e<0||e>255)return!1;return!0}checkIpv6(e,t,r){if((t=String(t)).includes(":::")||t.split("::").length>2)return!1;const s=t.split(":");if(s.length<3||s.length>8)return!1;for(const e of s)if(""!==e&&!/^[0-9a-f]{1,4}$/i.test(e))return!1;return!0}checkIp(e,t,r){return this.checkIpv4(e,t,r)||this.checkIpv6(e,t,r)}checkTimezone(e,t,r){try{Intl.DateTimeFormat(void 0,{timeZone:t})}catch(e){if(e instanceof RangeError)return!1}return!0}checkUrl(e,t,r){try{new URL(t)}catch(e){return!1}return!0}checkUlid(e,t,r){return/[0-7][0-9A-HJKMNP-TV-Z]{25}/.test(t)}checkUuid(e,t,r){return/[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/.test(t)}}class o{#r;keys(){return Object.keys(this.#r)}values(){return Object.values(this.#r)}entries(){return Object.entries(this.#r)}add(e,t){Object.hasOwn(this.#r,e)?this.#r[e].push(t):this.#r[e]=[t]}get(e){if(!e.includes("*"))return Object.hasOwn(this.#r,e)?this.#r[e]:{};const t=new RegExp("^"+e.replaceAll("*",".*?")+"$"),r={};for(const[e,s]of this.entries())t.test(e)&&(r[e]=s);return r}first(e){for(const t of Object.values(this.get(e)))return Array.isArray(t)?t[0]:t;return""}has(e){return""!==this.first(e)}remove(e){delete this.#r[e]}messages(){return this.#r}all(){const e=[];return this.values().forEach(t=>e.push(...t)),e}count(){let e=0;return this.values().forEach(t=>e+=t.length),e}isEmpty(){return 0===this.keys().length}isNotEmpty(){return!this.isEmpty()}sortByKeys(e){const t={};for(const r of e)Object.hasOwn(this.#r,r)&&(t[r]=this.#r[r]);this.#r=t}constructor(){this.#r={}}}class p{static#s;static#i={};static locale(e){this.#s=e}static setMessages(e,t){this.#i[e]=s(t)}static get(e){if(this.#i[this.#s]&&this.#i[this.#s][e])return this.#i[this.#s][e]}static has(e){return void 0!==this.get(e)}static set(e,t){l(t)?Object.assign(this.#i[this.#s],s(t,e)):"string"==typeof t&&(this.#i[this.#s][e]=t)}}class d{constructor(e){this.validator=e}replace(e,t){return Object.entries(t).forEach(([t,r])=>e=e.replaceAll(":"+t,r)),e}replaceCaseVariants(e,t){return Object.entries(t).flatMap(([e,t])=>[[e,t],[e.toLocaleUpperCase(),t.toLocaleUpperCase()],[e.charAt(0).toLocaleUpperCase()+e.substring(1),t.charAt(0).toLocaleUpperCase()+t.substring(1)]]).forEach(([t,r])=>e=e.replaceAll(":"+t,r)),e}replaceDecimal(e,t,r,s){return this.replace(e,{decimal:s.join("-")})}replaceMultipleOf(e,t,r,s){return this.replace(e,{value:s[0]})}replaceAcceptedIf(e,t,r,s){return this.replaceCaseVariants(e,{other:this.validator.getDisplayableAttribute(s[0]),value:this.validator.getDisplayableValue(s[0],this.validator.getValue(s[0]))})}replaceDeclinedIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredArrayKeys(e,t,r,s){return this.replace(e,{values:s.map(e=>this.validator.getDisplayableValue(t,e)).join(", ")})}replaceRequiredIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredIfAccepted(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredIfDeclined(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredUnless(e,t,r,s){return this.replaceCaseVariants(e,{other:this.validator.getDisplayableAttribute(s[0]),values:s.slice(1).map(e=>this.validator.getDisplayableValue(s[0],e)).join(", ")})}replaceRequiredWith(e,t,r,s){return this.replaceCaseVariants(e,{values:s.map(e=>this.validator.getDisplayableAttribute(e)).join(" / ")})}replaceRequiredWithAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceRequiredWithout(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceRequiredWithoutAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceMissingIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceMissingUnless(e,t,r,s){return this.replaceCaseVariants(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.replaceCaseVariants(e,{other:s.map(e=>this.validator.getDisplayableAttribute(e)).join(" / ")})}replaceSize(e,t,r,s){return this.replace(e,{size:s[0]})}replaceMin(e,t,r,s){return this.replace(e,{min:s[0]})}replaceMax(e,t,r,s){return this.replace(e,{max:s[0]})}replaceBetween(e,t,r,s){return this.replace(e,{min:s[0],max:s[1]})}replaceDigits(e,t,r,s){return this.replace(e,{digits:s[0]})}replaceMinDigits(e,t,r,s){return this.replaceMin(e,t,r,s)}replaceMaxDigits(e,t,r,s){return this.replaceMax(e,t,r,s)}replaceDigitsBetween(e,t,r,s){return this.replaceBetween(e,t,r,s)}replaceStartsWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceDoesntStartWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceEndsWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceDoesntEndWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceSame(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceDifferent(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceGt(e,t,r,s){const i=this.validator.getValue(s[0]);return this.replace(e,{value:i?this.validator.getSize(s[0],i):this.validator.getDisplayableAttribute(s[0])})}replaceGte(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceLt(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceLte(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceAfter(e,t,r,s){const i=s[0];return this.replace(e,{date:this.validator.hasAttribute(i)?this.validator.getDisplayableAttribute(i):i})}replaceAfterOrEqual(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceBefore(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceBeforeOrEqual(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceDateEquals(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceDateFormat(e,t,r,s){return this.replace(e,{format:s[0]})}replaceInArray(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceIn(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceNotIn(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceDoesntContain(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceMimetypes(e,t,r,s){return this.replace(e,{values:s.join(", ")})}replaceMimes(e,t,r,s){return this.replaceMimetypes(e,t,r,s)}replaceExtensions(e,t,r,s){return this.replaceMimetypes(e,t,r,s)}}class f{static#a={};static#c={};static#n=["active_url","bail","can","current_password","encoding","enum","exclude","exclude_if","exclude_unless","exclude_with","exclude_without","exists","nullable","sometimes","unique"];static#l=["accepted","accepted_if","declined","declined_if","filled","missing","missing_if","missing_unless","missing_with","missing_with_all","present","required","required_if","required_if_accepted","required_if_declined","required_unless","required_with","required_with_all","required_without","required_without_all"];#r;#u;#h;#o;#p;#d;#f;#g;#m;#k;#b;#y;static setLocale(e){p.locale(e)}static setMessages(e,t){p.setMessages(e,t)}static addChecker(e,t,r){f.#a[e]=t,r&&p.set(e,r)}static addImplicitChecker(e,t,r){f.addChecker(e,t,r),f.#l.push(e)}static addReplacer(e,t){f.#c[e]=t}static addDummyRule(e){f.#n.push(e)}constructor(e={},r={},s={},i={},a={}){this.#m=[],this.#k={},this.#b=!1,this.#y=!1,this.arrayRules=["array","list"],this.fileRules=["file","image","mimetypes","mimes"],this.stringRules=["string","alpha","alpha_dash","alpha_num","ascii","email"],this.numericRules=["decimal","numeric","integer"],this.sizeRules=["size","between","min","max","gt","lt","gte","lte"],this.setProperties(e,r,s,i,a),this.#d=new h(this),this.#f=new d(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.#f[t("replace_"+e)]=r;this.#g=new o}setProperties(e={},t={},r={},i={},a={}){return this.#r=e,this.#u=this.parseRules(t),this.#h=r,this.#o=i,this.#p=s(a),this}setData(e){return this.#r=e,this}setRules(e){return this.#u=this.parseRules(e),this}setCustomMessages(e){return this.#h=e,this}setCustomAttributes(e){return this.#o=e,this}setCustomValues(e){return this.#p=s(e),this}addImplicitAttribute(e,t){return this.#k[e]=t,this}stopOnFirstFailure(e=!0){return this.#b=e,this}alwaysBail(e=!0){return this.#y=e,this}parseRules(e){const t={};for(const[r,s]of Object.entries(e)){const e=r.includes("*")?this.parseWildcardAttribute(r):[r];for(const r of e){const e=[];for(const t of this.parseAttributeRules(s))e.push(this.parseAttributeRule(t));t[r]=e}}return t}parseWildcardAttribute(e){const t=[],r=e.indexOf("*"),s=e.substring(0,r-1),i=e.substring(r+2),a=this.getValue(s);return Array.isArray(a)||l(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.#k[t]=e)}),t):[e]}parseAttributeRules(e){return Array.isArray(e)?e:"function"==typeof e?[e]:String(e).split("|")}parseAttributeRule(e){if("function"==typeof e)return[e,[]];let t,r;if(Array.isArray(e))t=e[0]??"",r=e.slice(1);else{const s=e.indexOf(":");-1===s?(t=e,r=[]):(t=e.substring(0,s),r=function(e){const t=[];let r="",s=!1;for(let i=0;i<e.length;i++){const 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}(e.substring(s+1)))}return[this.normalizeRuleName(t),r]}normalizeRuleName(e){return{int:"integer",bool:"boolean"}[e]??e}async validate(){this.#d.clearCaches(),this.#g=new o;const e=[],r=new Set;for(const[e,r]of Object.entries(this.#u))for(const[e]of r)if(""!==e&&"function"!=typeof e&&"function"!=typeof this.#d[t("check_"+e)]&&!f.#n.includes(e))throw new Error(`Invalid validation rule: ${e}`);for(const[s,i]of Object.entries(this.#u)){let a=this.getValue(s);const n=e=>i.some(t=>t[0]===e);n("sometimes")&&void 0===a?r.add(s):e.push(async()=>{const e=this.#y||n("bail"),l=n("nullable");let u=!0;for(const[n,h]of i){if(""===n||"function"!=typeof n&&!f.#l.includes(n)&&(void 0===a||"string"==typeof a&&""===a.trim()||l&&null===a)){r.add(s);continue}let i,o,p;const d=(()=>{if("function"==typeof n)return n;{const e=this.#d[t("check_"+n)]??null;return null===e&&f.#n.includes(n)?()=>!0:e}})();if(null===d)throw new Error(`Invalid validation rule: ${n}`);if(i=await d.call(this.#d,s,a,h),"boolean"==typeof i&&(i={success:i}),({success:o,message:p=""}=i),!o&&(u=!1,p=c(p)?this.getMessage(s,n):p,p=this.makeReplacements(p,s,n,h),this.#g.add(s,p),e||f.#l.includes(n)))break}return u})}if(this.#b){for(const t of e)if(!await t())break}else await Promise.allSettled(e.map(e=>e())).then(e=>{for(const t of e)if("rejected"===t.status)throw t.reason}),this.#g.sortByKeys(Object.keys(this.#u));return this.#m=[...r],this.#g}async passes(){return await this.validate(),!this.#g.isNotEmpty()}async fails(){return!await this.passes()}getMessage(e,t){if("function"==typeof t)return"";const r=this.getValue(e);let s;e=this.getPrimaryAttribute(e);for(const r of[`${e}.${t}`,t])if(Object.hasOwn(this.#h,r)){s=this.#h[r];break}if(!s){let i=t;this.sizeRules.includes(i)&&(Array.isArray(r)||l(r)||this.hasRule(e,this.arrayRules)?i+=".array":r instanceof File||this.hasRule(e,this.fileRules)?i+=".file":this.hasRule(e,this.stringRules)?i+=".string":n(r)||this.hasRule(e,this.numericRules)?i+=".numeric":i+=".string"),s=p.get(i)}return s??`validation.${t}`}makeReplacements(e,r,s,i){const 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+)\.?/),u=null===l?-1:parseInt(l[1],10);if(-1!==u&&(e=e.replaceAll(":index",u).replaceAll(":position",u+1)),"string"==typeof s){const a=this.#f[t("replace_"+s)]??null;a&&(e=a.call(this.#f,e,r,s,i))}return e}getDisplayableAttribute(e){const t=this.getPrimaryAttribute(e);for(const r of[e,t]){if(Object.hasOwn(this.#o,r))return this.#o[r];if(p.has(`attributes.${r}`))return p.get(`attributes.${r}`)}return Object.hasOwn(this.#k,e)?e:(r=e,r.replace(/(.)(?=[A-Z])/g,e=>e+"_").toLowerCase()).replaceAll("_"," ");var r}getDisplayableValue(e,t){const r=`${e=this.getPrimaryAttribute(e)}.${t}`;return c(t)?"empty":"boolean"==typeof t||this.hasRule(e,"boolean")?Number(t)?"true":"false":Object.hasOwn(this.#p,r)?this.#p[r]:p.has(`values.${r}`)?p.get(`values.${r}`):t}getSize(e,t){return c(t)?0:this.hasRule(e,this.stringRules)?String(t).length:n(t)&&this.hasRule(e,this.numericRules)?parseFloat("string"==typeof t?t.trim():t,10):t instanceof File?t.size/1024:l(t)?Object.keys(t).length:Object.hasOwn(t,"length")?t.length:t}getRule(e){return e=this.getPrimaryAttribute(e),this.#u[e]??{}}hasRule(e,t){if(e=this.getPrimaryAttribute(e),t="string"==typeof t?[t]:t,!Object.hasOwn(this.#u,e))return!1;for(const r of t)if(this.#u[e].some(e=>e[0]===r))return!0;return!1}getPrimaryAttribute(e){return Object.hasOwn(this.#k,e)?this.#k[e]:e}hasAttribute(e){return void 0!==this.getValue(e)}getValue(e){return function(e,t,r){const s=t.split(".");let i=e;for(const e of s){if(!Object.hasOwn(i,e))return r;i=i[e]}return i}(this.#r,e)}errors(){return this.#g}skippedAttributes(){return this.#m}}return e.Checkers=h,e.ErrorBag=o,e.Lang=p,e.Replacers=d,e.Validator=f,e}({});
|
|
6
|
+
var quival=function(e){"use strict";function t(e){return e.replace(/[-_]/g," ").replace(/\s+/g," ").trim().replace(/(\s\w)/g,e=>e[1].toUpperCase())}function r(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function s(e,t=""){return Object.keys(e).reduce((r,i)=>{const c=t?`${t}.${i}`:i;return"object"==typeof e[i]&&null!==e[i]?Object.assign(r,s(e[i],c)):r[c]=e[i],r},{})}function i(e){if(e instanceof Date)return e;if(a(e)||"string"!=typeof e)return new Date("");let t,r,s,i,c,n,l,u;const h=e=>e&&/^\d*$/.test(e)?parseInt(e):e;if(null!==(t=e.match(/^(\d{1,2})[.\/-](\d{1,2})[.\/-](\d{2,4})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)))[,i,s,r,,c=0,n=0,,l=0,u="am"]=t.map(h);else if(null!==(t=e.match(/^(\d{2,4})[.\/-](\d{1,2})[.\/-](\d{1,2})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i))||null!==(t=e.match(/^(\d{4})(\d{2})(\d{2})\s?((\d{2})(\d{2})((\d{2}))?\s?(am|pm)?)?/i)))[,r,s,i,,c=0,n=0,,l=0,u="am"]=t.map(h);else if(t=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{4})[.\/-](\d{2})[.\/-](\d{2})/i))[,c,n,,l,u="am",r,s,i]=t.map(h);else if(t=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{2})[.\/-](\d{2})[.\/-](\d{4})/i))[,c,n,,l,u="am",i,s,r]=t.map(h);else{if(!(t=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?/i)))return new Date(e);{const e=new Date;r=e.getFullYear(),s=e.getMonth()+1,i=e.getDate(),[,c=0,n=0,,l=0,u="am"]=t.map(h)}}return r>=10&&r<100&&(r+=2e3),u=u.toLowerCase(),"pm"===u&&c<12?c+=12:"am"===u&&12===c&&(c=0),new Date(`${r}-${s}-${i} ${c}:${n}:${l}`)}function c(e,t){if(a(e))return new Date("");t=t.split("");const r={Y:"(\\d{4})",y:"(\\d{2})",m:"(\\d{2})",n:"([1-9]\\d?)",d:"(\\d{2})",j:"([1-9]\\d?)",G:"([1-9]\\d?)",g:"([1-9]\\d?)",H:"(\\d{2})",h:"(\\d{2})",i:"(\\d{2})",s:"(\\d{2})",A:"(AM|PM)",a:"(am|pm)"};let s="^",i={years:-1,months:-1,days:-1,hours:-1,minutes:-1,seconds:-1,meridiem:-1},c=1;for(const e of t)Object.hasOwn(r,e)?(s+=r[e],-1!==["Y","y"].indexOf(e)?i.years=c++:-1!==["m","n"].indexOf(e)?i.months=c++:-1!==["d","j"].indexOf(e)?i.days=c++:-1!==["G","g","H","h"].indexOf(e)?i.hours=c++:"i"===e?i.minutes=c++:"s"===e?i.seconds=c++:-1!==["A","a"].indexOf(e)&&(i.meridiem=c++)):s+="\\"+e;s+="$";let n=e.match(new RegExp(s));if(null===n)return new Date("");n=n.map(e=>e&&/^\d*$/.test(e)?parseInt(e):e);const l=new Date;let u=n[i.years],h=n[i.months],o=n[i.days],p=n[i.hours]??0,d=n[i.minutes]??0,f=n[i.seconds]??0,g=n[i.meridiem]??"am";return u||h||o?!u||h||o?u||!h||o?u||h||!o||(u=l.getFullYear(),h=l.getMonth()+1):(u=l.getFullYear(),o=1):(h=1,o=1):(u=l.getFullYear(),h=l.getMonth()+1,o=l.getDate()),u>=10&&u<100&&(u+=2e3),g=g.toLowerCase(),"pm"===g&&p<12?p+=12:"am"===g&&12===p&&(p=0),new Date(`${u}-${h}-${o} ${p}:${d}:${f}`)}function a(e){return""===e||null==e}function n(e){const t=Number(e);return null!==e&&"boolean"!=typeof e&&"number"==typeof t&&!isNaN(t)}function l(e){return"[object Object]"===Object.prototype.toString.call(e)}function u(e){return e instanceof Date&&"Invalid Date"!==e.toDateString()}class h{#e;#t;constructor(e){this.#e={},this.#t={},this.validator=e}clearCaches(){this.#e={},this.#t={}}isDependent(e){const t=this.validator.getValue(e[0]);return e.slice(1).some(e=>e==t)}collectRequiredsThenTest(e,t,r,s){let i=[];for(const e of r)i.push(this.checkRequired(e,this.validator.getValue(e)));return!s(i)||this.checkRequired(e,t)}collectPresentsThenTest(e,t,r,s){let i=[];for(const e of r)i.push(this.checkPresent(e,this.validator.getValue(e)));return!s(i)||this.checkPresent(e,t)}collectMissingsThenTest(e,t,r,s){let i=[];for(const e of r)i.push(this.checkMissing(e,this.validator.getValue(e)));return!s(i)||this.checkMissing(e,t)}testStringUsingRegex(e,t,r,s,i=!1){return("string"==typeof t||"number"==typeof t)&&(t=String(t),i||this.validator.hasRule(e,"ascii")?r.test(t):s.test(t))}compareValues(e,t,r,s){if(a(t))return!1;const i=r[0]??"";let c=this.validator.getValue(i);return c=void 0===c?n(i)?parseFloat(i):null:this.validator.getSize(i,c),!a(c)&&s(this.validator.getSize(e,t),c)}compareDates(e,t,r,s){const a=this.validator.getRule(e),n=Array.isArray(a)?a.find(([e])=>"date_format"===e):null,l=n?n[1][0]:null;if(!u(t=l?c(t,l):i(t)))return!1;const h=r[0]??"";let o=this.validator.getValue(h);if(void 0===o)o=l?c(h,l):i(h);else{const e=this.validator.getRule(h),t=Array.isArray(e)?e.find(([e])=>"date_format"===e):null,r=t?t[1][0]:null;o=r?c(o,r):i(o)}return!!u(o)&&s(t.getTime(),o.getTime())}checkArray(e,t,r=[]){if(!Array.isArray(t)&&!l(t))return!1;if(r.length>0)for(const e of Object.keys(t))if(!r.includes(e))return!1;return!0}checkList(e,t,r){return Array.isArray(t)}checkBoolean(e,t,r=[]){return r.includes("strict")?[!0,!1].includes(t):[!0,!1,0,1,"0","1"].includes(t)}checkDate(e,t,r){return u(i(t))}checkFile(e,t,r){return t instanceof File}checkInteger(e,t,r=[]){return r.includes("strict")||"string"!=typeof t||(t=parseFloat(t)),Number.isInteger(t)}checkNumeric(e,t,r=[]){return r.includes("strict")?"number"==typeof t:n(t)}checkString(e,t,r){return"string"==typeof t}checkDecimal(e,t,r=[]){if(!this.checkNumeric(e,t))return!1;const s=(String(t).split(".")[1]??"").length;return 1===r.length?s==r[0]:s>=r[0]&&s<=r[1]}checkMultipleOf(e,t,r){if(!n(t)||!n(r[0]))return!1;const s=parseInt(t,10),i=parseInt(r[0],10);return(0!==s||0!==i)&&(0===s||0!==i&&s%i===0)}checkAccepted(e,t,r){return["yes","on","1",1,!0,"true"].includes(t)}checkAcceptedIf(e,t,r){return!this.isDependent(r)||this.checkAccepted(e,t,r)}checkDeclined(e,t,r){return["no","off","0",0,!1,"false"].includes(t)}checkDeclinedIf(e,t,r){return!this.isDependent(r)||this.checkDeclined(e,t,r)}checkRequired(e,t,r){return!a(t)&&(Array.isArray(t)?t.length>0:t instanceof File?t.size>0:(t=String(t).replace(/\s/g,"")).length>0)}checkRequiredArrayKeys(e,t,r=[]){if(!this.checkArray(e,t))return!1;const s=Object.keys(t);for(const e of r)if(!s.includes(e))return!1;return!0}checkRequiredIf(e,t,r){return!this.isDependent(r)||this.checkRequired(e,t)}checkRequiredIfAccepted(e,t,r){return!this.checkAccepted(r[0],this.validator.getValue(r[0]))||this.checkRequired(e,t)}checkRequiredIfDeclined(e,t,r){return!this.checkDeclined(r[0],this.validator.getValue(r[0]))||this.checkRequired(e,t)}checkRequiredUnless(e,t,r){return!!this.isDependent(r)||this.checkRequired(e,t)}checkRequiredWith(e,t,r){return this.collectRequiredsThenTest(e,t,r,e=>e.includes(!0))}checkRequiredWithAll(e,t,r){return this.collectRequiredsThenTest(e,t,r,e=>!e.includes(!1))}checkRequiredWithout(e,t,r){return this.collectRequiredsThenTest(e,t,r,e=>e.includes(!1))}checkRequiredWithoutAll(e,t,r){return this.collectRequiredsThenTest(e,t,r,e=>!e.includes(!0))}checkFilled(e,t,r){return void 0===t||this.checkRequired(e,t)}checkPresent(e,t,r){return void 0!==t}checkPresentIf(e,t,r){return!this.isDependent(r)||this.checkPresent(e,t)}checkPresentUnless(e,t,r){return!!this.isDependent(r)||this.checkPresent(e,t)}checkPresentWith(e,t,r){return this.collectPresentsThenTest(e,t,r,e=>e.includes(!0))}checkPresentWithAll(e,t,r){return this.collectPresentsThenTest(e,t,r,e=>!e.includes(!1))}checkMissing(e,t,r){return void 0===t}checkMissingIf(e,t,r){return!this.isDependent(r)||this.checkMissing(e,t)}checkMissingUnless(e,t,r){return!!this.isDependent(r)||this.checkMissing(e,t)}checkMissingWith(e,t,r){return this.collectMissingsThenTest(e,t,r,e=>e.includes(!1))}checkMissingWithAll(e,t,r){return this.collectMissingsThenTest(e,t,r,e=>!e.includes(!0))}checkProhibited(e,t,r){return!this.checkRequired(e,t)}checkProhibitedIf(e,t,r){return!this.isDependent(r)||!this.checkRequired(e,t)}checkProhibitedUnless(e,t,r){return!!this.isDependent(r)||!this.checkRequired(e,t)}checkProhibits(e,t,r=[]){if(this.checkRequired(e,t))for(const e of r)if(this.checkRequired(e,this.validator.getValue(e)))return!1;return!0}checkSize(e,t,r){return this.validator.getSize(e,t)===parseFloat(r[0])}checkMin(e,t,r){return this.validator.getSize(e,t)>=parseFloat(r[0])}checkMax(e,t,r){return this.validator.getSize(e,t)<=parseFloat(r[0])}checkBetween(e,t,r){return this.checkMin(e,t,[r[0]])&&this.checkMax(e,t,[r[1]])}checkDigits(e,t,r,s=(e,t)=>e===t){return!!function(e){return-1===String(e).search(/[^0-9]/)}(t=String(t??""))&&s(t.length,parseInt(r[0],10),parseInt(r[1]??0,10))}checkMinDigits(e,t,r){return this.checkDigits(e,t,r,(e,t)=>e>=t)}checkMaxDigits(e,t,r){return this.checkDigits(e,t,r,(e,t)=>e<=t)}checkDigitsBetween(e,t,r){return this.checkDigits(e,t,r,(e,t,r)=>e>=t&&e<=r)}checkAlpha(e,t,r){return this.testStringUsingRegex(e,t,/^[a-z]+$/i,/^[\p{L}\p{M}]+$/u,r.includes("ascii"))}checkAlphaDash(e,t,r){return this.testStringUsingRegex(e,t,/^[a-z0-9_-]+$/i,/^[\p{L}\p{M}\p{N}_-]+$/u,r.includes("ascii"))}checkAlphaNum(e,t,r){return this.testStringUsingRegex(e,t,/^[a-z0-9]+$/i,/^[\p{L}\p{M}\p{N}]+$/u,r.includes("ascii"))}checkAscii(e,t,r){return!/[^\x09\x10\x13\x0A\x0D\x20-\x7E]/.test(t)}checkRegex(e,t,r,s=!1){if("string"!=typeof t&&!n(t))return!1;const i=r.join(",");let[c,l,u]=i.match(/^\/(.*)\/([gimu]*)$/)??[];if(a(c))throw new Error(`Invalid regular expression pattern: ${i}`);u.includes("u")&&(l=l.replace(/\\A/g,"^").replace(/\\z/gi,"$").replace(/\\([pP])([CLMNPSZ])/g,"\\$1{$2}").replace(/\\\x\{([0-9a-f]+)\}/g,"\\u{$1}"));const h=new RegExp(l,u).test(t);return s?!h:h}checkNotRegex(e,t,r){return this.checkRegex(e,t,r,!0)}checkLowercase(e,t,r){return t===String(t).toLocaleLowerCase()}checkUppercase(e,t,r){return t===String(t).toLocaleUpperCase()}checkStartsWith(e,t,r=[]){t=String(t);for(const e of r)if(t.startsWith(e))return!0;return!1}checkDoesntStartWith(e,t,r){return!this.checkStartsWith(e,t,r)}checkEndsWith(e,t,r=[]){t=String(t);for(const e of r)if(t.endsWith(e))return!0;return!1}checkDoesntEndWith(e,t,r){return!this.checkEndsWith(e,t,r)}checkSame(e,t,r){return t===this.validator.getValue(r[0])}checkDifferent(e,t,r=[]){for(const e of r){const r=this.validator.getValue(e);if(void 0!==r&&t===r)return!1}return!0}checkConfirmed(e,t,r){return this.checkSame(e,t,[r[0]??e+"_confirmation"])}checkGt(e,t,r){return this.compareValues(e,t,r,(e,t)=>e>t)}checkGte(e,t,r){return this.compareValues(e,t,r,(e,t)=>e>=t)}checkLt(e,t,r){return this.compareValues(e,t,r,(e,t)=>e<t)}checkLte(e,t,r){return this.compareValues(e,t,r,(e,t)=>e<=t)}checkAfter(e,t,r){return this.compareDates(e,t,r,(e,t)=>e>t)}checkAfterOrEqual(e,t,r){return this.compareDates(e,t,r,(e,t)=>e>=t)}checkBefore(e,t,r){return this.compareDates(e,t,r,(e,t)=>e<t)}checkBeforeOrEqual(e,t,r){return this.compareDates(e,t,r,(e,t)=>e<=t)}checkDateEquals(e,t,r){return this.compareDates(e,t,r,(e,t)=>e===t)}checkDateFormat(e,t,r){const s=r[0].split(""),i={Y:"(\\d{4})",y:"(\\d{2})",m:"(\\d{2})",n:"([1-9]\\d?)",d:"(\\d{2})",j:"([1-9]\\d?)",G:"([1-9]\\d?)",g:"([1-9]\\d?)",H:"(\\d{2})",h:"(\\d{2})",i:"(\\d{2})",s:"(\\d{2})",A:"(AM|PM)",a:"(am|pm)"};let c="^";for(const e of s)Object.hasOwn(i,e)?c+=i[e]:c+="\\"+e;return c+="$",new RegExp(c).test(t)}checkContains(e,t,r=[]){if(!this.checkArray(e,t))return!1;for(const e of r)if(!t.includes(e))return!1;return!0}checkDoesntContain(e,t,r=[]){if(!this.checkArray(e,t))return!1;for(const e of r)if(t.includes(e))return!1;return!0}checkDistinct(e,t,i){const c=this.validator.getPrimaryAttribute(e);if(!c.includes("*"))return!0;const a=c.indexOf("*"),n=c.substring(0,a-1);let l;Object.hasOwn(this.#e,n)?l=this.#e[n]:(l=JSON.stringify(s(this.validator.getValue(n)??{})),this.#e[n]=l);const u=i.includes("ignore_case"),h=!u&&i.includes("strict"),o=r(String(t));let p=`"${r(c.substring(a)).replaceAll("\\*",'[^."]+')}":`,d=0;return p+=h?"string"==typeof t?`"${o}"`:`${o}`:`(${o}|"${o}")`,p+="[,}]+",d+=l.match(new RegExp(p,"g"+(u?"i":"")))?.length??0,1===d}checkInArray(e,t,r){const i=this.validator.getPrimaryAttribute(r[0]);if(!i.includes("*"))return!1;const c=this.validator.getValue(i.split(".*")[0])??{};return Object.values(s(c)).some(e=>e==t)}checkIn(e,t,r){if(!this.checkArray(e,t)||!this.validator.hasRule(e,"array"))return r.some(e=>e==t);for(const e of Object.values(t))if(!r.some(t=>t==e))return!1;return!0}checkNotIn(e,t,r){return!this.checkIn(e,t,r)}checkMimetypes(e,t,r){return!!this.checkFile(e,t)&&r.includes(t.type)}checkMimes(e,t,r=[]){return!!this.checkFile(e,t)&&(r.includes("jpg")&&!r.includes("jpeg")&&r.push("jpeg"),r.includes("jpeg")&&!r.includes("jpg")&&r.push("jpg"),r.includes(t.name.split(".").pop().toLowerCase()))}checkExtensions(e,t,r){return this.checkMimes(e,t,r)}async checkImage(e,t,r=[]){const s=["jpg","jpeg","png","gif","bmp","webp"];r.includes("allow_svg")&&s.push("svg");let i=this.checkMimes(e,t,s);return i&&"undefined"!=typeof FileReader?(await new Promise((e,r)=>{const s=new FileReader;s.onload=t=>e(t.target.result),s.onerror=r,s.readAsDataURL(t)}).then(async t=>{const r=new Image;r.src=t,await r.decode(),this.#t[e]=r}).catch(()=>{i=!1}),i):i}async checkDimensions(e,t,r=[]){if(!await this.checkImage(e,t)||!Object.hasOwn(this.#t,e))return!1;const s={};for(const e of r){const[t,r]=e.split("=",2);if("ratio"===t&&r.includes("/")){const[e,i]=r.split("/",2).map(e=>parseFloat(e,10));s[t]=e/i}else s[t]=parseFloat(r,10)}const i=this.#t[e],c=i.naturalWidth,a=i.naturalHeight;return!(Object.hasOwn(s,"width")&&s.width!==c||Object.hasOwn(s,"height")&&s.height!==a||Object.hasOwn(s,"min_width")&&s.min_width>c||Object.hasOwn(s,"min_height")&&s.min_height>a||Object.hasOwn(s,"max_width")&&s.max_width<c||Object.hasOwn(s,"max_height")&&s.max_height<a)&&(!Object.hasOwn(s,"ratio")||Math.abs(s.ratio-c/a)<=1/(Math.max(c,a)+1))}checkEmail(e,t,r){if(!/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(t)){return/^((?:[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]|[^\u0000-\u007F])+@(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?(?:\.(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?)+)*$/.test(t)}return!0}checkJson(e,t,r){try{JSON.parse(t)}catch(e){return!1}return!0}checkHexColor(e,t,r){return/^#(?:(?:[0-9a-f]{3}){1,2}|(?:[0-9a-f]{4}){1,2})$/i.test(t)}checkMacAddress(e,t,r){t=String(t);const s={"-":2,":":2,".":4};let i,c;for([i,c]of Object.entries(s))if(t.includes(i))break;const a=t.split(i);if(a.length!==12/c)return!1;for(const e of a)if(!new RegExp("^[0-9a-f]{"+c+"}$","i").test(e))return!1;return!0}checkIpv4(e,t,r){if(/[^\d.]/.test(t))return!1;const s=String(t).split(".").map(e=>parseInt(e,10));if(4!==s.length)return!1;for(const e of s)if(isNaN(e)||e<0||e>255)return!1;return!0}checkIpv6(e,t,r){if((t=String(t)).includes(":::")||t.split("::").length>2)return!1;const s=t.split(":");if(s.length<3||s.length>8)return!1;for(const e of s)if(""!==e&&!/^[0-9a-f]{1,4}$/i.test(e))return!1;return!0}checkIp(e,t,r){return this.checkIpv4(e,t,r)||this.checkIpv6(e,t,r)}checkTimezone(e,t,r){try{Intl.DateTimeFormat(void 0,{timeZone:t})}catch(e){if(e instanceof RangeError)return!1}return!0}checkUrl(e,t,r){try{new URL(t)}catch(e){return!1}return!0}checkUlid(e,t,r){return/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/.test(t)}checkUuid(e,t,r){return/^[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}$/.test(t)}}class o{#r;keys(){return Object.keys(this.#r)}values(){return Object.values(this.#r)}entries(){return Object.entries(this.#r)}add(e,t){Object.hasOwn(this.#r,e)?this.#r[e].push(t):this.#r[e]=[t]}get(e){if(!e.includes("*"))return Object.hasOwn(this.#r,e)?this.#r[e]:{};const t=new RegExp("^"+e.replaceAll("*",".*?")+"$"),r={};for(const[e,s]of this.entries())t.test(e)&&(r[e]=s);return r}first(e){for(const t of Object.values(this.get(e)))return Array.isArray(t)?t[0]:t;return""}has(e){return""!==this.first(e)}remove(e){delete this.#r[e]}messages(){return this.#r}all(){const e=[];return this.values().forEach(t=>e.push(...t)),e}count(){let e=0;return this.values().forEach(t=>e+=t.length),e}isEmpty(){return 0===this.keys().length}isNotEmpty(){return!this.isEmpty()}sortByKeys(e){const t={};for(const r of e)Object.hasOwn(this.#r,r)&&(t[r]=this.#r[r]);this.#r=t}constructor(){this.#r={}}}class p{static#s;static#i={};static locale(e){this.#s=e}static setMessages(e,t){this.#i[e]=s(t)}static get(e){if(this.#i[this.#s]&&this.#i[this.#s][e])return this.#i[this.#s][e]}static has(e){return void 0!==this.get(e)}static set(e,t){l(t)?Object.assign(this.#i[this.#s],s(t,e)):"string"==typeof t&&(this.#i[this.#s][e]=t)}}class d{constructor(e){this.validator=e}replace(e,t){return Object.entries(t).forEach(([t,r])=>e=e.replaceAll(":"+t,r)),e}replaceCaseVariants(e,t){return Object.entries(t).flatMap(([e,t])=>[[e,t],[e.toLocaleUpperCase(),t.toLocaleUpperCase()],[e.charAt(0).toLocaleUpperCase()+e.substring(1),t.charAt(0).toLocaleUpperCase()+t.substring(1)]]).forEach(([t,r])=>e=e.replaceAll(":"+t,r)),e}replaceDecimal(e,t,r,s){return this.replace(e,{decimal:s.join("-")})}replaceMultipleOf(e,t,r,s){return this.replace(e,{value:s[0]})}replaceAcceptedIf(e,t,r,s){return this.replaceCaseVariants(e,{other:this.validator.getDisplayableAttribute(s[0]),value:this.validator.getDisplayableValue(s[0],this.validator.getValue(s[0]))})}replaceDeclinedIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredArrayKeys(e,t,r,s){return this.replace(e,{values:s.map(e=>this.validator.getDisplayableValue(t,e)).join(", ")})}replaceRequiredIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredIfAccepted(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredIfDeclined(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredUnless(e,t,r,s){return this.replaceCaseVariants(e,{other:this.validator.getDisplayableAttribute(s[0]),values:s.slice(1).map(e=>this.validator.getDisplayableValue(s[0],e)).join(", ")})}replaceRequiredWith(e,t,r,s){return this.replaceCaseVariants(e,{values:s.map(e=>this.validator.getDisplayableAttribute(e)).join(" / ")})}replaceRequiredWithAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceRequiredWithout(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceRequiredWithoutAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replacePresentIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replacePresentUnless(e,t,r,s){return this.replaceCaseVariants(this.replaceRequiredUnless(e,t,r,s),{value:this.validator.getDisplayableValue(s[0],s[1])})}replacePresentWith(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replacePresentWithAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceMissingIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceMissingUnless(e,t,r,s){return this.replacePresentUnless(e,t,r,s)}replaceMissingWith(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceMissingWithAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceProhibitedIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceProhibitedUnless(e,t,r,s){return this.replaceRequiredUnless(e,t,r,s)}replaceProhibits(e,t,r,s){return this.replaceCaseVariants(e,{other:s.map(e=>this.validator.getDisplayableAttribute(e)).join(" / ")})}replaceSize(e,t,r,s){return this.replace(e,{size:s[0]})}replaceMin(e,t,r,s){return this.replace(e,{min:s[0]})}replaceMax(e,t,r,s){return this.replace(e,{max:s[0]})}replaceBetween(e,t,r,s){return this.replace(e,{min:s[0],max:s[1]})}replaceDigits(e,t,r,s){return this.replace(e,{digits:s[0]})}replaceMinDigits(e,t,r,s){return this.replaceMin(e,t,r,s)}replaceMaxDigits(e,t,r,s){return this.replaceMax(e,t,r,s)}replaceDigitsBetween(e,t,r,s){return this.replaceBetween(e,t,r,s)}replaceStartsWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceDoesntStartWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceEndsWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceDoesntEndWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceSame(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceDifferent(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceGt(e,t,r,s){const i=this.validator.getValue(s[0]);return this.replace(e,{value:i?this.validator.getSize(s[0],i):this.validator.getDisplayableAttribute(s[0])})}replaceGte(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceLt(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceLte(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceAfter(e,t,r,s){const i=s[0];return this.replace(e,{date:this.validator.hasAttribute(i)?this.validator.getDisplayableAttribute(i):i})}replaceAfterOrEqual(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceBefore(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceBeforeOrEqual(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceDateEquals(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceDateFormat(e,t,r,s){return this.replace(e,{format:s[0]})}replaceInArray(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceIn(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceNotIn(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceDoesntContain(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceMimetypes(e,t,r,s){return this.replace(e,{values:s.join(", ")})}replaceMimes(e,t,r,s){return this.replaceMimetypes(e,t,r,s)}replaceExtensions(e,t,r,s){return this.replaceMimetypes(e,t,r,s)}}class f{static#c={};static#a={};static#n=["active_url","bail","can","current_password","encoding","enum","exclude","exclude_if","exclude_unless","exclude_with","exclude_without","exists","nullable","sometimes","unique"];static#l=["accepted","accepted_if","declined","declined_if","filled","missing","missing_if","missing_unless","missing_with","missing_with_all","present","present_if","present_unless","present_with","present_with_all","required","required_if","required_if_accepted","required_if_declined","required_unless","required_with","required_with_all","required_without","required_without_all"];#r;#u;#h;#o;#p;#d;#f;#g;#m;#k;#A;#y;static setLocale(e){p.locale(e)}static setMessages(e,t){p.setMessages(e,t)}static addChecker(e,t,r){f.#c[e]=t,r&&p.set(e,r)}static addImplicitChecker(e,t,r){f.addChecker(e,t,r),f.#l.push(e)}static addReplacer(e,t){f.#a[e]=t}static addDummyRule(e){f.#n.push(e)}constructor(e={},r={},s={},i={},c={}){this.#m=[],this.#k={},this.#A=!1,this.#y=!1,this.arrayRules=["array","list"],this.fileRules=["file","image","mimetypes","mimes"],this.stringRules=["string","alpha","alpha_dash","alpha_num","ascii","email"],this.numericRules=["decimal","numeric","integer"],this.sizeRules=["size","between","min","max","gt","lt","gte","lte"],this.setProperties(e,r,s,i,c),this.#d=new h(this),this.#f=new d(this);for(const[e,r]of Object.entries(f.#c))this.#d[t("check_"+e)]=r;for(const[e,r]of Object.entries(f.#a))this.#f[t("replace_"+e)]=r;this.#g=new o}setProperties(e={},t={},r={},i={},c={}){return this.#r=e,this.#u=this.parseRules(t),this.#h=r,this.#o=i,this.#p=s(c),this}setData(e){return this.#r=e,this}setRules(e){return this.#u=this.parseRules(e),this}setCustomMessages(e){return this.#h=e,this}setCustomAttributes(e){return this.#o=e,this}setCustomValues(e){return this.#p=s(e),this}addImplicitAttribute(e,t){return this.#k[e]=t,this}stopOnFirstFailure(e=!0){return this.#A=e,this}alwaysBail(e=!0){return this.#y=e,this}parseRules(e){const t={};for(const[r,s]of Object.entries(e)){const e=r.includes("*")?this.parseWildcardAttribute(r):[r];for(const r of e){const e=[];for(const t of this.parseAttributeRules(s))e.push(this.parseAttributeRule(t));t[r]=e}}return t}parseWildcardAttribute(e){const t=[],r=e.indexOf("*"),s=e.substring(0,r-1),i=e.substring(r+2),c=this.getValue(s);return Array.isArray(c)||l(c)?(Object.entries(c).forEach(([r,c])=>{const a=`${s}.${r}.${i}`.replace(/\.$/,""),n=a.includes("*")?this.parseWildcardAttribute(a):[a];t.push(...n),n.forEach(t=>this.#k[t]=e)}),t):[e]}parseAttributeRules(e){return Array.isArray(e)?e:"function"==typeof e?[e]:String(e).split("|")}parseAttributeRule(e){if("function"==typeof e)return[e,[]];let t,r;if(Array.isArray(e))t=e[0]??"",r=e.slice(1);else{const s=e.indexOf(":");-1===s?(t=e,r=[]):(t=e.substring(0,s),r=function(e){const t=[];let r="",s=!1;for(let i=0;i<e.length;i++){const c=e[i];'"'===c?s&&'"'===e[i+1]?(r+='"',i++):(s=!s,s&&(r=r.trim())):","!==c||s?r+=c:(t.push(r),r="")}return t.push(r),t}(e.substring(s+1)))}return[this.normalizeRuleName(t),r]}normalizeRuleName(e){return{int:"integer",bool:"boolean"}[e]??e}async validate(){this.#d.clearCaches(),this.#g=new o;const e=[],r=new Set;for(const[e,r]of Object.entries(this.#u))for(const[e]of r)if(""!==e&&"function"!=typeof e&&"function"!=typeof this.#d[t("check_"+e)]&&!f.#n.includes(e))throw new Error(`Invalid validation rule: ${e}`);for(const[s,i]of Object.entries(this.#u)){let c=this.getValue(s);const n=e=>i.some(t=>t[0]===e);n("sometimes")&&void 0===c?r.add(s):e.push(async()=>{const e=this.#y||n("bail"),l=n("nullable");let u=!0;for(const[n,h]of i){if(""===n||"function"!=typeof n&&!f.#l.includes(n)&&(void 0===c||"string"==typeof c&&""===c.trim()||l&&null===c)){r.add(s);continue}let i,o,p;const d=(()=>{if("function"==typeof n)return n;{const e=this.#d[t("check_"+n)]??null;return null===e&&f.#n.includes(n)?()=>!0:e}})();if(null===d)throw new Error(`Invalid validation rule: ${n}`);if(i=await d.call(this.#d,s,c,h),"boolean"==typeof i&&(i={success:i}),({success:o,message:p=""}=i),!o&&(u=!1,p=a(p)?this.getMessage(s,n):p,p=this.makeReplacements(p,s,n,h),this.#g.add(s,p),e||f.#l.includes(n)))break}return u})}if(this.#A){for(const t of e)if(!await t())break}else await Promise.allSettled(e.map(e=>e())).then(e=>{for(const t of e)if("rejected"===t.status)throw t.reason}),this.#g.sortByKeys(Object.keys(this.#u));return this.#m=[...r],this.#g}async passes(){return await this.validate(),!this.#g.isNotEmpty()}async fails(){return!await this.passes()}getMessage(e,t){if("function"==typeof t)return"";const r=this.getValue(e);let s;e=this.getPrimaryAttribute(e);for(const r of[`${e}.${t}`,t])if(Object.hasOwn(this.#h,r)){s=this.#h[r];break}if(!s){let i=t;this.sizeRules.includes(i)&&(Array.isArray(r)||l(r)||this.hasRule(e,this.arrayRules)?i+=".array":r instanceof File||this.hasRule(e,this.fileRules)?i+=".file":this.hasRule(e,this.stringRules)?i+=".string":n(r)||this.hasRule(e,this.numericRules)?i+=".numeric":i+=".string"),s=p.get(i)}return s??`validation.${t}`}makeReplacements(e,r,s,i){const c=this.getDisplayableAttribute(r),a=this.getValue(r),n={attribute:c,ATTRIBUTE:c.toLocaleUpperCase(),Attribute:c.charAt(0).toLocaleUpperCase()+c.substring(1),input:this.getDisplayableValue(r,a)};for(const[t,r]of Object.entries(n))e=e.replaceAll(":"+t,r);const l=r.match(/\.(\d+)\.?/),u=null===l?-1:parseInt(l[1],10);if(-1!==u&&(e=e.replaceAll(":index",u).replaceAll(":position",u+1)),"string"==typeof s){const c=this.#f[t("replace_"+s)]??null;c&&(e=c.call(this.#f,e,r,s,i))}return e}getDisplayableAttribute(e){const t=this.getPrimaryAttribute(e);for(const r of[e,t]){if(Object.hasOwn(this.#o,r))return this.#o[r];if(p.has(`attributes.${r}`))return p.get(`attributes.${r}`)}return Object.hasOwn(this.#k,e)?e:(r=e,r.replace(/(.)(?=[A-Z])/g,e=>e+"_").toLowerCase()).replaceAll("_"," ");var r}getDisplayableValue(e,t){const r=`${e=this.getPrimaryAttribute(e)}.${t}`;return Object.hasOwn(this.#p,r)?this.#p[r]:p.has(`values.${r}`)?p.get(`values.${r}`):a(t)?"empty":Array.isArray(t)?"array":"boolean"==typeof t||this.hasRule(e,"boolean")?Number(t)?"true":"false":t}getSize(e,t){return a(t)?0:this.hasRule(e,this.stringRules)?String(t).length:n(t)&&this.hasRule(e,this.numericRules)?parseFloat("string"==typeof t?t.trim():t,10):t instanceof File?t.size/1024:l(t)?Object.keys(t).length:Object.hasOwn(t,"length")?t.length:t}getRule(e){return e=this.getPrimaryAttribute(e),this.#u[e]??[]}hasRule(e,t){if(e=this.getPrimaryAttribute(e),t="string"==typeof t?[t]:t,!Object.hasOwn(this.#u,e))return!1;for(const r of t)if(this.#u[e].some(e=>e[0]===r))return!0;return!1}getPrimaryAttribute(e){return Object.hasOwn(this.#k,e)?this.#k[e]:e}hasAttribute(e){return void 0!==this.getValue(e)}getValue(e){return function(e,t,r){const s=t.split(".");let i=e;for(const e of s){if(null==i||!Object.hasOwn(i,e))return r;i=i[e]}return i}(this.#r,e)}errors(){return this.#g}skippedAttributes(){return this.#m}}return e.Checkers=h,e.ErrorBag=o,e.Lang=p,e.Replacers=d,e.Validator=f,e}({});
|
package/package.json
CHANGED
package/src/Checkers.js
CHANGED
|
@@ -35,6 +35,20 @@ export default class Checkers {
|
|
|
35
35
|
return true;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
collectPresentsThenTest(attribute, value, parameters, callback) {
|
|
39
|
+
let result = [];
|
|
40
|
+
|
|
41
|
+
for (const other of parameters) {
|
|
42
|
+
result.push(this.checkPresent(other, this.validator.getValue(other)));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (callback(result)) {
|
|
46
|
+
return this.checkPresent(attribute, value);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
|
|
38
52
|
collectMissingsThenTest(attribute, value, parameters, callback) {
|
|
39
53
|
let result = [];
|
|
40
54
|
|
|
@@ -89,9 +103,11 @@ export default class Checkers {
|
|
|
89
103
|
}
|
|
90
104
|
|
|
91
105
|
compareDates(attribute, value, parameters, callback) {
|
|
92
|
-
const
|
|
106
|
+
const rules = this.validator.getRule(attribute);
|
|
107
|
+
const dateFormatRule = Array.isArray(rules) ? rules.find(([name]) => name === 'date_format') : null;
|
|
108
|
+
const format = dateFormatRule ? dateFormatRule[1][0] : null;
|
|
93
109
|
|
|
94
|
-
value =
|
|
110
|
+
value = format ? parseDateByFormat(value, format) : parseDate(value);
|
|
95
111
|
|
|
96
112
|
if (!isValidDate(value)) {
|
|
97
113
|
return false;
|
|
@@ -101,11 +117,13 @@ export default class Checkers {
|
|
|
101
117
|
let otherValue = this.validator.getValue(other);
|
|
102
118
|
|
|
103
119
|
if (typeof otherValue === 'undefined') {
|
|
104
|
-
otherValue = parseDate(other);
|
|
120
|
+
otherValue = format ? parseDateByFormat(other, format) : parseDate(other);
|
|
105
121
|
} else {
|
|
106
|
-
const
|
|
122
|
+
const otherRules = this.validator.getRule(other);
|
|
123
|
+
const otherDateFormatRule = Array.isArray(otherRules) ? otherRules.find(([name]) => name === 'date_format') : null;
|
|
124
|
+
const otherFormat = otherDateFormatRule ? otherDateFormatRule[1][0] : null;
|
|
107
125
|
|
|
108
|
-
otherValue =
|
|
126
|
+
otherValue = otherFormat ? parseDateByFormat(otherValue, otherFormat) : parseDate(otherValue);
|
|
109
127
|
}
|
|
110
128
|
|
|
111
129
|
if (!isValidDate(otherValue)) {
|
|
@@ -322,6 +340,30 @@ export default class Checkers {
|
|
|
322
340
|
return typeof value !== 'undefined';
|
|
323
341
|
}
|
|
324
342
|
|
|
343
|
+
checkPresentIf(attribute, value, parameters) {
|
|
344
|
+
if (this.isDependent(parameters)) {
|
|
345
|
+
return this.checkPresent(attribute, value);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
checkPresentUnless(attribute, value, parameters) {
|
|
352
|
+
if (!this.isDependent(parameters)) {
|
|
353
|
+
return this.checkPresent(attribute, value);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
checkPresentWith(attribute, value, parameters) {
|
|
360
|
+
return this.collectPresentsThenTest(attribute, value, parameters, (result) => result.includes(true));
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
checkPresentWithAll(attribute, value, parameters) {
|
|
364
|
+
return this.collectPresentsThenTest(attribute, value, parameters, (result) => !result.includes(false));
|
|
365
|
+
}
|
|
366
|
+
|
|
325
367
|
// Missing
|
|
326
368
|
checkMissing(attribute, value, parameters) {
|
|
327
369
|
return typeof value === 'undefined';
|
|
@@ -877,14 +919,16 @@ export default class Checkers {
|
|
|
877
919
|
return false;
|
|
878
920
|
}
|
|
879
921
|
|
|
880
|
-
const blocks = String(value)
|
|
922
|
+
const blocks = String(value)
|
|
923
|
+
.split('.')
|
|
924
|
+
.map((block) => parseInt(block, 10));
|
|
881
925
|
|
|
882
926
|
if (blocks.length !== 4) {
|
|
883
927
|
return false;
|
|
884
928
|
}
|
|
885
929
|
|
|
886
930
|
for (const block of blocks) {
|
|
887
|
-
if (block < 0 || block > 255) {
|
|
931
|
+
if (isNaN(block) || block < 0 || block > 255) {
|
|
888
932
|
return false;
|
|
889
933
|
}
|
|
890
934
|
}
|
|
@@ -941,10 +985,10 @@ export default class Checkers {
|
|
|
941
985
|
}
|
|
942
986
|
|
|
943
987
|
checkUlid(attribute, value, parameters) {
|
|
944
|
-
return
|
|
988
|
+
return /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/.test(value);
|
|
945
989
|
}
|
|
946
990
|
|
|
947
991
|
checkUuid(attribute, value, parameters) {
|
|
948
|
-
return
|
|
992
|
+
return /^[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}$/.test(value);
|
|
949
993
|
}
|
|
950
994
|
}
|
package/src/Replacers.js
CHANGED
|
@@ -95,17 +95,34 @@ export default class Replacers {
|
|
|
95
95
|
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
//
|
|
99
|
-
|
|
98
|
+
// Present
|
|
99
|
+
replacePresentIf(message, attribute, rule, parameters) {
|
|
100
100
|
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
replacePresentUnless(message, attribute, rule, parameters) {
|
|
104
104
|
return this.replaceCaseVariants(this.replaceRequiredUnless(message, attribute, rule, parameters), {
|
|
105
105
|
value: this.validator.getDisplayableValue(parameters[0], parameters[1]),
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
replacePresentWith(message, attribute, rule, parameters) {
|
|
110
|
+
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
replacePresentWithAll(message, attribute, rule, parameters) {
|
|
114
|
+
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Missing
|
|
118
|
+
replaceMissingIf(message, attribute, rule, parameters) {
|
|
119
|
+
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
replaceMissingUnless(message, attribute, rule, parameters) {
|
|
123
|
+
return this.replacePresentUnless(message, attribute, rule, parameters);
|
|
124
|
+
}
|
|
125
|
+
|
|
109
126
|
replaceMissingWith(message, attribute, rule, parameters) {
|
|
110
127
|
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
111
128
|
}
|
package/src/Validator.js
CHANGED
|
@@ -38,6 +38,10 @@ export default class Validator {
|
|
|
38
38
|
'missing_with',
|
|
39
39
|
'missing_with_all',
|
|
40
40
|
'present',
|
|
41
|
+
'present_if',
|
|
42
|
+
'present_unless',
|
|
43
|
+
'present_with',
|
|
44
|
+
'present_with_all',
|
|
41
45
|
'required',
|
|
42
46
|
'required_if',
|
|
43
47
|
'required_if_accepted',
|
|
@@ -483,14 +487,18 @@ export default class Validator {
|
|
|
483
487
|
|
|
484
488
|
const path = `${attribute}.${value}`;
|
|
485
489
|
|
|
490
|
+
if (Object.hasOwn(this.#customValues, path)) {
|
|
491
|
+
return this.#customValues[path];
|
|
492
|
+
} else if (Lang.has(`values.${path}`)) {
|
|
493
|
+
return Lang.get(`values.${path}`);
|
|
494
|
+
}
|
|
495
|
+
|
|
486
496
|
if (isEmpty(value)) {
|
|
487
497
|
return 'empty';
|
|
498
|
+
} else if (Array.isArray(value)) {
|
|
499
|
+
return 'array';
|
|
488
500
|
} else if (typeof value === 'boolean' || this.hasRule(attribute, 'boolean')) {
|
|
489
501
|
return Number(value) ? 'true' : 'false';
|
|
490
|
-
} else if (Object.hasOwn(this.#customValues, path)) {
|
|
491
|
-
return this.#customValues[path];
|
|
492
|
-
} else if (Lang.has(`values.${path}`)) {
|
|
493
|
-
return Lang.get(`values.${path}`);
|
|
494
502
|
}
|
|
495
503
|
|
|
496
504
|
return value;
|
|
@@ -517,7 +525,7 @@ export default class Validator {
|
|
|
517
525
|
getRule(attribute) {
|
|
518
526
|
attribute = this.getPrimaryAttribute(attribute);
|
|
519
527
|
|
|
520
|
-
return this.#rules[attribute] ??
|
|
528
|
+
return this.#rules[attribute] ?? [];
|
|
521
529
|
}
|
|
522
530
|
|
|
523
531
|
hasRule(attribute, rules) {
|
package/src/helpers.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function toCamelCase(string) {
|
|
2
2
|
return string
|
|
3
3
|
.replace(/[-_]/g, ' ')
|
|
4
|
-
.replace(/\s
|
|
4
|
+
.replace(/\s+/g, ' ')
|
|
5
5
|
.trim()
|
|
6
6
|
.replace(/(\s\w)/g, (match) => match[1].toUpperCase());
|
|
7
7
|
}
|
|
@@ -19,7 +19,7 @@ export function getByPath(obj, path, defaultValue) {
|
|
|
19
19
|
let current = obj;
|
|
20
20
|
|
|
21
21
|
for (const key of keys) {
|
|
22
|
-
if (!Object.hasOwn(current, key)) {
|
|
22
|
+
if (current === null || current === undefined || !Object.hasOwn(current, key)) {
|
|
23
23
|
return defaultValue;
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -41,7 +41,7 @@ export function setByPath(obj, path, value) {
|
|
|
41
41
|
current = current[key];
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
current[keys.
|
|
44
|
+
current[keys.at(-1)] = value;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export function flattenObject(obj, prefix = '') {
|
|
@@ -91,10 +91,10 @@ export function parseCsvString(value) {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
export function parseDate(value) {
|
|
94
|
-
if (
|
|
95
|
-
return new Date('');
|
|
96
|
-
} else if (value instanceof Date) {
|
|
94
|
+
if (value instanceof Date) {
|
|
97
95
|
return value;
|
|
96
|
+
} else if (isEmpty(value) || typeof value !== 'string') {
|
|
97
|
+
return new Date('');
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
let match, years, months, days, hours, minutes, seconds, meridiem;
|
|
@@ -128,8 +128,12 @@ export function parseDate(value) {
|
|
|
128
128
|
years += 2000;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
meridiem = meridiem.toLowerCase();
|
|
132
|
+
|
|
133
|
+
if (meridiem === 'pm' && hours < 12) {
|
|
132
134
|
hours += 12;
|
|
135
|
+
} else if (meridiem === 'am' && hours === 12) {
|
|
136
|
+
hours = 0;
|
|
133
137
|
}
|
|
134
138
|
|
|
135
139
|
return new Date(`${years}-${months}-${days} ${hours}:${minutes}:${seconds}`);
|
|
@@ -235,8 +239,12 @@ export function parseDateByFormat(value, format) {
|
|
|
235
239
|
years = years + 2000;
|
|
236
240
|
}
|
|
237
241
|
|
|
238
|
-
|
|
242
|
+
meridiem = meridiem.toLowerCase();
|
|
243
|
+
|
|
244
|
+
if (meridiem === 'pm' && hours < 12) {
|
|
239
245
|
hours += 12;
|
|
246
|
+
} else if (meridiem === 'am' && hours === 12) {
|
|
247
|
+
hours = 0;
|
|
240
248
|
}
|
|
241
249
|
|
|
242
250
|
return new Date(`${years}-${months}-${days} ${hours}:${minutes}:${seconds}`);
|
package/src/locales/en.js
CHANGED
|
@@ -116,6 +116,10 @@ export default {
|
|
|
116
116
|
uncompromised: 'The given :attribute has appeared in a data leak. Please choose a different :attribute.',
|
|
117
117
|
},
|
|
118
118
|
present: 'The :attribute field must be present.',
|
|
119
|
+
present_if: 'The :attribute field must be present when :other is :value.',
|
|
120
|
+
present_unless: 'The :attribute field must be present unless :other is :value.',
|
|
121
|
+
present_with: 'The :attribute field must be present when :values is present.',
|
|
122
|
+
present_with_all: 'The :attribute field must be present when :values are present.',
|
|
119
123
|
prohibited: 'The :attribute field is prohibited.',
|
|
120
124
|
prohibited_if: 'The :attribute field is prohibited when :other is :value.',
|
|
121
125
|
prohibited_unless: 'The :attribute field is prohibited unless :other is in :values.',
|
package/src/locales/ms.js
CHANGED
|
@@ -116,6 +116,10 @@ export default {
|
|
|
116
116
|
uncompromised: 'Nilai :attribute yang diberikan telah muncul dalam kebocoran data. Sila pilih :attribute yang berbeza.',
|
|
117
117
|
},
|
|
118
118
|
present: 'Medan :attribute mesti wujud.',
|
|
119
|
+
present_if: 'Medan :attribute mesti wujud apabila :other adalah :value.',
|
|
120
|
+
present_unless: 'Medan :attribute mesti wujud melainkan :other adalah :value.',
|
|
121
|
+
present_with: 'Medan :attribute mesti wujud apabila :values wujud.',
|
|
122
|
+
present_with_all: 'Medan :attribute mesti wujud apabila :values wujud.',
|
|
119
123
|
prohibited: 'Medan :attribute dilarang.',
|
|
120
124
|
prohibited_if: 'Medan :attribute dilarang apabila :other adalah :value.',
|
|
121
125
|
prohibited_unless: 'Medan :attribute dilarang melainkan :other berada dalam :values.',
|
package/test/helpers.js
CHANGED
|
@@ -24,6 +24,9 @@ describe('Helpers', () => {
|
|
|
24
24
|
assert.equal(toCamelCase('-test-name'), 'testName');
|
|
25
25
|
assert.equal(toCamelCase('a test name'), 'aTestName');
|
|
26
26
|
assert.equal(toCamelCase(' test name'), 'testName');
|
|
27
|
+
assert.equal(toCamelCase('a__test__name'), 'aTestName');
|
|
28
|
+
assert.equal(toCamelCase('a--test--name'), 'aTestName');
|
|
29
|
+
assert.equal(toCamelCase('a___test___name'), 'aTestName');
|
|
27
30
|
});
|
|
28
31
|
|
|
29
32
|
it('toSnakeCase', () => {
|
|
@@ -39,6 +42,9 @@ describe('Helpers', () => {
|
|
|
39
42
|
it('getByPath', () => {
|
|
40
43
|
assert.equal(getByPath({ a: { b: 1 } }, 'a.b'), 1);
|
|
41
44
|
assert.equal(getByPath({ a: [1, { c: 2 }] }, 'a.1.c'), 2);
|
|
45
|
+
assert.equal(getByPath({ a: null }, 'a.b'), undefined);
|
|
46
|
+
assert.equal(getByPath({ a: undefined }, 'a.b'), undefined);
|
|
47
|
+
assert.equal(getByPath({ a: null }, 'a.b', 'default'), 'default');
|
|
42
48
|
});
|
|
43
49
|
|
|
44
50
|
it('setByPath', () => {
|
|
@@ -51,6 +57,14 @@ describe('Helpers', () => {
|
|
|
51
57
|
setByPath(obj, 'a.1.c', 5);
|
|
52
58
|
|
|
53
59
|
assert.deepEqual(obj, { a: [1, { c: 5 }] });
|
|
60
|
+
|
|
61
|
+
obj = {};
|
|
62
|
+
setByPath(obj, 'x', 42);
|
|
63
|
+
assert.deepEqual(obj, { x: 42 });
|
|
64
|
+
|
|
65
|
+
obj = {};
|
|
66
|
+
setByPath(obj, 'a.b.c', 'deep');
|
|
67
|
+
assert.deepEqual(obj, { a: { b: { c: 'deep' } } });
|
|
54
68
|
});
|
|
55
69
|
|
|
56
70
|
it('flattenObject', () => {
|
|
@@ -81,6 +95,10 @@ describe('Helpers', () => {
|
|
|
81
95
|
date3.setSeconds(50);
|
|
82
96
|
date3.setMilliseconds(0);
|
|
83
97
|
|
|
98
|
+
assert.deepEqual(parseDate(date1), date1);
|
|
99
|
+
assert.deepEqual(parseDate(date2), date2);
|
|
100
|
+
assert.deepEqual(parseDate(date3), date3);
|
|
101
|
+
|
|
84
102
|
assert.deepEqual(parseDate('11-08-2023'), date1);
|
|
85
103
|
assert.deepEqual(parseDate('11-08-2023 08:40:50'), date2);
|
|
86
104
|
assert.deepEqual(parseDate('11-08-2023 08:40:50 am'), date2);
|
|
@@ -114,6 +132,11 @@ describe('Helpers', () => {
|
|
|
114
132
|
assert.deepEqual(parseDate('08:40:50 am'), date3);
|
|
115
133
|
assert.deepEqual(parseDate('08:40:50'), date3);
|
|
116
134
|
assert.deepEqual(parseDate('08:40:50 am'), date3);
|
|
135
|
+
|
|
136
|
+
const date4 = new Date('2023/08/11 00:30:00');
|
|
137
|
+
assert.deepEqual(parseDate('2023-08-11 12:30:00 am'), date4);
|
|
138
|
+
assert.deepEqual(parseDate('11-08-2023 12:30:00 am'), date4);
|
|
139
|
+
assert.deepEqual(parseDate('12:30:00 am 2023-08-11'), date4);
|
|
117
140
|
});
|
|
118
141
|
|
|
119
142
|
it('parseDateByFormat', () => {
|
|
@@ -131,6 +154,9 @@ describe('Helpers', () => {
|
|
|
131
154
|
assert.deepEqual(parseDateByFormat('08-11-23 08:40:50', 'm-d-y H:i:s'), date2);
|
|
132
155
|
assert.deepEqual(parseDateByFormat('08-11-2023 08:40:50 am', 'm-d-Y H:i:s a'), date2);
|
|
133
156
|
assert.deepEqual(parseDateByFormat('08-11-23 08:40:50 am', 'm-d-y H:i:s a'), date2);
|
|
157
|
+
|
|
158
|
+
const date4 = new Date('2023/08/11 00:30:00');
|
|
159
|
+
assert.deepEqual(parseDateByFormat('08-11-2023 12:30:00 am', 'm-d-Y H:i:s a'), date4);
|
|
134
160
|
});
|
|
135
161
|
|
|
136
162
|
it('isDigits', () => {
|
package/test/validation.js
CHANGED
|
@@ -190,6 +190,14 @@ describe('Validation', () => {
|
|
|
190
190
|
const validator = new Validator({ field: '2021-12-31', date }, rules2);
|
|
191
191
|
assert(await validator.fails());
|
|
192
192
|
});
|
|
193
|
+
|
|
194
|
+
it(`Passes when using date_format with after rule`, async () => {
|
|
195
|
+
const validator = new Validator({ field: '06/15/2022' }, { field: 'date_format:m/d/Y|after:06/01/2022' });
|
|
196
|
+
assert(await validator.passes());
|
|
197
|
+
|
|
198
|
+
validator.setData({ field: '05/30/2022' });
|
|
199
|
+
assert(await validator.fails());
|
|
200
|
+
});
|
|
193
201
|
});
|
|
194
202
|
|
|
195
203
|
describe(`Rule 'after_or_equal'`, () => {
|
|
@@ -226,6 +234,17 @@ describe('Validation', () => {
|
|
|
226
234
|
const validator = new Validator({ field: '2021-12-31', date }, rules2);
|
|
227
235
|
assert(await validator.fails());
|
|
228
236
|
});
|
|
237
|
+
|
|
238
|
+
it(`Passes when using date_format with after_or_equal rule`, async () => {
|
|
239
|
+
const validator = new Validator({ field: '06/01/2022' }, { field: 'date_format:m/d/Y|after_or_equal:06/01/2022' });
|
|
240
|
+
assert(await validator.passes());
|
|
241
|
+
|
|
242
|
+
validator.setData({ field: '06/15/2022' });
|
|
243
|
+
assert(await validator.passes());
|
|
244
|
+
|
|
245
|
+
validator.setData({ field: '05/30/2022' });
|
|
246
|
+
assert(await validator.fails());
|
|
247
|
+
});
|
|
229
248
|
});
|
|
230
249
|
|
|
231
250
|
describe(`Rule 'alpha'`, () => {
|
|
@@ -391,6 +410,14 @@ describe('Validation', () => {
|
|
|
391
410
|
const validator = new Validator({ field: '2022-01-02', date }, rules2);
|
|
392
411
|
assert(await validator.fails());
|
|
393
412
|
});
|
|
413
|
+
|
|
414
|
+
it(`Passes when using date_format with before rule`, async () => {
|
|
415
|
+
const validator = new Validator({ field: '05/30/2022' }, { field: 'date_format:m/d/Y|before:06/01/2022' });
|
|
416
|
+
assert(await validator.passes());
|
|
417
|
+
|
|
418
|
+
validator.setData({ field: '06/15/2022' });
|
|
419
|
+
assert(await validator.fails());
|
|
420
|
+
});
|
|
394
421
|
});
|
|
395
422
|
|
|
396
423
|
describe(`Rule 'before_or_equal'`, () => {
|
|
@@ -427,6 +454,17 @@ describe('Validation', () => {
|
|
|
427
454
|
const validator = new Validator({ field: '2022-01-02', date }, rules2);
|
|
428
455
|
assert(await validator.fails());
|
|
429
456
|
});
|
|
457
|
+
|
|
458
|
+
it(`Passes when using date_format with before_or_equal rule`, async () => {
|
|
459
|
+
const validator = new Validator({ field: '06/01/2022' }, { field: 'date_format:m/d/Y|before_or_equal:06/01/2022' });
|
|
460
|
+
assert(await validator.passes());
|
|
461
|
+
|
|
462
|
+
validator.setData({ field: '05/30/2022' });
|
|
463
|
+
assert(await validator.passes());
|
|
464
|
+
|
|
465
|
+
validator.setData({ field: '06/15/2022' });
|
|
466
|
+
assert(await validator.fails());
|
|
467
|
+
});
|
|
430
468
|
});
|
|
431
469
|
|
|
432
470
|
describe(`Rule 'between'`, () => {
|
|
@@ -636,6 +674,17 @@ describe('Validation', () => {
|
|
|
636
674
|
const validator = new Validator({ field: '2021-12-31', date }, rules2);
|
|
637
675
|
assert(await validator.fails());
|
|
638
676
|
});
|
|
677
|
+
|
|
678
|
+
it(`Passes when using date_format with date_equals rule`, async () => {
|
|
679
|
+
const validator = new Validator({ field: '06/01/2022' }, { field: 'date_format:m/d/Y|date_equals:06/01/2022' });
|
|
680
|
+
assert(await validator.passes());
|
|
681
|
+
|
|
682
|
+
validator.setData({ field: '06/15/2022' });
|
|
683
|
+
assert(await validator.fails());
|
|
684
|
+
|
|
685
|
+
validator.setData({ field: '05/30/2022' });
|
|
686
|
+
assert(await validator.fails());
|
|
687
|
+
});
|
|
639
688
|
});
|
|
640
689
|
|
|
641
690
|
describe(`Rule 'date_format'`, () => {
|
|
@@ -1493,6 +1542,25 @@ describe('Validation', () => {
|
|
|
1493
1542
|
validator.setData({ field: '2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF' });
|
|
1494
1543
|
assert(await validator.fails());
|
|
1495
1544
|
});
|
|
1545
|
+
|
|
1546
|
+
it(`Fails when the field has empty blocks from consecutive dots`, async () => {
|
|
1547
|
+
let validator = new Validator({ field: '1...1' }, rules);
|
|
1548
|
+
assert(await validator.fails());
|
|
1549
|
+
|
|
1550
|
+
validator = new Validator({ field: '192..168.1' }, rules);
|
|
1551
|
+
assert(await validator.fails());
|
|
1552
|
+
|
|
1553
|
+
validator = new Validator({ field: '...' }, rules);
|
|
1554
|
+
assert(await validator.fails());
|
|
1555
|
+
});
|
|
1556
|
+
|
|
1557
|
+
it(`Fails when the field has leading or trailing dots`, async () => {
|
|
1558
|
+
let validator = new Validator({ field: '.1.2.3.4' }, rules);
|
|
1559
|
+
assert(await validator.fails());
|
|
1560
|
+
|
|
1561
|
+
validator = new Validator({ field: '1.2.3.4.' }, rules);
|
|
1562
|
+
assert(await validator.fails());
|
|
1563
|
+
});
|
|
1496
1564
|
});
|
|
1497
1565
|
|
|
1498
1566
|
describe(`Rule 'ipv6'`, () => {
|
|
@@ -2354,6 +2422,162 @@ describe('Validation', () => {
|
|
|
2354
2422
|
});
|
|
2355
2423
|
});
|
|
2356
2424
|
|
|
2425
|
+
describe(`Rule 'present_if'`, () => {
|
|
2426
|
+
const rules = { field: 'present_if:other,foo,bar' };
|
|
2427
|
+
|
|
2428
|
+
it(`Passes when the field is present and the other field's value is equal to the first value`, async () => {
|
|
2429
|
+
const validator = new Validator({ field: '', other: 'foo' }, rules);
|
|
2430
|
+
assert(await validator.passes());
|
|
2431
|
+
});
|
|
2432
|
+
|
|
2433
|
+
it(`Passes when the field is present and the other field's value is equal to the second value`, async () => {
|
|
2434
|
+
const validator = new Validator({ field: '', other: 'bar' }, rules);
|
|
2435
|
+
assert(await validator.passes());
|
|
2436
|
+
});
|
|
2437
|
+
|
|
2438
|
+
it(`Passes when the field is not present and the other field's value is not equal to any value`, async () => {
|
|
2439
|
+
const validator = new Validator({ other: 'bob' }, rules);
|
|
2440
|
+
assert(await validator.passes());
|
|
2441
|
+
});
|
|
2442
|
+
|
|
2443
|
+
it(`Passes when the field is present and the other field's value is not equal to any value`, async () => {
|
|
2444
|
+
const validator = new Validator({ field: '', other: 'bob' }, rules);
|
|
2445
|
+
assert(await validator.passes());
|
|
2446
|
+
});
|
|
2447
|
+
|
|
2448
|
+
it(`Fails when the field is not present and the other field's value is equal to any value`, async () => {
|
|
2449
|
+
const validator = new Validator({ other: 'foo' }, rules);
|
|
2450
|
+
assert(await validator.fails());
|
|
2451
|
+
});
|
|
2452
|
+
|
|
2453
|
+
const rules2 = { field: ['present_if:other1,foo,bar', 'present_if:other2,win,amp'] };
|
|
2454
|
+
|
|
2455
|
+
it(`Passes when the field is not present and other fields' value are not equal to provided values`, async () => {
|
|
2456
|
+
const validator = new Validator({ other1: 'baz', other2: 'rar' }, rules2);
|
|
2457
|
+
assert(await validator.passes());
|
|
2458
|
+
});
|
|
2459
|
+
|
|
2460
|
+
it(`Fails when the field is not present and other fields' value are equal to provided values`, async () => {
|
|
2461
|
+
const validator = new Validator({ other1: 'foo', other2: 'win' }, rules2);
|
|
2462
|
+
assert(await validator.fails());
|
|
2463
|
+
});
|
|
2464
|
+
|
|
2465
|
+
it(`Fails when the field is not present and any other fields' value is equal to provided value`, async () => {
|
|
2466
|
+
const validator = new Validator({ other1: 'foo', other2: 'rar' }, rules2);
|
|
2467
|
+
assert(await validator.fails());
|
|
2468
|
+
|
|
2469
|
+
validator.setData({ other1: 'baz', other2: 'win' });
|
|
2470
|
+
assert(await validator.fails());
|
|
2471
|
+
});
|
|
2472
|
+
});
|
|
2473
|
+
|
|
2474
|
+
describe(`Rule 'present_unless'`, () => {
|
|
2475
|
+
const rules = { field: 'present_unless:other,foo,bar' };
|
|
2476
|
+
|
|
2477
|
+
it(`Passes when the field is not present and the other field's value is equal to the first value`, async () => {
|
|
2478
|
+
const validator = new Validator({ other: 'foo' }, rules);
|
|
2479
|
+
assert(await validator.passes());
|
|
2480
|
+
});
|
|
2481
|
+
|
|
2482
|
+
it(`Passes when the field is not present and the other field's value is equal to the second value`, async () => {
|
|
2483
|
+
const validator = new Validator({ other: 'bar' }, rules);
|
|
2484
|
+
assert(await validator.passes());
|
|
2485
|
+
});
|
|
2486
|
+
|
|
2487
|
+
it(`Passes when the field is present and the other field's value is not equal to any value`, async () => {
|
|
2488
|
+
const validator = new Validator({ field: '', other: 'bob' }, rules);
|
|
2489
|
+
assert(await validator.passes());
|
|
2490
|
+
});
|
|
2491
|
+
|
|
2492
|
+
it(`Fails when the field is not present and the other field's value is not equal to any value`, async () => {
|
|
2493
|
+
const validator = new Validator({ other: 'bob' }, rules);
|
|
2494
|
+
assert(await validator.fails());
|
|
2495
|
+
});
|
|
2496
|
+
|
|
2497
|
+
const rules2 = { field: ['present_unless:other1,foo,bar', 'present_unless:other2,win,amp'] };
|
|
2498
|
+
|
|
2499
|
+
it(`Passes when the field is not present and other fields' value are equal to provided values`, async () => {
|
|
2500
|
+
const validator = new Validator({ other1: 'foo', other2: 'win' }, rules2);
|
|
2501
|
+
assert(await validator.passes());
|
|
2502
|
+
});
|
|
2503
|
+
|
|
2504
|
+
it(`Fails when the field is not present and other fields' value are not equal to provided values`, async () => {
|
|
2505
|
+
const validator = new Validator({ other1: 'baz', other2: 'rar' }, rules2);
|
|
2506
|
+
assert(await validator.fails());
|
|
2507
|
+
});
|
|
2508
|
+
|
|
2509
|
+
it(`Fails when the field is not present and any other fields' value is not equal to provided value`, async () => {
|
|
2510
|
+
const validator = new Validator({ other1: 'foo', other2: 'rar' }, rules2);
|
|
2511
|
+
assert(await validator.fails());
|
|
2512
|
+
|
|
2513
|
+
validator.setData({ other1: 'baz', other2: 'win' });
|
|
2514
|
+
assert(await validator.fails());
|
|
2515
|
+
});
|
|
2516
|
+
});
|
|
2517
|
+
|
|
2518
|
+
describe(`Rule 'present_with'`, () => {
|
|
2519
|
+
const rules = { field: 'present_with:foo,bar' };
|
|
2520
|
+
|
|
2521
|
+
it(`Passes when the field is present and the first other field is present`, async () => {
|
|
2522
|
+
const validator = new Validator({ field: '', foo: 'abc' }, rules);
|
|
2523
|
+
assert(await validator.passes());
|
|
2524
|
+
});
|
|
2525
|
+
|
|
2526
|
+
it(`Passes when the field is present and the second other field is present`, async () => {
|
|
2527
|
+
const validator = new Validator({ field: '', bar: 123 }, rules);
|
|
2528
|
+
assert(await validator.passes());
|
|
2529
|
+
});
|
|
2530
|
+
|
|
2531
|
+
it(`Passes when the field is present and all other fields are not present`, async () => {
|
|
2532
|
+
const validator = new Validator({ field: '' }, rules);
|
|
2533
|
+
assert(await validator.passes());
|
|
2534
|
+
});
|
|
2535
|
+
|
|
2536
|
+
it(`Passes when the field is not present and all other fields are not present`, async () => {
|
|
2537
|
+
const validator = new Validator({}, rules);
|
|
2538
|
+
assert(await validator.passes());
|
|
2539
|
+
});
|
|
2540
|
+
|
|
2541
|
+
it(`Fails when the field is not present and the first other field is present`, async () => {
|
|
2542
|
+
const validator = new Validator({ foo: 'abc' }, rules);
|
|
2543
|
+
assert(await validator.fails());
|
|
2544
|
+
});
|
|
2545
|
+
|
|
2546
|
+
it(`Fails when the field is not present and the second other field is present`, async () => {
|
|
2547
|
+
const validator = new Validator({ bar: 123 }, rules);
|
|
2548
|
+
assert(await validator.fails());
|
|
2549
|
+
});
|
|
2550
|
+
});
|
|
2551
|
+
|
|
2552
|
+
describe(`Rule 'present_with_all'`, () => {
|
|
2553
|
+
const rules = { field: 'present_with_all:foo,bar' };
|
|
2554
|
+
|
|
2555
|
+
it(`Passes when the field is present and all other fields are present`, async () => {
|
|
2556
|
+
const validator = new Validator({ field: '', foo: 'abc', bar: 123 }, rules);
|
|
2557
|
+
assert(await validator.passes());
|
|
2558
|
+
});
|
|
2559
|
+
|
|
2560
|
+
it(`Passes when the field is present and any other field is present`, async () => {
|
|
2561
|
+
const validator = new Validator({ field: '', foo: 'abc' }, rules);
|
|
2562
|
+
assert(await validator.passes());
|
|
2563
|
+
});
|
|
2564
|
+
|
|
2565
|
+
it(`Passes when the field is not present and all other fields are not present`, async () => {
|
|
2566
|
+
const validator = new Validator({}, rules);
|
|
2567
|
+
assert(await validator.passes());
|
|
2568
|
+
});
|
|
2569
|
+
|
|
2570
|
+
it(`Passes when the field is not present and any other field is not present`, async () => {
|
|
2571
|
+
const validator = new Validator({ foo: 'abc' }, rules);
|
|
2572
|
+
assert(await validator.passes());
|
|
2573
|
+
});
|
|
2574
|
+
|
|
2575
|
+
it(`Fails when the field is not present and all other fields are present`, async () => {
|
|
2576
|
+
const validator = new Validator({ foo: 'abc', bar: 123 }, rules);
|
|
2577
|
+
assert(await validator.fails());
|
|
2578
|
+
});
|
|
2579
|
+
});
|
|
2580
|
+
|
|
2357
2581
|
describe(`Rule 'prohibited'`, () => {
|
|
2358
2582
|
const rules = { field: 'prohibited' };
|
|
2359
2583
|
|
|
@@ -3065,6 +3289,17 @@ describe('Validation', () => {
|
|
|
3065
3289
|
const validator = new Validator({ field: '01GZPCVRPR6K3KOW5B9ESB8PH3' }, rules);
|
|
3066
3290
|
assert(await validator.fails());
|
|
3067
3291
|
});
|
|
3292
|
+
|
|
3293
|
+
it(`Fails when the field contains a valid ULID with extra characters`, async () => {
|
|
3294
|
+
let validator = new Validator({ field: 'xxx01GZPCVRPR6K3KQW5B9ESB8PH3' }, rules);
|
|
3295
|
+
assert(await validator.fails());
|
|
3296
|
+
|
|
3297
|
+
validator = new Validator({ field: '01GZPCVRPR6K3KQW5B9ESB8PH3xxx' }, rules);
|
|
3298
|
+
assert(await validator.fails());
|
|
3299
|
+
|
|
3300
|
+
validator = new Validator({ field: 'xxx01GZPCVRPR6K3KQW5B9ESB8PH3xxx' }, rules);
|
|
3301
|
+
assert(await validator.fails());
|
|
3302
|
+
});
|
|
3068
3303
|
});
|
|
3069
3304
|
|
|
3070
3305
|
describe(`Rule 'uuid'`, () => {
|
|
@@ -3079,5 +3314,16 @@ describe('Validation', () => {
|
|
|
3079
3314
|
const validator = new Validator({ field: '395dbfe1-3451-x3f0-b295-337c00074099' }, rules);
|
|
3080
3315
|
assert(await validator.fails());
|
|
3081
3316
|
});
|
|
3317
|
+
|
|
3318
|
+
it(`Fails when the field contains a valid UUID with extra characters`, async () => {
|
|
3319
|
+
let validator = new Validator({ field: 'xxx395dbfe1-3451-43f0-b295-337c00074099' }, rules);
|
|
3320
|
+
assert(await validator.fails());
|
|
3321
|
+
|
|
3322
|
+
validator = new Validator({ field: '395dbfe1-3451-43f0-b295-337c00074099xxx' }, rules);
|
|
3323
|
+
assert(await validator.fails());
|
|
3324
|
+
|
|
3325
|
+
validator = new Validator({ field: 'xxx395dbfe1-3451-43f0-b295-337c00074099xxx' }, rules);
|
|
3326
|
+
assert(await validator.fails());
|
|
3327
|
+
});
|
|
3082
3328
|
});
|
|
3083
3329
|
});
|