Skip to main content
Version: 1.0.2

๐Ÿงž 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):

  1. len_gt_N_lt_N,
  2. len_lt_N,
  3. len_gt_N,
  4. len_gte_N_lt_N,
  5. len_gte_N_lte_N,
  6. len_lte_N,
  7. len_gte_N,
  8. len_gt_N_lte_N;

Explanation:

  1. The letter N is taken from math - Natural_number. That is, you need to replace it with what you need.
  2. gt - More than.
  3. lt - Less than
  4. lte - Less than or equal to
  5. 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)) {
// ...
}