Unlock the Magic of is.lowerCase and is.not_lowerCase in JavaScript with 'thiis': Your Friendly Guide to String Checks

karbashevskyi

Ivan Karbashevskyi

Posted on December 2, 2023

Unlock the Magic of is.lowerCase and is.not_lowerCase in JavaScript with 'thiis': Your Friendly Guide to String Checks

JavaScript is a language of possibilities, and when it comes to handling strings, having tools that simplify the checks can make coding a joyous journey. Enter the is.lowerCase method from the 'thiis' package - your trusty sidekick for checking if a string is in lowercase. In this article, we'll explore the wonders of is.lowerCase along with its companion, is.not_lowerCase, in various scenarios that showcase their versatility and playfulness.

Embracing Lowercase in JavaScript

Image description

Before we dive into the magical world of is.lowerCase, let's take a moment to appreciate the importance of lowercase letters in strings. In JavaScript, strings are case-sensitive, and knowing whether a string is in lowercase or not can be crucial for validation, formatting, and more.

Meet is.lowerCase - Your Lowercase Guru

Documentation link

Imagine you're on a quest to ensure that a string is in all lowercase glory. The is.lowerCase method is your guru, here to confirm if a string is, indeed, in lowercase. Let's witness its magic:

import { is } from 'thiis';

const myString = 'hellothere';
const result = is.lowerCase(myString);

console.log(result); // true
Enter fullscreen mode Exit fullscreen mode

In this example, we import the "is" object from the "thiis" package and use the is.lowerCase method to confirm that myString is indeed in lowercase. As expected, it returns true.

The Tale of Examples

Now, let's embark on a journey through several examples that showcase the charm of is.lowerCase and its companion, is.not_lowerCase. We'll explore six unique scenarios, including some playful combinations.

1. Basic Lowercase Validation

The primary role of is.lowerCase is to validate if a string is in lowercase. It helps you confirm when a string is all lowercase, which can be essential for consistent data:

import { is } from 'thiis';

const lowercaseString = 'hellothere';
const mixedCaseString = 'HelloThere';

console.log(is.lowerCase(lowercaseString)); // true
console.log(is.lowerCase(mixedCaseString)); // false
Enter fullscreen mode Exit fullscreen mode

2. Guarding Against Lowercase

Conversely, is.not_lowerCase serves as your guardian against strings that are in lowercase. It's handy when you want to ensure that a string isn't in lowercase before proceeding:

import { is } from 'thiis';

const importantString = 'ImportantString';
const regularString = 'justaregularstring';

console.log(is.not_lowerCase(importantString)); // true
console.log(is.not_lowerCase(regularString)); // false
Enter fullscreen mode Exit fullscreen mode

3. Creative Combos with is.kebabCases_or_lowerCase

Mixing and matching methods can be powerful. For instance, you can use is.kebabCases_or_lowerCase to check if a string is either in kebab case or all lowercase:

import { is } from 'thiis';

const kebabCaseString = 'kebab-case-string';
const randomString = 'RandomString';

console.log(is.kebabCases_or_lowerCase(kebabCaseString)); // true
console.log(is.kebabCases_or_lowerCase(randomString)); // false
Enter fullscreen mode Exit fullscreen mode

4. Stream of Lowercase with is.lowerCase

Let's explore a scenario involving stream$ from RxJS. Using filter and is.lowerCase, we can ensure that the stream processes only strings in lowercase:

import { is } from 'thiis';
import { from } from 'rxjs';
import { filter } from 'rxjs/operators';

const stream$ = from(['lowercase', 'NotLowerCase', 'anotherlowercase']);

stream$
  .pipe(
    filter(value => is.lowerCase(value))
  )
  .subscribe(lowerCaseValue => {
    console.log(lowerCaseValue); // Only lowercase strings will be part of the stream's story.
  });
Enter fullscreen mode Exit fullscreen mode

5. Array Exploration with is.not_lowerCase

Arrays are another playground for is.not_lowerCase. You can use every() to confirm that all elements are not in lowercase and some() to check if at least one isn't:

import { is } from 'thiis';

const notLowerCaseArray = ['Uppercase', 'NotLowerCase', 'RandomString'];
const mixedCaseArray = ['AnotherMixedCase', 'AlsoNotLowerCase', 'lowercase'];

const allElementsNotLowerCase = notLowerCaseArray.every(is.not_lowerCase); // true
const someElementsNotLowerCase = mixedCaseArray.some(is.not_lowerCase); // true

console.log(allElementsNotLowerCase);
console.log(someElementsNotLowerCase);
Enter fullscreen mode Exit fullscreen mode

6. String Transformation with is.lowerCase

Sometimes, you might want to transform a string into lowercase only if it's not already in that form. is.lowerCase can guide your transformation decisions:

import { is } from 'thiis';

function transformToLowerCase(input) {
  return is.lowerCase(input) ? input : input.toLowerCase();
}

console.log(transformToLowerCase('AlreadyLowerCase')); // 'AlreadyLowerCase'
console.log(transformToLowerCase('MakeMeLowerCase')); // 'makemelowercase'
Enter fullscreen mode Exit fullscreen mode

The Adventure Continues

The is.lowerCase and is.not_lowerCase methods from the 'thiis' package are your reliable companions on your JavaScript adventure. They make string checks playful and precise, ensuring your code interacts with lowercase strings exactly as intended. By adding the 'thiis' package to your JavaScript toolkit and exploring its documentation for more tips and examples, you can navigate the JavaScript landscape with confidence and creativity.

So, keep coding, and remember that the world of JavaScript is full of delightful discoveries!

🎗 ChatGPT & DALL·E 3

💖 💪 🙅 🚩
karbashevskyi
Ivan Karbashevskyi

Posted on December 2, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related