File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,8 @@ All features with links to their page in the documentation:
50
50
Whether the string is a valid strong password.
51
51
- #### [ toNullIfBlank()] ( https://pub.dev/documentation/fleasy/latest/fleasy/NullableStringExtensions/toNullIfBlank.html )
52
52
Returns null if the string ` isBlank ` or it's text if it ` isNotBlank ` .
53
+ - #### [ addHttps()] ( https://pub.dev/documentation/fleasy/latest/fleasy/StringExtensions/addHttps.html )
54
+ Adds https:// to the link if it does not contain https:// or http:// already. This is helpful to make a link openable when using the [ url_launcher] ( https://pub.dev/packages/url_launcher ) package for example.
53
55
54
56
55
57
- ### Extensions on ` DateTime ` :
Original file line number Diff line number Diff line change @@ -52,6 +52,13 @@ extension StringExtensions on String {
52
52
/// - at least 1 number
53
53
/// - at least 1 special character
54
54
bool get isStrongPassword => _strongPasswordRegExp.hasMatch (this );
55
+
56
+ /// Adds https:// to the link if it does not contain https:// or http:// already..
57
+ ///
58
+ /// This is helpful to make a link openable when using the [url_launcher] (https://pub.dev/packages/url_launcher) package for example.
59
+ String addHttps () {
60
+ return contains ('https://' ) || contains ('http://' ) ? this : 'https://$this ' ;
61
+ }
55
62
}
56
63
57
64
extension NullableStringExtensions on String ? {
Original file line number Diff line number Diff line change @@ -159,4 +159,24 @@ void main() {
159
159
expect (password.isStrongPassword, equals (false ));
160
160
});
161
161
});
162
+
163
+ group ('addHttps' , () {
164
+ test ('adds https:// when there is no http:// or https://.' , () {
165
+ const url = 'www.jensbecker.dev' ;
166
+
167
+ expect (url.addHttps (), equals ('https://www.jensbecker.dev' ));
168
+ });
169
+
170
+ test ('does not add https:// when there is http:// already.' , () {
171
+ const url = 'http://www.jensbecker.dev' ;
172
+
173
+ expect (url.addHttps (), equals (url));
174
+ });
175
+
176
+ test ('does not add https:// when there is https:// already.' , () {
177
+ const url = 'https://www.jensbecker.dev' ;
178
+
179
+ expect (url.addHttps (), equals (url));
180
+ });
181
+ });
162
182
}
You can’t perform that action at this time.
0 commit comments