DEV Community

Cover image for Unleashing the Power of `is.edge` and `is.not_edge` with 'thiis': Your Gateway to JavaScript Magic
Ivan Karbashevskyi
Ivan Karbashevskyi

Posted on

Unleashing the Power of `is.edge` and `is.not_edge` with 'thiis': Your Gateway to JavaScript Magic

JavaScript is a magical realm, and as developers, we often find ourselves at the edge of possibilities. Introducing the is.edge method and its trusty companion, is.not_edge from the 'thiis' package! In this article, we'll embark on an enchanting journey, exploring these tools that open up new dimensions of JavaScript. Get ready for a ride that transcends the ordinary!

The Edge of JavaScript Sorcery

Before we delve into the enchanting world of is.edge and is.not_edge, let's briefly talk about the concept of the "edge." In the magical realm of JavaScript, the "edge" represents the cutting edge, the forefront of innovation, and the boundary of what's possible. These methods act as your magical lenses, helping you perceive the edge with clarity.

Meet is.edge - Your Portal to the Edge

Documentation link

Imagine you're standing at the edge of a mystical realm, and you want to ensure that a value is truly at the edge. The is.edge method acts as your magical portal, allowing you to confirm if a value is genuinely on the edge. Let the magic unfold:

import { is } from 'thiis'; // Import the "is" object from the "thiis" package

const myValue = 'cutting-edge';
const result = is.edge(myValue);

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.edge method to confirm that myValue is indeed on the edge. As expected, it returns true because the value is genuinely at the edge.

The Journey of Examples

Now, let's embark on a captivating journey through six examples that showcase the versatility of is.edge and its counterpart, is.not_edge. Our journey will include scenarios from the magical realm of streams and the mystical arrays.

1. Unleashing the Cutting Edge

The primary role of is.edge is to unveil the cutting edge. It helps you confirm when a value is truly at the edge, sparking the magic:

import { is } from 'thiis';

const cuttingEdgeValue = someFunctionThatMayReturnCuttingEdge();

if (is.edge(cuttingEdgeValue)) {
  // Witness the magic of the cutting edge!
} else {
  // Continue your exploration with curiosity.
Enter fullscreen mode Exit fullscreen mode

2. Guarding Against the Ordinary

Conversely, is.not_edge serves as your guardian against the ordinary. It ensures that a value isn't just any value, but rather, something extraordinary:

import { is } from 'thiis';

const extraordinaryValue = someFunctionThatShouldNotBeOrdinary();

if (is.not_edge(extraordinaryValue)) {
  // Your guardian prevents the ordinary from seeping in!
} else {
  // Time to explore other extraordinary possibilities.
Enter fullscreen mode Exit fullscreen mode

3. Magical Validation with is.edge

When working with user input, ensuring that the input is at the edge is crucial for unleashing magic. Use is.edge to validate and handle situations where the input might be truly extraordinary:

import { is } from 'thiis';

function validateUserInput(input) {
  if (is.edge(input)) {
    return 'Your input is magically extraordinary!';
  } else {
    return 'Please provide input worthy of the magical realm.';
Enter fullscreen mode Exit fullscreen mode

4. Masterful Conditionals with is.not_edge

In the world of conditionals, ensure that a value is not just any value before executing specific magical actions with is.not_edge:

import { is } from 'thiis';

const userChoice = getUserInput();

if (is.not_edge(userChoice)) {
  // Execute magical actions for extraordinary choices.
} else {
  // Handle other scenarios with grace and wonder.
Enter fullscreen mode Exit fullscreen mode

5. Mystical Streams with is.edge

Let's explore a scenario involving stream$ from RxJS. Using filter and is.edge, we can ensure that the stream processes only values truly at the edge:

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

const stream$ = from(['ordinary', 'mystical', 'cutting-edge', 'extraordinary']);

  .subscribe(value => {
    console.log(value); // Only values truly at the edge will be part of the stream's enchanting journey.
Enter fullscreen mode Exit fullscreen mode

In this example, the filter(is.edge) ensures that only values truly at the edge get processed by the stream.

6. Array Alchemy with is.not_edge

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

import { is } from 'thiis';

const notEdgeArray = ['ordinary', 'extraordinary', 'magical'];
const mixedArray = ['ordinary', 'ordinary', 'ordinary', 'extraordinary'];

const allElementsNotEdge = notEdgeArray.every(is.not_edge); // true
const someElementsNotEdge = mixedArray.some(is.not_edge); // true

Enter fullscreen mode Exit fullscreen mode

Here, allElementsNotEdge checks if all elements in notEdgeArray are not just any elements, and someElementsNotEdge checks if at least one element in mixedArray isn't just any element.

The Magical Continuation

The is.edge and is.not_edge methods from the 'thiis' package are your mystical companions in the world of JavaScript magic. They make type checking a delightful experience, ensuring your code interacts with values at the edge with grace and wonder. By adding the 'thiis' package to your JavaScript toolkit and exploring its

documentation for more tips and examples, you can navigate the JavaScript magical realm with confidence and a touch of enchantment.

So, keep weaving your spells with JavaScript, and remember that the magic never ends!

🎗 ChatGPT & DALL·E 3

Top comments (1)

karbashevskyi profile image
Ivan Karbashevskyi

Telegram channel: