quival 0.5.3 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/locales/en.js +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 +92 -37
- package/dist/quival.min.js +2 -2
- package/package.json +1 -1
- package/src/Checkers.js +58 -6
- package/src/Replacers.js +20 -3
- package/src/Validator.js +13 -5
- package/src/helpers.js +33 -27
- package/src/locales/en.js +4 -0
- package/src/locales/ms.js +4 -0
- package/test/helpers.js +19 -0
- package/test/validation.js +177 -0
package/dist/locales/en.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* quival v0.5.
|
|
2
|
+
* quival v0.5.5 (git+https://github.com/apih/quival.git)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -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.5 (git+https://github.com/apih/quival.git)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
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.5 (git+https://github.com/apih/quival.git)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -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.5 (git+https://github.com/apih/quival.git)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
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,11 +1,26 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* quival v0.5.
|
|
2
|
+
* quival v0.5.5 (git+https://github.com/apih/quival.git)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
var quival = (function (exports) {
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
+
const castToIntegers = (value) => (value && /^\d*$/.test(value) ? parseInt(value) : value);
|
|
10
|
+
const buildDate = (years, months, days, hours, minutes, seconds, meridiem) => {
|
|
11
|
+
if (years >= 10 && years < 100) {
|
|
12
|
+
years += 2000;
|
|
13
|
+
}
|
|
14
|
+
if (meridiem !== null) {
|
|
15
|
+
meridiem = meridiem.toLowerCase();
|
|
16
|
+
if (meridiem === 'pm' && hours < 12) {
|
|
17
|
+
hours += 12;
|
|
18
|
+
} else if (meridiem === 'am' && hours === 12) {
|
|
19
|
+
hours = 0;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return new Date(`${years}-${months}-${days} ${hours}:${minutes}:${seconds}`);
|
|
23
|
+
};
|
|
9
24
|
function toCamelCase(string) {
|
|
10
25
|
return string
|
|
11
26
|
.replace(/[-_]/g, ' ')
|
|
@@ -23,7 +38,7 @@ var quival = (function (exports) {
|
|
|
23
38
|
const keys = path.split('.');
|
|
24
39
|
let current = obj;
|
|
25
40
|
for (const key of keys) {
|
|
26
|
-
if (!Object.hasOwn(current, key)) {
|
|
41
|
+
if (current === null || current === undefined || !Object.hasOwn(current, key)) {
|
|
27
42
|
return defaultValue;
|
|
28
43
|
}
|
|
29
44
|
current = current[key];
|
|
@@ -74,34 +89,27 @@ var quival = (function (exports) {
|
|
|
74
89
|
return new Date('');
|
|
75
90
|
}
|
|
76
91
|
let match, years, months, days, hours, minutes, seconds, meridiem;
|
|
77
|
-
const castToIntegers = (value) => (value && /^\d*$/.test(value) ? parseInt(value) : value);
|
|
78
92
|
if ((match = value.match(/^(\d{1,2})[.\/-](\d{1,2})[.\/-](\d{2,4})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)) !== null) {
|
|
79
|
-
[, days, months, years, , hours = 0, minutes = 0, , seconds = 0, meridiem =
|
|
93
|
+
[, days, months, years, , hours = 0, minutes = 0, , seconds = 0, meridiem = null] = match.map(castToIntegers);
|
|
80
94
|
} else if (
|
|
81
95
|
(match = value.match(/^(\d{2,4})[.\/-](\d{1,2})[.\/-](\d{1,2})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)) !== null ||
|
|
82
96
|
(match = value.match(/^(\d{4})(\d{2})(\d{2})\s?((\d{2})(\d{2})((\d{2}))?\s?(am|pm)?)?/i)) !== null
|
|
83
97
|
) {
|
|
84
|
-
[, years, months, days, , hours = 0, minutes = 0, , seconds = 0, meridiem =
|
|
98
|
+
[, years, months, days, , hours = 0, minutes = 0, , seconds = 0, meridiem = null] = match.map(castToIntegers);
|
|
85
99
|
} else if ((match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{4})[.\/-](\d{2})[.\/-](\d{2})/i))) {
|
|
86
|
-
[, hours, minutes, , seconds, meridiem =
|
|
100
|
+
[, hours, minutes, , seconds, meridiem = null, years, months, days] = match.map(castToIntegers);
|
|
87
101
|
} else if ((match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{2})[.\/-](\d{2})[.\/-](\d{4})/i))) {
|
|
88
|
-
[, hours, minutes, , seconds, meridiem =
|
|
102
|
+
[, hours, minutes, , seconds, meridiem = null, days, months, years] = match.map(castToIntegers);
|
|
89
103
|
} else if ((match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?/i))) {
|
|
90
104
|
const current = new Date();
|
|
91
105
|
years = current.getFullYear();
|
|
92
106
|
months = current.getMonth() + 1;
|
|
93
107
|
days = current.getDate();
|
|
94
|
-
[, hours = 0, minutes = 0, , seconds = 0, meridiem =
|
|
108
|
+
[, hours = 0, minutes = 0, , seconds = 0, meridiem = null] = match.map(castToIntegers);
|
|
95
109
|
} else {
|
|
96
110
|
return new Date(value);
|
|
97
111
|
}
|
|
98
|
-
|
|
99
|
-
years += 2000;
|
|
100
|
-
}
|
|
101
|
-
if (meridiem.toLowerCase() === 'pm' && hours < 12) {
|
|
102
|
-
hours += 12;
|
|
103
|
-
}
|
|
104
|
-
return new Date(`${years}-${months}-${days} ${hours}:${minutes}:${seconds}`);
|
|
112
|
+
return buildDate(years, months, days, hours, minutes, seconds, meridiem);
|
|
105
113
|
}
|
|
106
114
|
function parseDateByFormat(value, format) {
|
|
107
115
|
if (isEmpty(value)) {
|
|
@@ -162,7 +170,7 @@ var quival = (function (exports) {
|
|
|
162
170
|
if (match === null) {
|
|
163
171
|
return new Date('');
|
|
164
172
|
}
|
|
165
|
-
match = match.map(
|
|
173
|
+
match = match.map(castToIntegers);
|
|
166
174
|
const current = new Date();
|
|
167
175
|
let years = match[indices.years];
|
|
168
176
|
let months = match[indices.months];
|
|
@@ -170,7 +178,7 @@ var quival = (function (exports) {
|
|
|
170
178
|
let hours = match[indices.hours] ?? 0;
|
|
171
179
|
let minutes = match[indices.minutes] ?? 0;
|
|
172
180
|
let seconds = match[indices.seconds] ?? 0;
|
|
173
|
-
let meridiem = match[indices.meridiem] ??
|
|
181
|
+
let meridiem = match[indices.meridiem] ?? null;
|
|
174
182
|
if (!years && !months && !days) {
|
|
175
183
|
years = current.getFullYear();
|
|
176
184
|
months = current.getMonth() + 1;
|
|
@@ -185,13 +193,10 @@ var quival = (function (exports) {
|
|
|
185
193
|
years = current.getFullYear();
|
|
186
194
|
months = current.getMonth() + 1;
|
|
187
195
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
hours += 12;
|
|
193
|
-
}
|
|
194
|
-
return new Date(`${years}-${months}-${days} ${hours}:${minutes}:${seconds}`);
|
|
196
|
+
return buildDate(years, months, days, hours, minutes, seconds, meridiem);
|
|
197
|
+
}
|
|
198
|
+
function getDecimalPlaces(value) {
|
|
199
|
+
return (String(value).split('.')[1] ?? '').length;
|
|
195
200
|
}
|
|
196
201
|
function isDigits(value) {
|
|
197
202
|
return String(value).search(/[^0-9]/) === -1;
|
|
@@ -237,6 +242,16 @@ var quival = (function (exports) {
|
|
|
237
242
|
}
|
|
238
243
|
return true;
|
|
239
244
|
}
|
|
245
|
+
collectPresentsThenTest(attribute, value, parameters, callback) {
|
|
246
|
+
let result = [];
|
|
247
|
+
for (const other of parameters) {
|
|
248
|
+
result.push(this.checkPresent(other, this.validator.getValue(other)));
|
|
249
|
+
}
|
|
250
|
+
if (callback(result)) {
|
|
251
|
+
return this.checkPresent(attribute, value);
|
|
252
|
+
}
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
240
255
|
collectMissingsThenTest(attribute, value, parameters, callback) {
|
|
241
256
|
let result = [];
|
|
242
257
|
for (const other of parameters) {
|
|
@@ -359,8 +374,8 @@ var quival = (function (exports) {
|
|
|
359
374
|
if (!isNumeric(value) || !isNumeric(parameters[0])) {
|
|
360
375
|
return false;
|
|
361
376
|
}
|
|
362
|
-
const numerator =
|
|
363
|
-
const denominator =
|
|
377
|
+
const numerator = Number(value);
|
|
378
|
+
const denominator = Number(parameters[0]);
|
|
364
379
|
if (numerator === 0 && denominator === 0) {
|
|
365
380
|
return false;
|
|
366
381
|
} else if (numerator === 0) {
|
|
@@ -368,7 +383,9 @@ var quival = (function (exports) {
|
|
|
368
383
|
} else if (denominator === 0) {
|
|
369
384
|
return false;
|
|
370
385
|
}
|
|
371
|
-
|
|
386
|
+
const decimalPlaces = Math.max(getDecimalPlaces(numerator), getDecimalPlaces(denominator));
|
|
387
|
+
const factor = 10 ** decimalPlaces;
|
|
388
|
+
return Math.round(numerator * factor) % Math.round(denominator * factor) === 0;
|
|
372
389
|
}
|
|
373
390
|
// Agreement
|
|
374
391
|
checkAccepted(attribute, value, parameters) {
|
|
@@ -458,6 +475,24 @@ var quival = (function (exports) {
|
|
|
458
475
|
checkPresent(attribute, value, parameters) {
|
|
459
476
|
return typeof value !== 'undefined';
|
|
460
477
|
}
|
|
478
|
+
checkPresentIf(attribute, value, parameters) {
|
|
479
|
+
if (this.isDependent(parameters)) {
|
|
480
|
+
return this.checkPresent(attribute, value);
|
|
481
|
+
}
|
|
482
|
+
return true;
|
|
483
|
+
}
|
|
484
|
+
checkPresentUnless(attribute, value, parameters) {
|
|
485
|
+
if (!this.isDependent(parameters)) {
|
|
486
|
+
return this.checkPresent(attribute, value);
|
|
487
|
+
}
|
|
488
|
+
return true;
|
|
489
|
+
}
|
|
490
|
+
checkPresentWith(attribute, value, parameters) {
|
|
491
|
+
return this.collectPresentsThenTest(attribute, value, parameters, (result) => result.includes(true));
|
|
492
|
+
}
|
|
493
|
+
checkPresentWithAll(attribute, value, parameters) {
|
|
494
|
+
return this.collectPresentsThenTest(attribute, value, parameters, (result) => !result.includes(false));
|
|
495
|
+
}
|
|
461
496
|
// Missing
|
|
462
497
|
checkMissing(attribute, value, parameters) {
|
|
463
498
|
return typeof value === 'undefined';
|
|
@@ -884,12 +919,12 @@ var quival = (function (exports) {
|
|
|
884
919
|
}
|
|
885
920
|
const blocks = String(value)
|
|
886
921
|
.split('.')
|
|
887
|
-
.
|
|
922
|
+
.map((block) => parseInt(block, 10));
|
|
888
923
|
if (blocks.length !== 4) {
|
|
889
924
|
return false;
|
|
890
925
|
}
|
|
891
926
|
for (const block of blocks) {
|
|
892
|
-
if (block < 0 || block > 255) {
|
|
927
|
+
if (isNaN(block) || block < 0 || block > 255) {
|
|
893
928
|
return false;
|
|
894
929
|
}
|
|
895
930
|
}
|
|
@@ -1122,15 +1157,28 @@ var quival = (function (exports) {
|
|
|
1122
1157
|
replaceRequiredWithoutAll(message, attribute, rule, parameters) {
|
|
1123
1158
|
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
1124
1159
|
}
|
|
1125
|
-
//
|
|
1126
|
-
|
|
1160
|
+
// Present
|
|
1161
|
+
replacePresentIf(message, attribute, rule, parameters) {
|
|
1127
1162
|
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
1128
1163
|
}
|
|
1129
|
-
|
|
1164
|
+
replacePresentUnless(message, attribute, rule, parameters) {
|
|
1130
1165
|
return this.replaceCaseVariants(this.replaceRequiredUnless(message, attribute, rule, parameters), {
|
|
1131
1166
|
value: this.validator.getDisplayableValue(parameters[0], parameters[1]),
|
|
1132
1167
|
});
|
|
1133
1168
|
}
|
|
1169
|
+
replacePresentWith(message, attribute, rule, parameters) {
|
|
1170
|
+
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
1171
|
+
}
|
|
1172
|
+
replacePresentWithAll(message, attribute, rule, parameters) {
|
|
1173
|
+
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
1174
|
+
}
|
|
1175
|
+
// Missing
|
|
1176
|
+
replaceMissingIf(message, attribute, rule, parameters) {
|
|
1177
|
+
return this.replaceAcceptedIf(message, attribute, rule, parameters);
|
|
1178
|
+
}
|
|
1179
|
+
replaceMissingUnless(message, attribute, rule, parameters) {
|
|
1180
|
+
return this.replacePresentUnless(message, attribute, rule, parameters);
|
|
1181
|
+
}
|
|
1134
1182
|
replaceMissingWith(message, attribute, rule, parameters) {
|
|
1135
1183
|
return this.replaceRequiredWith(message, attribute, rule, parameters);
|
|
1136
1184
|
}
|
|
@@ -1304,6 +1352,10 @@ var quival = (function (exports) {
|
|
|
1304
1352
|
'missing_with',
|
|
1305
1353
|
'missing_with_all',
|
|
1306
1354
|
'present',
|
|
1355
|
+
'present_if',
|
|
1356
|
+
'present_unless',
|
|
1357
|
+
'present_with',
|
|
1358
|
+
'present_with_all',
|
|
1307
1359
|
'required',
|
|
1308
1360
|
'required_if',
|
|
1309
1361
|
'required_if_accepted',
|
|
@@ -1651,14 +1703,17 @@ var quival = (function (exports) {
|
|
|
1651
1703
|
getDisplayableValue(attribute, value) {
|
|
1652
1704
|
attribute = this.getPrimaryAttribute(attribute);
|
|
1653
1705
|
const path = `${attribute}.${value}`;
|
|
1706
|
+
if (Object.hasOwn(this.#customValues, path)) {
|
|
1707
|
+
return this.#customValues[path];
|
|
1708
|
+
} else if (Lang.has(`values.${path}`)) {
|
|
1709
|
+
return Lang.get(`values.${path}`);
|
|
1710
|
+
}
|
|
1654
1711
|
if (isEmpty(value)) {
|
|
1655
1712
|
return 'empty';
|
|
1713
|
+
} else if (Array.isArray(value)) {
|
|
1714
|
+
return 'array';
|
|
1656
1715
|
} else if (typeof value === 'boolean' || this.hasRule(attribute, 'boolean')) {
|
|
1657
1716
|
return Number(value) ? 'true' : 'false';
|
|
1658
|
-
} else if (Object.hasOwn(this.#customValues, path)) {
|
|
1659
|
-
return this.#customValues[path];
|
|
1660
|
-
} else if (Lang.has(`values.${path}`)) {
|
|
1661
|
-
return Lang.get(`values.${path}`);
|
|
1662
1717
|
}
|
|
1663
1718
|
return value;
|
|
1664
1719
|
}
|
|
@@ -1680,7 +1735,7 @@ var quival = (function (exports) {
|
|
|
1680
1735
|
}
|
|
1681
1736
|
getRule(attribute) {
|
|
1682
1737
|
attribute = this.getPrimaryAttribute(attribute);
|
|
1683
|
-
return this.#rules[attribute] ??
|
|
1738
|
+
return this.#rules[attribute] ?? [];
|
|
1684
1739
|
}
|
|
1685
1740
|
hasRule(attribute, rules) {
|
|
1686
1741
|
attribute = this.getPrimaryAttribute(attribute);
|
package/dist/quival.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* quival v0.5.
|
|
2
|
+
* quival v0.5.5 (git+https://github.com/apih/quival.git)
|
|
3
3
|
* (c) 2023 Mohd Hafizuddin M Marzuki <hafizuddin_83@yahoo.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
var quival=function(e){"use strict";function t(e){return e.replace(/[-_]/g," ").replace(/\s+/g," ").trim().replace(/(\s\w)/g,e=>e[1].toUpperCase())}function r(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function s(e,t=""){return Object.keys(e).reduce((r,i)=>{const 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(e instanceof Date)return e;if(c(e)||"string"!=typeof e)return new Date("");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),n=Array.isArray(c)?c.find(([e])=>"date_format"===e):null,l=n?n[1][0]:null;if(!u(t=l?a(t,l):i(t)))return!1;const h=r[0]??"";let o=this.validator.getValue(h);if(void 0===o)o=l?a(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?a(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!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(".").filter(e=>""!==e);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;#y;#A;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.#y=!1,this.#A=!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.#y=e,this}alwaysBail(e=!0){return this.#A=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.#A||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.#y){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";const t=e=>e&&/^\d*$/.test(e)?parseInt(e):e,r=(e,t,r,s,i,c,a)=>(e>=10&&e<100&&(e+=2e3),null!==a&&("pm"===(a=a.toLowerCase())&&s<12?s+=12:"am"===a&&12===s&&(s=0)),new Date(`${e}-${t}-${r} ${s}:${i}:${c}`));function s(e){return e.replace(/[-_]/g," ").replace(/\s+/g," ").trim().replace(/(\s\w)/g,e=>e[1].toUpperCase())}function i(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function c(e,t=""){return Object.keys(e).reduce((r,s)=>{const i=t?`${t}.${s}`:s;return"object"==typeof e[s]&&null!==e[s]?Object.assign(r,c(e[s],i)):r[i]=e[s],r},{})}function a(e){if(e instanceof Date)return e;if(u(e)||"string"!=typeof e)return new Date("");let s,i,c,a,n,l,h,o;if(null!==(s=e.match(/^(\d{1,2})[.\/-](\d{1,2})[.\/-](\d{2,4})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)))[,a,c,i,,n=0,l=0,,h=0,o=null]=s.map(t);else if(null!==(s=e.match(/^(\d{2,4})[.\/-](\d{1,2})[.\/-](\d{1,2})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i))||null!==(s=e.match(/^(\d{4})(\d{2})(\d{2})\s?((\d{2})(\d{2})((\d{2}))?\s?(am|pm)?)?/i)))[,i,c,a,,n=0,l=0,,h=0,o=null]=s.map(t);else if(s=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{4})[.\/-](\d{2})[.\/-](\d{2})/i))[,n,l,,h,o=null,i,c,a]=s.map(t);else if(s=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{2})[.\/-](\d{2})[.\/-](\d{4})/i))[,n,l,,h,o=null,a,c,i]=s.map(t);else{if(!(s=e.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?/i)))return new Date(e);{const e=new Date;i=e.getFullYear(),c=e.getMonth()+1,a=e.getDate(),[,n=0,l=0,,h=0,o=null]=s.map(t)}}return r(i,c,a,n,l,h,o)}function n(e,s){if(u(e))return new Date("");s=s.split("");const i={Y:"(\\d{4})",y:"(\\d{2})",m:"(\\d{2})",n:"([1-9]\\d?)",d:"(\\d{2})",j:"([1-9]\\d?)",G:"([1-9]\\d?)",g:"([1-9]\\d?)",H:"(\\d{2})",h:"(\\d{2})",i:"(\\d{2})",s:"(\\d{2})",A:"(AM|PM)",a:"(am|pm)"};let c="^",a={years:-1,months:-1,days:-1,hours:-1,minutes:-1,seconds:-1,meridiem:-1},n=1;for(const e of s)Object.hasOwn(i,e)?(c+=i[e],-1!==["Y","y"].indexOf(e)?a.years=n++:-1!==["m","n"].indexOf(e)?a.months=n++:-1!==["d","j"].indexOf(e)?a.days=n++:-1!==["G","g","H","h"].indexOf(e)?a.hours=n++:"i"===e?a.minutes=n++:"s"===e?a.seconds=n++:-1!==["A","a"].indexOf(e)&&(a.meridiem=n++)):c+="\\"+e;c+="$";let l=e.match(new RegExp(c));if(null===l)return new Date("");l=l.map(t);const h=new Date;let o=l[a.years],p=l[a.months],d=l[a.days],f=l[a.hours]??0,g=l[a.minutes]??0,m=l[a.seconds]??0,k=l[a.meridiem]??null;return o||p||d?!o||p||d?o||!p||d?o||p||!d||(o=h.getFullYear(),p=h.getMonth()+1):(o=h.getFullYear(),d=1):(p=1,d=1):(o=h.getFullYear(),p=h.getMonth()+1,d=h.getDate()),r(o,p,d,f,g,m,k)}function l(e){return(String(e).split(".")[1]??"").length}function u(e){return""===e||null==e}function h(e){const t=Number(e);return null!==e&&"boolean"!=typeof e&&"number"==typeof t&&!isNaN(t)}function o(e){return"[object Object]"===Object.prototype.toString.call(e)}function p(e){return e instanceof Date&&"Invalid Date"!==e.toDateString()}class d{#e;#t;constructor(e){this.#e={},this.#t={},this.validator=e}clearCaches(){this.#e={},this.#t={}}isDependent(e){const t=this.validator.getValue(e[0]);return e.slice(1).some(e=>e==t)}collectRequiredsThenTest(e,t,r,s){let i=[];for(const e of r)i.push(this.checkRequired(e,this.validator.getValue(e)));return!s(i)||this.checkRequired(e,t)}collectPresentsThenTest(e,t,r,s){let i=[];for(const e of r)i.push(this.checkPresent(e,this.validator.getValue(e)));return!s(i)||this.checkPresent(e,t)}collectMissingsThenTest(e,t,r,s){let i=[];for(const e of r)i.push(this.checkMissing(e,this.validator.getValue(e)));return!s(i)||this.checkMissing(e,t)}testStringUsingRegex(e,t,r,s,i=!1){return("string"==typeof t||"number"==typeof t)&&(t=String(t),i||this.validator.hasRule(e,"ascii")?r.test(t):s.test(t))}compareValues(e,t,r,s){if(u(t))return!1;const i=r[0]??"";let c=this.validator.getValue(i);return c=void 0===c?h(i)?parseFloat(i):null:this.validator.getSize(i,c),!u(c)&&s(this.validator.getSize(e,t),c)}compareDates(e,t,r,s){const i=this.validator.getRule(e),c=Array.isArray(i)?i.find(([e])=>"date_format"===e):null,l=c?c[1][0]:null;if(!p(t=l?n(t,l):a(t)))return!1;const u=r[0]??"";let h=this.validator.getValue(u);if(void 0===h)h=l?n(u,l):a(u);else{const e=this.validator.getRule(u),t=Array.isArray(e)?e.find(([e])=>"date_format"===e):null,r=t?t[1][0]:null;h=r?n(h,r):a(h)}return!!p(h)&&s(t.getTime(),h.getTime())}checkArray(e,t,r=[]){if(!Array.isArray(t)&&!o(t))return!1;if(r.length>0)for(const e of Object.keys(t))if(!r.includes(e))return!1;return!0}checkList(e,t,r){return Array.isArray(t)}checkBoolean(e,t,r=[]){return r.includes("strict")?[!0,!1].includes(t):[!0,!1,0,1,"0","1"].includes(t)}checkDate(e,t,r){return p(a(t))}checkFile(e,t,r){return t instanceof File}checkInteger(e,t,r=[]){return r.includes("strict")||"string"!=typeof t||(t=parseFloat(t)),Number.isInteger(t)}checkNumeric(e,t,r=[]){return r.includes("strict")?"number"==typeof t:h(t)}checkString(e,t,r){return"string"==typeof t}checkDecimal(e,t,r=[]){if(!this.checkNumeric(e,t))return!1;const s=(String(t).split(".")[1]??"").length;return 1===r.length?s==r[0]:s>=r[0]&&s<=r[1]}checkMultipleOf(e,t,r){if(!h(t)||!h(r[0]))return!1;const s=Number(t),i=Number(r[0]);if(0===s&&0===i)return!1;if(0===s)return!0;if(0===i)return!1;const c=10**Math.max(l(s),l(i));return Math.round(s*c)%Math.round(i*c)===0}checkAccepted(e,t,r){return["yes","on","1",1,!0,"true"].includes(t)}checkAcceptedIf(e,t,r){return!this.isDependent(r)||this.checkAccepted(e,t,r)}checkDeclined(e,t,r){return["no","off","0",0,!1,"false"].includes(t)}checkDeclinedIf(e,t,r){return!this.isDependent(r)||this.checkDeclined(e,t,r)}checkRequired(e,t,r){return!u(t)&&(Array.isArray(t)?t.length>0:t instanceof File?t.size>0:(t=String(t).replace(/\s/g,"")).length>0)}checkRequiredArrayKeys(e,t,r=[]){if(!this.checkArray(e,t))return!1;const s=Object.keys(t);for(const e of r)if(!s.includes(e))return!1;return!0}checkRequiredIf(e,t,r){return!this.isDependent(r)||this.checkRequired(e,t)}checkRequiredIfAccepted(e,t,r){return!this.checkAccepted(r[0],this.validator.getValue(r[0]))||this.checkRequired(e,t)}checkRequiredIfDeclined(e,t,r){return!this.checkDeclined(r[0],this.validator.getValue(r[0]))||this.checkRequired(e,t)}checkRequiredUnless(e,t,r){return!!this.isDependent(r)||this.checkRequired(e,t)}checkRequiredWith(e,t,r){return this.collectRequiredsThenTest(e,t,r,e=>e.includes(!0))}checkRequiredWithAll(e,t,r){return this.collectRequiredsThenTest(e,t,r,e=>!e.includes(!1))}checkRequiredWithout(e,t,r){return this.collectRequiredsThenTest(e,t,r,e=>e.includes(!1))}checkRequiredWithoutAll(e,t,r){return this.collectRequiredsThenTest(e,t,r,e=>!e.includes(!0))}checkFilled(e,t,r){return void 0===t||this.checkRequired(e,t)}checkPresent(e,t,r){return void 0!==t}checkPresentIf(e,t,r){return!this.isDependent(r)||this.checkPresent(e,t)}checkPresentUnless(e,t,r){return!!this.isDependent(r)||this.checkPresent(e,t)}checkPresentWith(e,t,r){return this.collectPresentsThenTest(e,t,r,e=>e.includes(!0))}checkPresentWithAll(e,t,r){return this.collectPresentsThenTest(e,t,r,e=>!e.includes(!1))}checkMissing(e,t,r){return void 0===t}checkMissingIf(e,t,r){return!this.isDependent(r)||this.checkMissing(e,t)}checkMissingUnless(e,t,r){return!!this.isDependent(r)||this.checkMissing(e,t)}checkMissingWith(e,t,r){return this.collectMissingsThenTest(e,t,r,e=>e.includes(!1))}checkMissingWithAll(e,t,r){return this.collectMissingsThenTest(e,t,r,e=>!e.includes(!0))}checkProhibited(e,t,r){return!this.checkRequired(e,t)}checkProhibitedIf(e,t,r){return!this.isDependent(r)||!this.checkRequired(e,t)}checkProhibitedUnless(e,t,r){return!!this.isDependent(r)||!this.checkRequired(e,t)}checkProhibits(e,t,r=[]){if(this.checkRequired(e,t))for(const e of r)if(this.checkRequired(e,this.validator.getValue(e)))return!1;return!0}checkSize(e,t,r){return this.validator.getSize(e,t)===parseFloat(r[0])}checkMin(e,t,r){return this.validator.getSize(e,t)>=parseFloat(r[0])}checkMax(e,t,r){return this.validator.getSize(e,t)<=parseFloat(r[0])}checkBetween(e,t,r){return this.checkMin(e,t,[r[0]])&&this.checkMax(e,t,[r[1]])}checkDigits(e,t,r,s=(e,t)=>e===t){return!!function(e){return-1===String(e).search(/[^0-9]/)}(t=String(t??""))&&s(t.length,parseInt(r[0],10),parseInt(r[1]??0,10))}checkMinDigits(e,t,r){return this.checkDigits(e,t,r,(e,t)=>e>=t)}checkMaxDigits(e,t,r){return this.checkDigits(e,t,r,(e,t)=>e<=t)}checkDigitsBetween(e,t,r){return this.checkDigits(e,t,r,(e,t,r)=>e>=t&&e<=r)}checkAlpha(e,t,r){return this.testStringUsingRegex(e,t,/^[a-z]+$/i,/^[\p{L}\p{M}]+$/u,r.includes("ascii"))}checkAlphaDash(e,t,r){return this.testStringUsingRegex(e,t,/^[a-z0-9_-]+$/i,/^[\p{L}\p{M}\p{N}_-]+$/u,r.includes("ascii"))}checkAlphaNum(e,t,r){return this.testStringUsingRegex(e,t,/^[a-z0-9]+$/i,/^[\p{L}\p{M}\p{N}]+$/u,r.includes("ascii"))}checkAscii(e,t,r){return!/[^\x09\x10\x13\x0A\x0D\x20-\x7E]/.test(t)}checkRegex(e,t,r,s=!1){if("string"!=typeof t&&!h(t))return!1;const i=r.join(",");let[c,a,n]=i.match(/^\/(.*)\/([gimu]*)$/)??[];if(u(c))throw new Error(`Invalid regular expression pattern: ${i}`);n.includes("u")&&(a=a.replace(/\\A/g,"^").replace(/\\z/gi,"$").replace(/\\([pP])([CLMNPSZ])/g,"\\$1{$2}").replace(/\\\x\{([0-9a-f]+)\}/g,"\\u{$1}"));const l=new RegExp(a,n).test(t);return s?!l:l}checkNotRegex(e,t,r){return this.checkRegex(e,t,r,!0)}checkLowercase(e,t,r){return t===String(t).toLocaleLowerCase()}checkUppercase(e,t,r){return t===String(t).toLocaleUpperCase()}checkStartsWith(e,t,r=[]){t=String(t);for(const e of r)if(t.startsWith(e))return!0;return!1}checkDoesntStartWith(e,t,r){return!this.checkStartsWith(e,t,r)}checkEndsWith(e,t,r=[]){t=String(t);for(const e of r)if(t.endsWith(e))return!0;return!1}checkDoesntEndWith(e,t,r){return!this.checkEndsWith(e,t,r)}checkSame(e,t,r){return t===this.validator.getValue(r[0])}checkDifferent(e,t,r=[]){for(const e of r){const r=this.validator.getValue(e);if(void 0!==r&&t===r)return!1}return!0}checkConfirmed(e,t,r){return this.checkSame(e,t,[r[0]??e+"_confirmation"])}checkGt(e,t,r){return this.compareValues(e,t,r,(e,t)=>e>t)}checkGte(e,t,r){return this.compareValues(e,t,r,(e,t)=>e>=t)}checkLt(e,t,r){return this.compareValues(e,t,r,(e,t)=>e<t)}checkLte(e,t,r){return this.compareValues(e,t,r,(e,t)=>e<=t)}checkAfter(e,t,r){return this.compareDates(e,t,r,(e,t)=>e>t)}checkAfterOrEqual(e,t,r){return this.compareDates(e,t,r,(e,t)=>e>=t)}checkBefore(e,t,r){return this.compareDates(e,t,r,(e,t)=>e<t)}checkBeforeOrEqual(e,t,r){return this.compareDates(e,t,r,(e,t)=>e<=t)}checkDateEquals(e,t,r){return this.compareDates(e,t,r,(e,t)=>e===t)}checkDateFormat(e,t,r){const s=r[0].split(""),i={Y:"(\\d{4})",y:"(\\d{2})",m:"(\\d{2})",n:"([1-9]\\d?)",d:"(\\d{2})",j:"([1-9]\\d?)",G:"([1-9]\\d?)",g:"([1-9]\\d?)",H:"(\\d{2})",h:"(\\d{2})",i:"(\\d{2})",s:"(\\d{2})",A:"(AM|PM)",a:"(am|pm)"};let c="^";for(const e of s)Object.hasOwn(i,e)?c+=i[e]:c+="\\"+e;return c+="$",new RegExp(c).test(t)}checkContains(e,t,r=[]){if(!this.checkArray(e,t))return!1;for(const e of r)if(!t.includes(e))return!1;return!0}checkDoesntContain(e,t,r=[]){if(!this.checkArray(e,t))return!1;for(const e of r)if(t.includes(e))return!1;return!0}checkDistinct(e,t,r){const s=this.validator.getPrimaryAttribute(e);if(!s.includes("*"))return!0;const a=s.indexOf("*"),n=s.substring(0,a-1);let l;Object.hasOwn(this.#e,n)?l=this.#e[n]:(l=JSON.stringify(c(this.validator.getValue(n)??{})),this.#e[n]=l);const u=r.includes("ignore_case"),h=!u&&r.includes("strict"),o=i(String(t));let p=`"${i(s.substring(a)).replaceAll("\\*",'[^."]+')}":`,d=0;return p+=h?"string"==typeof t?`"${o}"`:`${o}`:`(${o}|"${o}")`,p+="[,}]+",d+=l.match(new RegExp(p,"g"+(u?"i":"")))?.length??0,1===d}checkInArray(e,t,r){const s=this.validator.getPrimaryAttribute(r[0]);if(!s.includes("*"))return!1;const i=this.validator.getValue(s.split(".*")[0])??{};return Object.values(c(i)).some(e=>e==t)}checkIn(e,t,r){if(!this.checkArray(e,t)||!this.validator.hasRule(e,"array"))return r.some(e=>e==t);for(const e of Object.values(t))if(!r.some(t=>t==e))return!1;return!0}checkNotIn(e,t,r){return!this.checkIn(e,t,r)}checkMimetypes(e,t,r){return!!this.checkFile(e,t)&&r.includes(t.type)}checkMimes(e,t,r=[]){return!!this.checkFile(e,t)&&(r.includes("jpg")&&!r.includes("jpeg")&&r.push("jpeg"),r.includes("jpeg")&&!r.includes("jpg")&&r.push("jpg"),r.includes(t.name.split(".").pop().toLowerCase()))}checkExtensions(e,t,r){return this.checkMimes(e,t,r)}async checkImage(e,t,r=[]){const s=["jpg","jpeg","png","gif","bmp","webp"];r.includes("allow_svg")&&s.push("svg");let i=this.checkMimes(e,t,s);return i&&"undefined"!=typeof FileReader?(await new Promise((e,r)=>{const s=new FileReader;s.onload=t=>e(t.target.result),s.onerror=r,s.readAsDataURL(t)}).then(async t=>{const r=new Image;r.src=t,await r.decode(),this.#t[e]=r}).catch(()=>{i=!1}),i):i}async checkDimensions(e,t,r=[]){if(!await this.checkImage(e,t)||!Object.hasOwn(this.#t,e))return!1;const s={};for(const e of r){const[t,r]=e.split("=",2);if("ratio"===t&&r.includes("/")){const[e,i]=r.split("/",2).map(e=>parseFloat(e,10));s[t]=e/i}else s[t]=parseFloat(r,10)}const i=this.#t[e],c=i.naturalWidth,a=i.naturalHeight;return!(Object.hasOwn(s,"width")&&s.width!==c||Object.hasOwn(s,"height")&&s.height!==a||Object.hasOwn(s,"min_width")&&s.min_width>c||Object.hasOwn(s,"min_height")&&s.min_height>a||Object.hasOwn(s,"max_width")&&s.max_width<c||Object.hasOwn(s,"max_height")&&s.max_height<a)&&(!Object.hasOwn(s,"ratio")||Math.abs(s.ratio-c/a)<=1/(Math.max(c,a)+1))}checkEmail(e,t,r){if(!/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(t)){return/^((?:[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]|[^\u0000-\u007F])+@(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?(?:\.(?:[a-zA-Z0-9]|[^\u0000-\u007F])(?:(?:[a-zA-Z0-9-]|[^\u0000-\u007F]){0,61}(?:[a-zA-Z0-9]|[^\u0000-\u007F]))?)+)*$/.test(t)}return!0}checkJson(e,t,r){try{JSON.parse(t)}catch(e){return!1}return!0}checkHexColor(e,t,r){return/^#(?:(?:[0-9a-f]{3}){1,2}|(?:[0-9a-f]{4}){1,2})$/i.test(t)}checkMacAddress(e,t,r){t=String(t);const s={"-":2,":":2,".":4};let i,c;for([i,c]of Object.entries(s))if(t.includes(i))break;const a=t.split(i);if(a.length!==12/c)return!1;for(const e of a)if(!new RegExp("^[0-9a-f]{"+c+"}$","i").test(e))return!1;return!0}checkIpv4(e,t,r){if(/[^\d.]/.test(t))return!1;const s=String(t).split(".").map(e=>parseInt(e,10));if(4!==s.length)return!1;for(const e of s)if(isNaN(e)||e<0||e>255)return!1;return!0}checkIpv6(e,t,r){if((t=String(t)).includes(":::")||t.split("::").length>2)return!1;const s=t.split(":");if(s.length<3||s.length>8)return!1;for(const e of s)if(""!==e&&!/^[0-9a-f]{1,4}$/i.test(e))return!1;return!0}checkIp(e,t,r){return this.checkIpv4(e,t,r)||this.checkIpv6(e,t,r)}checkTimezone(e,t,r){try{Intl.DateTimeFormat(void 0,{timeZone:t})}catch(e){if(e instanceof RangeError)return!1}return!0}checkUrl(e,t,r){try{new URL(t)}catch(e){return!1}return!0}checkUlid(e,t,r){return/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/.test(t)}checkUuid(e,t,r){return/^[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}$/.test(t)}}class f{#r;keys(){return Object.keys(this.#r)}values(){return Object.values(this.#r)}entries(){return Object.entries(this.#r)}add(e,t){Object.hasOwn(this.#r,e)?this.#r[e].push(t):this.#r[e]=[t]}get(e){if(!e.includes("*"))return Object.hasOwn(this.#r,e)?this.#r[e]:{};const t=new RegExp("^"+e.replaceAll("*",".*?")+"$"),r={};for(const[e,s]of this.entries())t.test(e)&&(r[e]=s);return r}first(e){for(const t of Object.values(this.get(e)))return Array.isArray(t)?t[0]:t;return""}has(e){return""!==this.first(e)}remove(e){delete this.#r[e]}messages(){return this.#r}all(){const e=[];return this.values().forEach(t=>e.push(...t)),e}count(){let e=0;return this.values().forEach(t=>e+=t.length),e}isEmpty(){return 0===this.keys().length}isNotEmpty(){return!this.isEmpty()}sortByKeys(e){const t={};for(const r of e)Object.hasOwn(this.#r,r)&&(t[r]=this.#r[r]);this.#r=t}constructor(){this.#r={}}}class g{static#s;static#i={};static locale(e){this.#s=e}static setMessages(e,t){this.#i[e]=c(t)}static get(e){if(this.#i[this.#s]&&this.#i[this.#s][e])return this.#i[this.#s][e]}static has(e){return void 0!==this.get(e)}static set(e,t){o(t)?Object.assign(this.#i[this.#s],c(t,e)):"string"==typeof t&&(this.#i[this.#s][e]=t)}}class m{constructor(e){this.validator=e}replace(e,t){return Object.entries(t).forEach(([t,r])=>e=e.replaceAll(":"+t,r)),e}replaceCaseVariants(e,t){return Object.entries(t).flatMap(([e,t])=>[[e,t],[e.toLocaleUpperCase(),t.toLocaleUpperCase()],[e.charAt(0).toLocaleUpperCase()+e.substring(1),t.charAt(0).toLocaleUpperCase()+t.substring(1)]]).forEach(([t,r])=>e=e.replaceAll(":"+t,r)),e}replaceDecimal(e,t,r,s){return this.replace(e,{decimal:s.join("-")})}replaceMultipleOf(e,t,r,s){return this.replace(e,{value:s[0]})}replaceAcceptedIf(e,t,r,s){return this.replaceCaseVariants(e,{other:this.validator.getDisplayableAttribute(s[0]),value:this.validator.getDisplayableValue(s[0],this.validator.getValue(s[0]))})}replaceDeclinedIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredArrayKeys(e,t,r,s){return this.replace(e,{values:s.map(e=>this.validator.getDisplayableValue(t,e)).join(", ")})}replaceRequiredIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredIfAccepted(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredIfDeclined(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceRequiredUnless(e,t,r,s){return this.replaceCaseVariants(e,{other:this.validator.getDisplayableAttribute(s[0]),values:s.slice(1).map(e=>this.validator.getDisplayableValue(s[0],e)).join(", ")})}replaceRequiredWith(e,t,r,s){return this.replaceCaseVariants(e,{values:s.map(e=>this.validator.getDisplayableAttribute(e)).join(" / ")})}replaceRequiredWithAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceRequiredWithout(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceRequiredWithoutAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replacePresentIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replacePresentUnless(e,t,r,s){return this.replaceCaseVariants(this.replaceRequiredUnless(e,t,r,s),{value:this.validator.getDisplayableValue(s[0],s[1])})}replacePresentWith(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replacePresentWithAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceMissingIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceMissingUnless(e,t,r,s){return this.replacePresentUnless(e,t,r,s)}replaceMissingWith(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceMissingWithAll(e,t,r,s){return this.replaceRequiredWith(e,t,r,s)}replaceProhibitedIf(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceProhibitedUnless(e,t,r,s){return this.replaceRequiredUnless(e,t,r,s)}replaceProhibits(e,t,r,s){return this.replaceCaseVariants(e,{other:s.map(e=>this.validator.getDisplayableAttribute(e)).join(" / ")})}replaceSize(e,t,r,s){return this.replace(e,{size:s[0]})}replaceMin(e,t,r,s){return this.replace(e,{min:s[0]})}replaceMax(e,t,r,s){return this.replace(e,{max:s[0]})}replaceBetween(e,t,r,s){return this.replace(e,{min:s[0],max:s[1]})}replaceDigits(e,t,r,s){return this.replace(e,{digits:s[0]})}replaceMinDigits(e,t,r,s){return this.replaceMin(e,t,r,s)}replaceMaxDigits(e,t,r,s){return this.replaceMax(e,t,r,s)}replaceDigitsBetween(e,t,r,s){return this.replaceBetween(e,t,r,s)}replaceStartsWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceDoesntStartWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceEndsWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceDoesntEndWith(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceSame(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceDifferent(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceGt(e,t,r,s){const i=this.validator.getValue(s[0]);return this.replace(e,{value:i?this.validator.getSize(s[0],i):this.validator.getDisplayableAttribute(s[0])})}replaceGte(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceLt(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceLte(e,t,r,s){return this.replaceGt(e,t,r,s)}replaceAfter(e,t,r,s){const i=s[0];return this.replace(e,{date:this.validator.hasAttribute(i)?this.validator.getDisplayableAttribute(i):i})}replaceAfterOrEqual(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceBefore(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceBeforeOrEqual(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceDateEquals(e,t,r,s){return this.replaceAfter(e,t,r,s)}replaceDateFormat(e,t,r,s){return this.replace(e,{format:s[0]})}replaceInArray(e,t,r,s){return this.replaceAcceptedIf(e,t,r,s)}replaceIn(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceNotIn(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceDoesntContain(e,t,r,s){return this.replaceRequiredArrayKeys(e,t,r,s)}replaceMimetypes(e,t,r,s){return this.replace(e,{values:s.join(", ")})}replaceMimes(e,t,r,s){return this.replaceMimetypes(e,t,r,s)}replaceExtensions(e,t,r,s){return this.replaceMimetypes(e,t,r,s)}}class k{static#c={};static#a={};static#n=["active_url","bail","can","current_password","encoding","enum","exclude","exclude_if","exclude_unless","exclude_with","exclude_without","exists","nullable","sometimes","unique"];static#l=["accepted","accepted_if","declined","declined_if","filled","missing","missing_if","missing_unless","missing_with","missing_with_all","present","present_if","present_unless","present_with","present_with_all","required","required_if","required_if_accepted","required_if_declined","required_unless","required_with","required_with_all","required_without","required_without_all"];#r;#u;#h;#o;#p;#d;#f;#g;#m;#k;#A;#y;static setLocale(e){g.locale(e)}static setMessages(e,t){g.setMessages(e,t)}static addChecker(e,t,r){k.#c[e]=t,r&&g.set(e,r)}static addImplicitChecker(e,t,r){k.addChecker(e,t,r),k.#l.push(e)}static addReplacer(e,t){k.#a[e]=t}static addDummyRule(e){k.#n.push(e)}constructor(e={},t={},r={},i={},c={}){this.#m=[],this.#k={},this.#A=!1,this.#y=!1,this.arrayRules=["array","list"],this.fileRules=["file","image","mimetypes","mimes"],this.stringRules=["string","alpha","alpha_dash","alpha_num","ascii","email"],this.numericRules=["decimal","numeric","integer"],this.sizeRules=["size","between","min","max","gt","lt","gte","lte"],this.setProperties(e,t,r,i,c),this.#d=new d(this),this.#f=new m(this);for(const[e,t]of Object.entries(k.#c))this.#d[s("check_"+e)]=t;for(const[e,t]of Object.entries(k.#a))this.#f[s("replace_"+e)]=t;this.#g=new f}setProperties(e={},t={},r={},s={},i={}){return this.#r=e,this.#u=this.parseRules(t),this.#h=r,this.#o=s,this.#p=c(i),this}setData(e){return this.#r=e,this}setRules(e){return this.#u=this.parseRules(e),this}setCustomMessages(e){return this.#h=e,this}setCustomAttributes(e){return this.#o=e,this}setCustomValues(e){return this.#p=c(e),this}addImplicitAttribute(e,t){return this.#k[e]=t,this}stopOnFirstFailure(e=!0){return this.#A=e,this}alwaysBail(e=!0){return this.#y=e,this}parseRules(e){const t={};for(const[r,s]of Object.entries(e)){const e=r.includes("*")?this.parseWildcardAttribute(r):[r];for(const r of e){const e=[];for(const t of this.parseAttributeRules(s))e.push(this.parseAttributeRule(t));t[r]=e}}return t}parseWildcardAttribute(e){const t=[],r=e.indexOf("*"),s=e.substring(0,r-1),i=e.substring(r+2),c=this.getValue(s);return Array.isArray(c)||o(c)?(Object.entries(c).forEach(([r,c])=>{const a=`${s}.${r}.${i}`.replace(/\.$/,""),n=a.includes("*")?this.parseWildcardAttribute(a):[a];t.push(...n),n.forEach(t=>this.#k[t]=e)}),t):[e]}parseAttributeRules(e){return Array.isArray(e)?e:"function"==typeof e?[e]:String(e).split("|")}parseAttributeRule(e){if("function"==typeof e)return[e,[]];let t,r;if(Array.isArray(e))t=e[0]??"",r=e.slice(1);else{const s=e.indexOf(":");-1===s?(t=e,r=[]):(t=e.substring(0,s),r=function(e){const t=[];let r="",s=!1;for(let i=0;i<e.length;i++){const c=e[i];'"'===c?s&&'"'===e[i+1]?(r+='"',i++):(s=!s,s&&(r=r.trim())):","!==c||s?r+=c:(t.push(r),r="")}return t.push(r),t}(e.substring(s+1)))}return[this.normalizeRuleName(t),r]}normalizeRuleName(e){return{int:"integer",bool:"boolean"}[e]??e}async validate(){this.#d.clearCaches(),this.#g=new f;const e=[],t=new Set;for(const[e,t]of Object.entries(this.#u))for(const[e]of t)if(""!==e&&"function"!=typeof e&&"function"!=typeof this.#d[s("check_"+e)]&&!k.#n.includes(e))throw new Error(`Invalid validation rule: ${e}`);for(const[r,i]of Object.entries(this.#u)){let c=this.getValue(r);const a=e=>i.some(t=>t[0]===e);a("sometimes")&&void 0===c?t.add(r):e.push(async()=>{const e=this.#y||a("bail"),n=a("nullable");let l=!0;for(const[a,h]of i){if(""===a||"function"!=typeof a&&!k.#l.includes(a)&&(void 0===c||"string"==typeof c&&""===c.trim()||n&&null===c)){t.add(r);continue}let i,o,p;const d=(()=>{if("function"==typeof a)return a;{const e=this.#d[s("check_"+a)]??null;return null===e&&k.#n.includes(a)?()=>!0:e}})();if(null===d)throw new Error(`Invalid validation rule: ${a}`);if(i=await d.call(this.#d,r,c,h),"boolean"==typeof i&&(i={success:i}),({success:o,message:p=""}=i),!o&&(l=!1,p=u(p)?this.getMessage(r,a):p,p=this.makeReplacements(p,r,a,h),this.#g.add(r,p),e||k.#l.includes(a)))break}return l})}if(this.#A){for(const t of e)if(!await t())break}else await Promise.allSettled(e.map(e=>e())).then(e=>{for(const t of e)if("rejected"===t.status)throw t.reason}),this.#g.sortByKeys(Object.keys(this.#u));return this.#m=[...t],this.#g}async passes(){return await this.validate(),!this.#g.isNotEmpty()}async fails(){return!await this.passes()}getMessage(e,t){if("function"==typeof t)return"";const r=this.getValue(e);let s;e=this.getPrimaryAttribute(e);for(const r of[`${e}.${t}`,t])if(Object.hasOwn(this.#h,r)){s=this.#h[r];break}if(!s){let i=t;this.sizeRules.includes(i)&&(Array.isArray(r)||o(r)||this.hasRule(e,this.arrayRules)?i+=".array":r instanceof File||this.hasRule(e,this.fileRules)?i+=".file":this.hasRule(e,this.stringRules)?i+=".string":h(r)||this.hasRule(e,this.numericRules)?i+=".numeric":i+=".string"),s=g.get(i)}return s??`validation.${t}`}makeReplacements(e,t,r,i){const c=this.getDisplayableAttribute(t),a=this.getValue(t),n={attribute:c,ATTRIBUTE:c.toLocaleUpperCase(),Attribute:c.charAt(0).toLocaleUpperCase()+c.substring(1),input:this.getDisplayableValue(t,a)};for(const[t,r]of Object.entries(n))e=e.replaceAll(":"+t,r);const l=t.match(/\.(\d+)\.?/),u=null===l?-1:parseInt(l[1],10);if(-1!==u&&(e=e.replaceAll(":index",u).replaceAll(":position",u+1)),"string"==typeof r){const c=this.#f[s("replace_"+r)]??null;c&&(e=c.call(this.#f,e,t,r,i))}return e}getDisplayableAttribute(e){const t=this.getPrimaryAttribute(e);for(const r of[e,t]){if(Object.hasOwn(this.#o,r))return this.#o[r];if(g.has(`attributes.${r}`))return g.get(`attributes.${r}`)}return Object.hasOwn(this.#k,e)?e:(r=e,r.replace(/(.)(?=[A-Z])/g,e=>e+"_").toLowerCase()).replaceAll("_"," ");var r}getDisplayableValue(e,t){const r=`${e=this.getPrimaryAttribute(e)}.${t}`;return Object.hasOwn(this.#p,r)?this.#p[r]:g.has(`values.${r}`)?g.get(`values.${r}`):u(t)?"empty":Array.isArray(t)?"array":"boolean"==typeof t||this.hasRule(e,"boolean")?Number(t)?"true":"false":t}getSize(e,t){return u(t)?0:this.hasRule(e,this.stringRules)?String(t).length:h(t)&&this.hasRule(e,this.numericRules)?parseFloat("string"==typeof t?t.trim():t,10):t instanceof File?t.size/1024:o(t)?Object.keys(t).length:Object.hasOwn(t,"length")?t.length:t}getRule(e){return e=this.getPrimaryAttribute(e),this.#u[e]??[]}hasRule(e,t){if(e=this.getPrimaryAttribute(e),t="string"==typeof t?[t]:t,!Object.hasOwn(this.#u,e))return!1;for(const r of t)if(this.#u[e].some(e=>e[0]===r))return!0;return!1}getPrimaryAttribute(e){return Object.hasOwn(this.#k,e)?this.#k[e]:e}hasAttribute(e){return void 0!==this.getValue(e)}getValue(e){return function(e,t,r){const s=t.split(".");let i=e;for(const e of s){if(null==i||!Object.hasOwn(i,e))return r;i=i[e]}return i}(this.#r,e)}errors(){return this.#g}skippedAttributes(){return this.#m}}return e.Checkers=d,e.ErrorBag=f,e.Lang=g,e.Replacers=m,e.Validator=k,e}({});
|
package/package.json
CHANGED
package/src/Checkers.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
escapeRegExp,
|
|
3
|
+
flattenObject,
|
|
4
|
+
getDecimalPlaces,
|
|
5
|
+
isDigits,
|
|
6
|
+
isEmpty,
|
|
7
|
+
isNumeric,
|
|
8
|
+
isPlainObject,
|
|
9
|
+
isValidDate,
|
|
10
|
+
parseDate,
|
|
11
|
+
parseDateByFormat,
|
|
12
|
+
} from './helpers.js';
|
|
2
13
|
|
|
3
14
|
export default class Checkers {
|
|
4
15
|
validator;
|
|
@@ -35,6 +46,20 @@ export default class Checkers {
|
|
|
35
46
|
return true;
|
|
36
47
|
}
|
|
37
48
|
|
|
49
|
+
collectPresentsThenTest(attribute, value, parameters, callback) {
|
|
50
|
+
let result = [];
|
|
51
|
+
|
|
52
|
+
for (const other of parameters) {
|
|
53
|
+
result.push(this.checkPresent(other, this.validator.getValue(other)));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (callback(result)) {
|
|
57
|
+
return this.checkPresent(attribute, value);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
38
63
|
collectMissingsThenTest(attribute, value, parameters, callback) {
|
|
39
64
|
let result = [];
|
|
40
65
|
|
|
@@ -196,8 +221,8 @@ export default class Checkers {
|
|
|
196
221
|
return false;
|
|
197
222
|
}
|
|
198
223
|
|
|
199
|
-
const numerator =
|
|
200
|
-
const denominator =
|
|
224
|
+
const numerator = Number(value);
|
|
225
|
+
const denominator = Number(parameters[0]);
|
|
201
226
|
|
|
202
227
|
if (numerator === 0 && denominator === 0) {
|
|
203
228
|
return false;
|
|
@@ -207,7 +232,10 @@ export default class Checkers {
|
|
|
207
232
|
return false;
|
|
208
233
|
}
|
|
209
234
|
|
|
210
|
-
|
|
235
|
+
const decimalPlaces = Math.max(getDecimalPlaces(numerator), getDecimalPlaces(denominator));
|
|
236
|
+
const factor = 10 ** decimalPlaces;
|
|
237
|
+
|
|
238
|
+
return Math.round(numerator * factor) % Math.round(denominator * factor) === 0;
|
|
211
239
|
}
|
|
212
240
|
|
|
213
241
|
// Agreement
|
|
@@ -326,6 +354,30 @@ export default class Checkers {
|
|
|
326
354
|
return typeof value !== 'undefined';
|
|
327
355
|
}
|
|
328
356
|
|
|
357
|
+
checkPresentIf(attribute, value, parameters) {
|
|
358
|
+
if (this.isDependent(parameters)) {
|
|
359
|
+
return this.checkPresent(attribute, value);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
return true;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
checkPresentUnless(attribute, value, parameters) {
|
|
366
|
+
if (!this.isDependent(parameters)) {
|
|
367
|
+
return this.checkPresent(attribute, value);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
checkPresentWith(attribute, value, parameters) {
|
|
374
|
+
return this.collectPresentsThenTest(attribute, value, parameters, (result) => result.includes(true));
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
checkPresentWithAll(attribute, value, parameters) {
|
|
378
|
+
return this.collectPresentsThenTest(attribute, value, parameters, (result) => !result.includes(false));
|
|
379
|
+
}
|
|
380
|
+
|
|
329
381
|
// Missing
|
|
330
382
|
checkMissing(attribute, value, parameters) {
|
|
331
383
|
return typeof value === 'undefined';
|
|
@@ -883,14 +935,14 @@ export default class Checkers {
|
|
|
883
935
|
|
|
884
936
|
const blocks = String(value)
|
|
885
937
|
.split('.')
|
|
886
|
-
.
|
|
938
|
+
.map((block) => parseInt(block, 10));
|
|
887
939
|
|
|
888
940
|
if (blocks.length !== 4) {
|
|
889
941
|
return false;
|
|
890
942
|
}
|
|
891
943
|
|
|
892
944
|
for (const block of blocks) {
|
|
893
|
-
if (block < 0 || block > 255) {
|
|
945
|
+
if (isNaN(block) || block < 0 || block > 255) {
|
|
894
946
|
return false;
|
|
895
947
|
}
|
|
896
948
|
}
|
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,3 +1,23 @@
|
|
|
1
|
+
const castToIntegers = (value) => (value && /^\d*$/.test(value) ? parseInt(value) : value);
|
|
2
|
+
|
|
3
|
+
const buildDate = (years, months, days, hours, minutes, seconds, meridiem) => {
|
|
4
|
+
if (years >= 10 && years < 100) {
|
|
5
|
+
years += 2000;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (meridiem !== null) {
|
|
9
|
+
meridiem = meridiem.toLowerCase();
|
|
10
|
+
|
|
11
|
+
if (meridiem === 'pm' && hours < 12) {
|
|
12
|
+
hours += 12;
|
|
13
|
+
} else if (meridiem === 'am' && hours === 12) {
|
|
14
|
+
hours = 0;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return new Date(`${years}-${months}-${days} ${hours}:${minutes}:${seconds}`);
|
|
19
|
+
};
|
|
20
|
+
|
|
1
21
|
export function toCamelCase(string) {
|
|
2
22
|
return string
|
|
3
23
|
.replace(/[-_]/g, ' ')
|
|
@@ -19,7 +39,7 @@ export function getByPath(obj, path, defaultValue) {
|
|
|
19
39
|
let current = obj;
|
|
20
40
|
|
|
21
41
|
for (const key of keys) {
|
|
22
|
-
if (!Object.hasOwn(current, key)) {
|
|
42
|
+
if (current === null || current === undefined || !Object.hasOwn(current, key)) {
|
|
23
43
|
return defaultValue;
|
|
24
44
|
}
|
|
25
45
|
|
|
@@ -99,19 +119,17 @@ export function parseDate(value) {
|
|
|
99
119
|
|
|
100
120
|
let match, years, months, days, hours, minutes, seconds, meridiem;
|
|
101
121
|
|
|
102
|
-
const castToIntegers = (value) => (value && /^\d*$/.test(value) ? parseInt(value) : value);
|
|
103
|
-
|
|
104
122
|
if ((match = value.match(/^(\d{1,2})[.\/-](\d{1,2})[.\/-](\d{2,4})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)) !== null) {
|
|
105
|
-
[, days, months, years, , hours = 0, minutes = 0, , seconds = 0, meridiem =
|
|
123
|
+
[, days, months, years, , hours = 0, minutes = 0, , seconds = 0, meridiem = null] = match.map(castToIntegers);
|
|
106
124
|
} else if (
|
|
107
125
|
(match = value.match(/^(\d{2,4})[.\/-](\d{1,2})[.\/-](\d{1,2})\s?((\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?)?/i)) !== null ||
|
|
108
126
|
(match = value.match(/^(\d{4})(\d{2})(\d{2})\s?((\d{2})(\d{2})((\d{2}))?\s?(am|pm)?)?/i)) !== null
|
|
109
127
|
) {
|
|
110
|
-
[, years, months, days, , hours = 0, minutes = 0, , seconds = 0, meridiem =
|
|
128
|
+
[, years, months, days, , hours = 0, minutes = 0, , seconds = 0, meridiem = null] = match.map(castToIntegers);
|
|
111
129
|
} else if ((match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{4})[.\/-](\d{2})[.\/-](\d{2})/i))) {
|
|
112
|
-
[, hours, minutes, , seconds, meridiem =
|
|
130
|
+
[, hours, minutes, , seconds, meridiem = null, years, months, days] = match.map(castToIntegers);
|
|
113
131
|
} else if ((match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?\s?(\d{2})[.\/-](\d{2})[.\/-](\d{4})/i))) {
|
|
114
|
-
[, hours, minutes, , seconds, meridiem =
|
|
132
|
+
[, hours, minutes, , seconds, meridiem = null, days, months, years] = match.map(castToIntegers);
|
|
115
133
|
} else if ((match = value.match(/(\d{1,2}):(\d{1,2})(:(\d{1,2}))?\s?(am|pm)?/i))) {
|
|
116
134
|
const current = new Date();
|
|
117
135
|
|
|
@@ -119,20 +137,12 @@ export function parseDate(value) {
|
|
|
119
137
|
months = current.getMonth() + 1;
|
|
120
138
|
days = current.getDate();
|
|
121
139
|
|
|
122
|
-
[, hours = 0, minutes = 0, , seconds = 0, meridiem =
|
|
140
|
+
[, hours = 0, minutes = 0, , seconds = 0, meridiem = null] = match.map(castToIntegers);
|
|
123
141
|
} else {
|
|
124
142
|
return new Date(value);
|
|
125
143
|
}
|
|
126
144
|
|
|
127
|
-
|
|
128
|
-
years += 2000;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (meridiem.toLowerCase() === 'pm' && hours < 12) {
|
|
132
|
-
hours += 12;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return new Date(`${years}-${months}-${days} ${hours}:${minutes}:${seconds}`);
|
|
145
|
+
return buildDate(years, months, days, hours, minutes, seconds, meridiem);
|
|
136
146
|
}
|
|
137
147
|
|
|
138
148
|
export function parseDateByFormat(value, format) {
|
|
@@ -204,7 +214,7 @@ export function parseDateByFormat(value, format) {
|
|
|
204
214
|
return new Date('');
|
|
205
215
|
}
|
|
206
216
|
|
|
207
|
-
match = match.map(
|
|
217
|
+
match = match.map(castToIntegers);
|
|
208
218
|
|
|
209
219
|
const current = new Date();
|
|
210
220
|
|
|
@@ -214,7 +224,7 @@ export function parseDateByFormat(value, format) {
|
|
|
214
224
|
let hours = match[indices.hours] ?? 0;
|
|
215
225
|
let minutes = match[indices.minutes] ?? 0;
|
|
216
226
|
let seconds = match[indices.seconds] ?? 0;
|
|
217
|
-
let meridiem = match[indices.meridiem] ??
|
|
227
|
+
let meridiem = match[indices.meridiem] ?? null;
|
|
218
228
|
|
|
219
229
|
if (!years && !months && !days) {
|
|
220
230
|
years = current.getFullYear();
|
|
@@ -231,15 +241,11 @@ export function parseDateByFormat(value, format) {
|
|
|
231
241
|
months = current.getMonth() + 1;
|
|
232
242
|
}
|
|
233
243
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (meridiem.toLowerCase() === 'pm' && hours < 12) {
|
|
239
|
-
hours += 12;
|
|
240
|
-
}
|
|
244
|
+
return buildDate(years, months, days, hours, minutes, seconds, meridiem);
|
|
245
|
+
}
|
|
241
246
|
|
|
242
|
-
|
|
247
|
+
export function getDecimalPlaces(value) {
|
|
248
|
+
return (String(value).split('.')[1] ?? '').length;
|
|
243
249
|
}
|
|
244
250
|
|
|
245
251
|
export function isDigits(value) {
|
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
|
@@ -42,6 +42,9 @@ describe('Helpers', () => {
|
|
|
42
42
|
it('getByPath', () => {
|
|
43
43
|
assert.equal(getByPath({ a: { b: 1 } }, 'a.b'), 1);
|
|
44
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');
|
|
45
48
|
});
|
|
46
49
|
|
|
47
50
|
it('setByPath', () => {
|
|
@@ -129,6 +132,16 @@ describe('Helpers', () => {
|
|
|
129
132
|
assert.deepEqual(parseDate('08:40:50 am'), date3);
|
|
130
133
|
assert.deepEqual(parseDate('08:40:50'), date3);
|
|
131
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);
|
|
140
|
+
|
|
141
|
+
const date5 = new Date('2026/01/03 12:10:17');
|
|
142
|
+
assert.deepEqual(parseDate('2026-01-03 12:10:17'), date5);
|
|
143
|
+
assert.deepEqual(parseDate('03-01-2026 12:10:17'), date5);
|
|
144
|
+
assert.deepEqual(parseDate('12:10:17 2026-01-03'), date5);
|
|
132
145
|
});
|
|
133
146
|
|
|
134
147
|
it('parseDateByFormat', () => {
|
|
@@ -146,6 +159,12 @@ describe('Helpers', () => {
|
|
|
146
159
|
assert.deepEqual(parseDateByFormat('08-11-23 08:40:50', 'm-d-y H:i:s'), date2);
|
|
147
160
|
assert.deepEqual(parseDateByFormat('08-11-2023 08:40:50 am', 'm-d-Y H:i:s a'), date2);
|
|
148
161
|
assert.deepEqual(parseDateByFormat('08-11-23 08:40:50 am', 'm-d-y H:i:s a'), date2);
|
|
162
|
+
|
|
163
|
+
const date4 = new Date('2023/08/11 00:30:00');
|
|
164
|
+
assert.deepEqual(parseDateByFormat('08-11-2023 12:30:00 am', 'm-d-Y H:i:s a'), date4);
|
|
165
|
+
|
|
166
|
+
const date5 = new Date('2026/01/03 12:10:17');
|
|
167
|
+
assert.deepEqual(parseDateByFormat('01-03-2026 12:10:17', 'm-d-Y H:i:s'), date5);
|
|
149
168
|
});
|
|
150
169
|
|
|
151
170
|
it('isDigits', () => {
|
package/test/validation.js
CHANGED
|
@@ -1553,6 +1553,14 @@ describe('Validation', () => {
|
|
|
1553
1553
|
validator = new Validator({ field: '...' }, rules);
|
|
1554
1554
|
assert(await validator.fails());
|
|
1555
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
|
+
});
|
|
1556
1564
|
});
|
|
1557
1565
|
|
|
1558
1566
|
describe(`Rule 'ipv6'`, () => {
|
|
@@ -2296,6 +2304,19 @@ describe('Validation', () => {
|
|
|
2296
2304
|
validator.setProperties({ field: 58 }, { field: 'multiple_of:11' });
|
|
2297
2305
|
assert(await validator.fails());
|
|
2298
2306
|
});
|
|
2307
|
+
|
|
2308
|
+
it(`Passes when decimal value is multiple of decimal parameter`, async () => {
|
|
2309
|
+
const validator = new Validator({ field: 0.3 }, { field: 'multiple_of:0.1' });
|
|
2310
|
+
assert(await validator.passes());
|
|
2311
|
+
|
|
2312
|
+
validator.setProperties({ field: 5 }, { field: 'multiple_of:2.5' });
|
|
2313
|
+
assert(await validator.passes());
|
|
2314
|
+
});
|
|
2315
|
+
|
|
2316
|
+
it(`Fails when decimal value is not multiple of decimal parameter`, async () => {
|
|
2317
|
+
const validator = new Validator({ field: 0.75 }, { field: 'multiple_of:0.5' });
|
|
2318
|
+
assert(await validator.fails());
|
|
2319
|
+
});
|
|
2299
2320
|
});
|
|
2300
2321
|
|
|
2301
2322
|
describe(`Rule 'not_in'`, () => {
|
|
@@ -2414,6 +2435,162 @@ describe('Validation', () => {
|
|
|
2414
2435
|
});
|
|
2415
2436
|
});
|
|
2416
2437
|
|
|
2438
|
+
describe(`Rule 'present_if'`, () => {
|
|
2439
|
+
const rules = { field: 'present_if:other,foo,bar' };
|
|
2440
|
+
|
|
2441
|
+
it(`Passes when the field is present and the other field's value is equal to the first value`, async () => {
|
|
2442
|
+
const validator = new Validator({ field: '', other: 'foo' }, rules);
|
|
2443
|
+
assert(await validator.passes());
|
|
2444
|
+
});
|
|
2445
|
+
|
|
2446
|
+
it(`Passes when the field is present and the other field's value is equal to the second value`, async () => {
|
|
2447
|
+
const validator = new Validator({ field: '', other: 'bar' }, rules);
|
|
2448
|
+
assert(await validator.passes());
|
|
2449
|
+
});
|
|
2450
|
+
|
|
2451
|
+
it(`Passes when the field is not present and the other field's value is not equal to any value`, async () => {
|
|
2452
|
+
const validator = new Validator({ other: 'bob' }, rules);
|
|
2453
|
+
assert(await validator.passes());
|
|
2454
|
+
});
|
|
2455
|
+
|
|
2456
|
+
it(`Passes when the field is present and the other field's value is not equal to any value`, async () => {
|
|
2457
|
+
const validator = new Validator({ field: '', other: 'bob' }, rules);
|
|
2458
|
+
assert(await validator.passes());
|
|
2459
|
+
});
|
|
2460
|
+
|
|
2461
|
+
it(`Fails when the field is not present and the other field's value is equal to any value`, async () => {
|
|
2462
|
+
const validator = new Validator({ other: 'foo' }, rules);
|
|
2463
|
+
assert(await validator.fails());
|
|
2464
|
+
});
|
|
2465
|
+
|
|
2466
|
+
const rules2 = { field: ['present_if:other1,foo,bar', 'present_if:other2,win,amp'] };
|
|
2467
|
+
|
|
2468
|
+
it(`Passes when the field is not present and other fields' value are not equal to provided values`, async () => {
|
|
2469
|
+
const validator = new Validator({ other1: 'baz', other2: 'rar' }, rules2);
|
|
2470
|
+
assert(await validator.passes());
|
|
2471
|
+
});
|
|
2472
|
+
|
|
2473
|
+
it(`Fails when the field is not present and other fields' value are equal to provided values`, async () => {
|
|
2474
|
+
const validator = new Validator({ other1: 'foo', other2: 'win' }, rules2);
|
|
2475
|
+
assert(await validator.fails());
|
|
2476
|
+
});
|
|
2477
|
+
|
|
2478
|
+
it(`Fails when the field is not present and any other fields' value is equal to provided value`, async () => {
|
|
2479
|
+
const validator = new Validator({ other1: 'foo', other2: 'rar' }, rules2);
|
|
2480
|
+
assert(await validator.fails());
|
|
2481
|
+
|
|
2482
|
+
validator.setData({ other1: 'baz', other2: 'win' });
|
|
2483
|
+
assert(await validator.fails());
|
|
2484
|
+
});
|
|
2485
|
+
});
|
|
2486
|
+
|
|
2487
|
+
describe(`Rule 'present_unless'`, () => {
|
|
2488
|
+
const rules = { field: 'present_unless:other,foo,bar' };
|
|
2489
|
+
|
|
2490
|
+
it(`Passes when the field is not present and the other field's value is equal to the first value`, async () => {
|
|
2491
|
+
const validator = new Validator({ other: 'foo' }, rules);
|
|
2492
|
+
assert(await validator.passes());
|
|
2493
|
+
});
|
|
2494
|
+
|
|
2495
|
+
it(`Passes when the field is not present and the other field's value is equal to the second value`, async () => {
|
|
2496
|
+
const validator = new Validator({ other: 'bar' }, rules);
|
|
2497
|
+
assert(await validator.passes());
|
|
2498
|
+
});
|
|
2499
|
+
|
|
2500
|
+
it(`Passes when the field is present and the other field's value is not equal to any value`, async () => {
|
|
2501
|
+
const validator = new Validator({ field: '', other: 'bob' }, rules);
|
|
2502
|
+
assert(await validator.passes());
|
|
2503
|
+
});
|
|
2504
|
+
|
|
2505
|
+
it(`Fails when the field is not present and the other field's value is not equal to any value`, async () => {
|
|
2506
|
+
const validator = new Validator({ other: 'bob' }, rules);
|
|
2507
|
+
assert(await validator.fails());
|
|
2508
|
+
});
|
|
2509
|
+
|
|
2510
|
+
const rules2 = { field: ['present_unless:other1,foo,bar', 'present_unless:other2,win,amp'] };
|
|
2511
|
+
|
|
2512
|
+
it(`Passes when the field is not present and other fields' value are equal to provided values`, async () => {
|
|
2513
|
+
const validator = new Validator({ other1: 'foo', other2: 'win' }, rules2);
|
|
2514
|
+
assert(await validator.passes());
|
|
2515
|
+
});
|
|
2516
|
+
|
|
2517
|
+
it(`Fails when the field is not present and other fields' value are not equal to provided values`, async () => {
|
|
2518
|
+
const validator = new Validator({ other1: 'baz', other2: 'rar' }, rules2);
|
|
2519
|
+
assert(await validator.fails());
|
|
2520
|
+
});
|
|
2521
|
+
|
|
2522
|
+
it(`Fails when the field is not present and any other fields' value is not equal to provided value`, async () => {
|
|
2523
|
+
const validator = new Validator({ other1: 'foo', other2: 'rar' }, rules2);
|
|
2524
|
+
assert(await validator.fails());
|
|
2525
|
+
|
|
2526
|
+
validator.setData({ other1: 'baz', other2: 'win' });
|
|
2527
|
+
assert(await validator.fails());
|
|
2528
|
+
});
|
|
2529
|
+
});
|
|
2530
|
+
|
|
2531
|
+
describe(`Rule 'present_with'`, () => {
|
|
2532
|
+
const rules = { field: 'present_with:foo,bar' };
|
|
2533
|
+
|
|
2534
|
+
it(`Passes when the field is present and the first other field is present`, async () => {
|
|
2535
|
+
const validator = new Validator({ field: '', foo: 'abc' }, rules);
|
|
2536
|
+
assert(await validator.passes());
|
|
2537
|
+
});
|
|
2538
|
+
|
|
2539
|
+
it(`Passes when the field is present and the second other field is present`, async () => {
|
|
2540
|
+
const validator = new Validator({ field: '', bar: 123 }, rules);
|
|
2541
|
+
assert(await validator.passes());
|
|
2542
|
+
});
|
|
2543
|
+
|
|
2544
|
+
it(`Passes when the field is present and all other fields are not present`, async () => {
|
|
2545
|
+
const validator = new Validator({ field: '' }, rules);
|
|
2546
|
+
assert(await validator.passes());
|
|
2547
|
+
});
|
|
2548
|
+
|
|
2549
|
+
it(`Passes when the field is not present and all other fields are not present`, async () => {
|
|
2550
|
+
const validator = new Validator({}, rules);
|
|
2551
|
+
assert(await validator.passes());
|
|
2552
|
+
});
|
|
2553
|
+
|
|
2554
|
+
it(`Fails when the field is not present and the first other field is present`, async () => {
|
|
2555
|
+
const validator = new Validator({ foo: 'abc' }, rules);
|
|
2556
|
+
assert(await validator.fails());
|
|
2557
|
+
});
|
|
2558
|
+
|
|
2559
|
+
it(`Fails when the field is not present and the second other field is present`, async () => {
|
|
2560
|
+
const validator = new Validator({ bar: 123 }, rules);
|
|
2561
|
+
assert(await validator.fails());
|
|
2562
|
+
});
|
|
2563
|
+
});
|
|
2564
|
+
|
|
2565
|
+
describe(`Rule 'present_with_all'`, () => {
|
|
2566
|
+
const rules = { field: 'present_with_all:foo,bar' };
|
|
2567
|
+
|
|
2568
|
+
it(`Passes when the field is present and all other fields are present`, async () => {
|
|
2569
|
+
const validator = new Validator({ field: '', foo: 'abc', bar: 123 }, rules);
|
|
2570
|
+
assert(await validator.passes());
|
|
2571
|
+
});
|
|
2572
|
+
|
|
2573
|
+
it(`Passes when the field is present and any other field is present`, async () => {
|
|
2574
|
+
const validator = new Validator({ field: '', foo: 'abc' }, rules);
|
|
2575
|
+
assert(await validator.passes());
|
|
2576
|
+
});
|
|
2577
|
+
|
|
2578
|
+
it(`Passes when the field is not present and all other fields are not present`, async () => {
|
|
2579
|
+
const validator = new Validator({}, rules);
|
|
2580
|
+
assert(await validator.passes());
|
|
2581
|
+
});
|
|
2582
|
+
|
|
2583
|
+
it(`Passes when the field is not present and any other field is not present`, async () => {
|
|
2584
|
+
const validator = new Validator({ foo: 'abc' }, rules);
|
|
2585
|
+
assert(await validator.passes());
|
|
2586
|
+
});
|
|
2587
|
+
|
|
2588
|
+
it(`Fails when the field is not present and all other fields are present`, async () => {
|
|
2589
|
+
const validator = new Validator({ foo: 'abc', bar: 123 }, rules);
|
|
2590
|
+
assert(await validator.fails());
|
|
2591
|
+
});
|
|
2592
|
+
});
|
|
2593
|
+
|
|
2417
2594
|
describe(`Rule 'prohibited'`, () => {
|
|
2418
2595
|
const rules = { field: 'prohibited' };
|
|
2419
2596
|
|