Convert text with only the first character in upper case
npm install text-upper-case-first[![NPM version][npm-image]][npm-url]
[![NPM downloads][downloads-image]][downloads-url]
[![Bundle size][bundlephobia-image]][bundlephobia-url]


> Transform text by making the first character uppercase while preserving the rest.
- Lightweight - Only ~200B minified + gzipped
- Type-safe - Full TypeScript support with comprehensive type definitions
- Zero dependencies - No external dependencies
- Tree-shakeable - ES modules support
- Universal - Works in browsers, Node.js, and serverless environments
- Well-tested - Comprehensive test suite with edge cases
``bashnpm
npm install text-upper-case-first
π― Quick Start
`javascript
import { upperCaseFirst } from "text-upper-case-first";console.log(upperCaseFirst("hello world")); // "Hello world"
console.log(upperCaseFirst("HELLO WORLD")); // "HELLO WORLD"
console.log(upperCaseFirst("camelCase")); // "CamelCase"
`π Usage
$3
`javascript
import { upperCaseFirst } from "text-upper-case-first";console.log(upperCaseFirst("hello")); // "Hello"
`$3
`javascript
const { upperCaseFirst } = require("text-upper-case-first");console.log(upperCaseFirst("hello")); // "Hello"
`$3
`typescript
import { upperCaseFirst } from "text-upper-case-first";const result: string = upperCaseFirst("hello world");
console.log(result); // "Hello world"
`π Transformation Examples
$3
`javascript
import { upperCaseFirst } from "text-upper-case-first";// Simple cases
upperCaseFirst("hello"); // "Hello"
upperCaseFirst("HELLO"); // "HELLO"
upperCaseFirst("Hello"); // "Hello"
// Multiple words
upperCaseFirst("hello world"); // "Hello world"
upperCaseFirst("HELLO WORLD"); // "HELLO WORLD"
upperCaseFirst("Hello World"); // "Hello World"
// Programming cases
upperCaseFirst("camelCase"); // "CamelCase"
upperCaseFirst("pascalCase"); // "PascalCase"
upperCaseFirst("snake_case"); // "Snake_case"
upperCaseFirst("kebab-case"); // "Kebab-case"
`$3
`javascript
import { upperCaseFirst } from "text-upper-case-first";// Empty and single character
upperCaseFirst(""); // ""
upperCaseFirst("a"); // "A"
upperCaseFirst("A"); // "A"
// Numbers and symbols
upperCaseFirst("123hello"); // "123hello"
upperCaseFirst("@hello"); // "@hello"
upperCaseFirst("hello123"); // "Hello123"
// Unicode characters
upperCaseFirst("Γ±ice"); // "Γice"
upperCaseFirst("ΓΌber"); // "Γber"
upperCaseFirst("cafΓ©"); // "CafΓ©"
`π Real-World Examples
$3
`javascript
import { upperCaseFirst } from "text-upper-case-first";// Capitalize sentences
upperCaseFirst("this is a sentence."); // "This is a sentence."
upperCaseFirst("welcome to our app"); // "Welcome to our app"
upperCaseFirst("error: invalid input"); // "Error: invalid input"
`$3
`javascript
import { upperCaseFirst } from "text-upper-case-first";// Format names
upperCaseFirst("john"); // "John"
upperCaseFirst("mary jane"); // "Mary jane"
upperCaseFirst("o'connor"); // "O'connor"
upperCaseFirst("van der berg"); // "Van der berg"
`$3
`javascript
import { upperCaseFirst } from "text-upper-case-first";// Process content titles
const titles = [
"getting started",
"installation guide",
"best practices",
"troubleshooting",
"frequently asked questions",
];
const formattedTitles = titles.map(upperCaseFirst);
console.log(formattedTitles);
// [
// "Getting started",
// "Installation guide",
// "Best practices",
// "Troubleshooting",
// "Frequently asked questions"
// ]
`$3
`javascript
import { upperCaseFirst } from "text-upper-case-first";function formatFormField(value) {
return upperCaseFirst(value.trim().toLowerCase());
}
console.log(formatFormField(" JOHN DOE ")); // "John doe"
console.log(formatFormField("jane smith")); // "Jane smith"
console.log(formatFormField("BOB WILSON")); // "Bob wilson"
`$3
`javascript
import { upperCaseFirst } from "text-upper-case-first";function formatMessage(message) {
return (
upperCaseFirst(message.trim()) +
(message.endsWith(".") || message.endsWith("!") || message.endsWith("?")
? ""
: ".")
);
}
console.log(formatMessage("hello world")); // "Hello world."
console.log(formatMessage("welcome back!")); // "Welcome back!"
console.log(formatMessage("are you sure?")); // "Are you sure?"
`$3
`javascript
import { upperCaseFirst } from "text-upper-case-first";function formatComment(comment) {
// Capitalize first letter and ensure proper punctuation
const formatted = upperCaseFirst(comment.trim());
if (!formatted.match(/[.!?]$/)) {
return formatted + ".";
}
return formatted;
}
console.log(formatComment("great article"));
// "Great article."
console.log(formatComment("thanks for sharing!"));
// "Thanks for sharing!"
`$3
`javascript
import { upperCaseFirst } from "text-upper-case-first";class NotificationFormatter {
static format(message, type = "info") {
const formattedMessage = upperCaseFirst(message.trim());
return {
type,
message: formattedMessage,
timestamp: new Date().toISOString(),
};
}
static formatBatch(messages) {
return messages.map((msg) => this.format(msg));
}
}
console.log(NotificationFormatter.format("user logged in successfully"));
// {
// type: "info",
// message: "User logged in successfully",
// timestamp: "2023-..."
// }
`$3
`javascript
import { upperCaseFirst } from "text-upper-case-first";function processTextInput(input, options = {}) {
const {
autoCapitalize = true,
trimWhitespace = true,
addPunctuation = false,
} = options;
let processed = input;
if (trimWhitespace) {
processed = processed.trim();
}
if (autoCapitalize) {
processed = upperCaseFirst(processed);
}
if (addPunctuation && !processed.match(/[.!?]$/)) {
processed += ".";
}
return processed;
}
console.log(
processTextInput(" hello world ", {
autoCapitalize: true,
addPunctuation: true,
}),
);
// "Hello world."
`$3
`javascript
import { upperCaseFirst } from "text-upper-case-first";function processBlogPost(post) {
return {
...post,
title: upperCaseFirst(post.title),
excerpt: upperCaseFirst(post.excerpt),
tags: post.tags.map((tag) => upperCaseFirst(tag)),
};
}
const blogPost = {
title: "getting started with react",
excerpt: "learn the basics of react development",
tags: ["react", "javascript", "frontend"],
content: "...",
};
console.log(processBlogPost(blogPost));
// {
// title: "Getting started with react",
// excerpt: "Learn the basics of react development",
// tags: ["React", "Javascript", "Frontend"],
// content: "..."
// }
`$3
`javascript
import { upperCaseFirst } from "text-upper-case-first";class ErrorFormatter {
static format(error) {
if (typeof error === "string") {
return upperCaseFirst(error);
}
if (error.message) {
return {
...error,
message: upperCaseFirst(error.message),
};
}
return error;
}
static formatValidationErrors(errors) {
const formatted = {};
Object.entries(errors).forEach(([field, message]) => {
formatted[field] = upperCaseFirst(message);
});
return formatted;
}
}
console.log(ErrorFormatter.format("invalid email address"));
// "Invalid email address"
console.log(
ErrorFormatter.formatValidationErrors({
email: "email is required",
password: "password must be at least 8 characters",
}),
);
// {
// email: "Email is required",
// password: "Password must be at least 8 characters"
// }
`π API Reference
$3
Makes the first character of a string uppercase while preserving the rest.
#### Parameters
-
input (string): The string to transform#### Returns
-
string: The string with the first character in uppercaseπ Bundle Size
This package is optimized for minimal bundle size:
- Minified: ~200B
- Gzipped: ~150B
- Tree-shakeable: Yes
- Side effects: None
π Browser Support
- Modern browsers: ES2015+ (Chrome 51+, Firefox 54+, Safari 10+)
- Node.js: 12+
- TypeScript: 4.0+
- Bundle formats: UMD, ESM, CommonJS
π§ͺ Testing
`bash
Run tests
pnpm testRun tests in watch mode
pnpm test --watchRun tests with coverage
pnpm test --coverageType checking
pnpm typecheckLinting
pnpm lint
`π Related Packages
text-camel-case - Convert to camelCase
- text-capital-case - Convert to Capital Case
- text-constant-case - Convert to CONSTANT_CASE
- text-dot-case - Convert to dot.case
- text-header-case - Convert to Header-Case
- text-case - All case transformations in one packageπ License
π€ Contributing
1. Fork the repository
2. Create your feature branch (
git checkout -b feature/amazing-feature)
3. Commit your changes (git commit -m 'Add some amazing feature')
4. Push to the branch (git push origin feature/amazing-feature`)- π§ Email: selikhov.dmitrey@gmail.com
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
- π Documentation: Full Documentation
---
Made with β€οΈ by Dmitry Selikhov
[npm-image]: https://img.shields.io/npm/v/text-upper-case-first.svg?style=flat
[npm-url]: https://npmjs.org/package/text-upper-case-first
[downloads-image]: https://img.shields.io/npm/dm/text-upper-case-first.svg?style=flat
[downloads-url]: https://npmjs.org/package/text-upper-case-first
[bundlephobia-image]: https://img.shields.io/bundlephobia/minzip/text-upper-case-first.svg
[bundlephobia-url]: https://bundlephobia.com/result?p=text-upper-case-first