npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

text-upper-case-first

v1.2.9

Published

Convert text with only the first character in upper case

Readme

Upper Case First

NPM version NPM downloads Bundle size License: MIT TypeScript

Transform text by making the first character uppercase while preserving the rest.

🚀 Features

  • 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

📦 Installation

# npm
npm install text-upper-case-first

# yarn
yarn add text-upper-case-first

# pnpm
pnpm add text-upper-case-first

# bun
bun add text-upper-case-first

🎯 Quick Start

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

ES Modules (Recommended)

import { upperCaseFirst } from "text-upper-case-first";

console.log(upperCaseFirst("hello")); // "Hello"

CommonJS

const { upperCaseFirst } = require("text-upper-case-first");

console.log(upperCaseFirst("hello")); // "Hello"

TypeScript

import { upperCaseFirst } from "text-upper-case-first";

const result: string = upperCaseFirst("hello world");
console.log(result); // "Hello world"

🔄 Transformation Examples

Basic Transformations

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"

Edge Cases

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

Sentence Capitalization

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"

Name Formatting

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"

Content Processing

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"
// ]

Form Field Processing

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"

Message Formatting

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?"

Comment Processing

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!"

Notification Processing

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-..."
// }

Text Input Processing

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."

Blog Post Processing

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: "..."
// }

Error Message Processing

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

upperCaseFirst(input)

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

# Run tests
pnpm test

# Run tests in watch mode
pnpm test --watch

# Run tests with coverage
pnpm test --coverage

# Type checking
pnpm typecheck

# Linting
pnpm lint

🔗 Related Packages

📜 License

MIT © Dmitry Selikhov

🤝 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)
  5. Open a Pull Request

🆘 Support


Made with ❤️ by Dmitry Selikhov