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.

TYPESCRIPT

Routing & Navigation

isRouteActive()

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

Parameters
  • 1
    targetLink - The link to check against
  • 2
    currentRoute - The current route
  • 3
    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.

TYPESCRIPT

decrypt(encryptedText)

Decrypts previously encrypted text.

TYPESCRIPT

String Manipulation

slugify(text)

Converts text into URL-friendly slugs.

TYPESCRIPT

capitalizeFirstLetter(str)

Capitalizes the first letter of a string.

TYPESCRIPT

Validation

Regular Expressions

  • 1
    nameRegex - Validates names (letters, numbers, spaces, hyphens)
  • 2
    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.

Key Features

🧩

Modular Design

Small, focused utilities that do one thing well

🔄

Type Safety

Full TypeScript support with proper type definitions

🛡️

Error Handling

Robust error handling with meaningful messages

📦

Zero Dependencies

Minimal external dependencies for core utilities