Skip to content

Strings

capitalize

1.0.0

Capitalizes the first letter of a string while leaving the rest of the string unchanged.

capitalize(/str/);
  • Capitalizes only the first character of a string
  • Preserves the original casing of the rest of the string
  • Returns empty string for non-string inputs
  • Handles empty strings gracefully
  • Simple and intuitive API
  • No side effects - does not modify original string
  • Lightweight and performant
  • Comprehensive testing
ArgTypeDefault ValueRequired
strstring-Yes

Use the capitalize() function to capitalize the first letter of a string.

import { capitalize } from '@inpulse-ui/utils';
const result = capitalize('hello world');
console.log(result); // "Hello world"

Preserves original casing of remaining characters:

console.log(capitalize('hello WORLD')); // "Hello WORLD"
console.log(capitalize('javaScript')); // "JavaScript"
console.log(capitalize('iPhone')); // "IPhone"
console.log(capitalize('myVARIABLE')); // "MyVARIABLE"

Handles edge cases:

console.log(capitalize('')); // ""
console.log(capitalize('a')); // "A"
console.log(capitalize('A')); // "A"
console.log(capitalize('123abc')); // "123abc"

Returns empty string for non-string inputs:

console.log(capitalize(null)); // ""
console.log(capitalize(undefined)); // ""
console.log(capitalize(123)); // ""
console.log(capitalize({})); // ""

Welcome message formatting - capitalizing user names for display:

import { capitalize } from '@inpulse-ui/utils';
// User input from form
const userName = 'john';
// Format for welcome message
const welcomeMessage = `Welcome, ${capitalize(userName)}!`;
console.log(welcomeMessage); // "Welcome, John doe!"
// Display in UI
document.getElementById('welcome').textContent = welcomeMessage;

Project

Built with by Jo Santana in Brazil.

© 2026 Inpulse. All rights reserved.