> For AI agents: the complete documentation index is available at https://massaman.dev/llms.txt, the full documentation bundle is available at https://massaman.dev/llms-full.txt.

# capitalize es-toolkit

Converts the first character of a string to uppercase and the remaining characters to lowercase.

```typescript
const result = capitalize(str);
```

## Usage

### `capitalize(str)`

Use `capitalize` when you want to make only the first letter uppercase and convert the rest to lowercase. It's useful for normalizing names or titles.

```typescript
import { capitalize } from 'es-toolkit/string';

// Basic usage
capitalize('hello'); // returns 'Hello'
capitalize('WORLD'); // returns 'World'
capitalize('javaScript'); // returns 'Javascript'
```

It also handles empty strings and single character strings correctly.

```typescript
import { capitalize } from 'es-toolkit/string';

capitalize(''); // returns ''
capitalize('a'); // returns 'A'
capitalize('A'); // returns 'A'
```

You can use it to normalize user input or create titles.

```typescript
import { capitalize } from 'es-toolkit/string';

// Normalize user names
const userName = 'john DOE';
const formattedName = userName.split(' ').map(capitalize).join(' ');
// returns 'John Doe'

// Create titles
const title = capitalize('welcome to our website');
// returns 'Welcome to our website'
```

#### Parameters


strstringrequired

The string to capitalize the first character.

#### Returns

Returns a new string with the first character capitalized and the rest in lowercase.

```typescript
string
```


Source: es-toolkit

Re-exported verbatim from [`es-toolkit`](https://es-toolkit.dev/reference/string/capitalize.html). Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.
