๐ง is.len_
๐ Descriptionโ
the is.len_
magic method is good because it has more variations and will help to read the code more easily and build various validations in a simpler way. This method is actually a template, but it has several templates, it first of all checks the length of the string, that is, let's say there is a text "some text" that has 9 characters (including the space) and we want to check it, how do we do it in classic way?
Answer: if("some text".length === 9) {}
What if with a magic method?
Answer: if(is.len_9("some text")) {}
Not bad, right?
In addition, there are 7 methods besides this one (i.e. there are 8 in total):
len_gt_N_lt_N
,len_lt_N
,len_gt_N
,len_gte_N_lt_N
,len_gte_N_lte_N
,len_lte_N
,len_gte_N
,len_gt_N_lte_N
;
Explanation:
- The letter N is taken from math - Natural_number. That is, you need to replace it with what you need.
- gt - More than.
- lt - Less than
- lte - Less than or equal to
- gte - Greater than or equal to
Remember that this method can be combined with other methods, for example: is.string.len_gt_60_lte_120($variable)
Exampleโ
input$.pipe(filter(is.len_gte_3_lte_10))
input$.pipe(filter(is.string.len_gte_3_lte_10))
input$.pipe(filter(is.len_gte_900))
if (is.len_lt_10($text)) {
// ...
}