capitalize
Capitalizes the first character of a string, with an option to preserve or lowercase the remaining characters.
Import
Section titled “Import”import { capitalize } from "1o1-utils";import { capitalize } from "1o1-utils/capitalize";Signature
Section titled “Signature”function capitalize({ str, preserveRest }: CapitalizeParams): stringParameters
Section titled “Parameters”| Name | Type | Required | Description |
|---|---|---|---|
| str | string | Yes | The string to capitalize |
| preserveRest | boolean | No | If true, keeps the rest of the string as-is; if false, lowercases it (default: false) |
Returns
Section titled “Returns”string
Examples
Section titled “Examples”capitalize({ str: "hello" });// => "Hello"
capitalize({ str: "hELLO", preserveRest: true });// => "HELLO" — rest preserved
capitalize({ str: "hELLO" });// => "Hello" — rest lowercasedEdge Cases
Section titled “Edge Cases”- Throws if
stris not a string. - Returns
""for empty string.
Also known as
Section titled “Also known as”uppercase first, first letter uppercase, initial cap
Prompt suggestion
Section titled “Prompt suggestion”I'm using 1o1-utils (npm: https://www.npmjs.com/package/1o1-utils, GitHub: https://github.com/pedrotroccoli/1o1-utils, LLM context: https://pedrotroccoli.github.io/1o1-utils/llms.txt). Show me how to use capitalize to format user display names