@@ -13,6 +13,12 @@ final RegExp _strongPasswordRegExp =
13
13
RegExp (r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_])\S{8,}$' );
14
14
15
15
extension StringExtensions on String {
16
+ /// Whether the string contains characters except of whitespace characters.
17
+ bool get isNotBlank => trim ().isNotEmpty;
18
+
19
+ /// Whether the string is either empty or solely made of whitespace characters.
20
+ bool get isBlank => trim ().isEmpty;
21
+
16
22
/// Whether the string is a valid email.
17
23
bool get isEmail => _emailRegExp.hasMatch (this );
18
24
@@ -49,13 +55,13 @@ extension StringExtensions on String {
49
55
}
50
56
51
57
extension NullableStringExtensions on String ? {
52
- /// Whether the string is not null nor empty .
53
- bool get isNotBlank => this != null && this ! .isNotEmpty;
58
+ /// Whether the string is not null and contains characters except of whitespace characters .
59
+ bool get isNotBlank => this != null && this ! .trim (). isNotEmpty;
54
60
55
- /// Whether the string is null or empty .
61
+ /// Whether the string is either null, empty or is solely made of whitespace characters .
56
62
bool get isBlank => ! isNotBlank;
57
63
58
- /// Returns null if the string is blank (empty or null) or it's text if not .
64
+ /// Returns null if the string [isBlank] or it's text if it [isNotBlank] .
59
65
String ? toNullIfBlank () => isNotBlank ? this : null ;
60
66
61
67
/// Whether the string is not null and a valid email.
@@ -64,18 +70,24 @@ extension NullableStringExtensions on String? {
64
70
/// Whether the string is not null and a valid url.
65
71
bool get isUrl => this != null ? this ! .isUrl : false ;
66
72
67
- /// Whether the string is a valid medium password.
73
+ /// Whether the string is not null and a valid easy password.
74
+ ///
75
+ /// Requirements:
76
+ /// - minimum 8 characters
77
+ /// - no whitespaces
78
+ bool get isEasyPassword => this != null ? this ! .isEasyPassword : false ;
79
+
80
+ /// Whether the string is not null and a valid medium password.
68
81
///
69
82
/// Requirements:
70
83
/// - minimum 8 characters
71
84
/// - no whitespaces
72
85
/// - at least 1 uppercase letter
73
86
/// - at least 1 lowercase letter
74
87
/// - at least 1 number
75
- bool get isMediumPassword =>
76
- this != null ? _mediumPasswordRegExp.hasMatch (this ! ) : false ;
88
+ bool get isMediumPassword => this != null ? this ! .isMediumPassword : false ;
77
89
78
- /// Whether the string is a valid strong password.
90
+ /// Whether the string is is not null and a valid strong password.
79
91
///
80
92
/// Requirements:
81
93
/// - minimum 8 characters
@@ -84,6 +96,5 @@ extension NullableStringExtensions on String? {
84
96
/// - at least 1 lowercase letter
85
97
/// - at least 1 number
86
98
/// - at least 1 special character
87
- bool get isStrongPassword =>
88
- this != null ? _strongPasswordRegExp.hasMatch (this ! ) : false ;
99
+ bool get isStrongPassword => this != null ? this ! .isStrongPassword : false ;
89
100
}
0 commit comments