Capitalize

Next

Capitalize the first letter of a string.

Docs
utilcnlib

Preview

Loading preview…
registry/default/strings/capitalize.ts
/**
 * Capitalizes the first character of a string.
 *
 * @param str - The input string.
 * @returns The string with the first character uppercased.
 *
 * @example
 * capitalize("typescript"); // "Typescript"
 */
export function capitalize(str: string): string {
  if (!str) return '';
  return str.charAt(0).toUpperCase() + str.slice(1);
}

Installation

npx shadcn@latest add @utilcn/capitalize

Usage

import { Capitalize } from "@/lib/capitalize"
Capitalize()