Utility Functions

A collection of utility functions used throughout the application for common tasks like styling, routing, encryption, and string manipulation.

Styling Utilities

cn(...inputs)

Combines Tailwind classes using clsx and tailwind-merge for conflict resolution.

cn("text-red-500", "bg-blue-500", className)

Routing & Navigation

isRouteActive(targetLink, currentRoute, depth)

Checks if a route is active based on the current path and specified depth.

Parameters
  • targetLink - The link to check against
  • currentRoute - The current route
  • depth - How far down segments should be matched

pagePathname(metaUrl)

Extracts the page pathname based on file location in the app directory.

Encryption & Security

encrypt(text)

Encrypts text using AES-256-CTR algorithm.

const encrypted = encrypt("sensitive data");

decrypt(encryptedText)

Decrypts previously encrypted text.

const decrypted = decrypt(encrypted);

String Manipulation

slugify(text)

Converts text into URL-friendly slugs.

slugify("Hello World!") // returns "hello-world"

capitalizeFirstLetter(str)

Capitalizes the first letter of a string.

capitalizeFirstLetter("hello") // returns "Hello"

Validation

Regular Expressions

  • nameRegex - Validates names (letters, numbers, spaces, hyphens)
  • slugRegex - Validates URL-friendly slugs

transformErrorToDetails(error)

Transforms Zod validation errors into readable strings.

Image & URL Utilities

placeholderImageUrl(options)

Generates placeholder image URLs with customizable colors and text.

absoluteUrl(path)

Converts relative paths to absolute URLs using the app's base URL.