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 🙏

© 2026 – Pkg Stats / Ryan Hefner

text-capital-case

v1.2.10

Published

Convert into a space separated text with each word capitalized

Readme

Capital Case

NPM version NPM downloads Bundle size License: MIT TypeScript

Transform text into Capital Case format where each word is capitalized and separated by spaces.

🚀 Features

  • Lightweight - Only ~450B 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
  • Customizable - Flexible options for advanced use cases

📦 Installation

# npm
npm install text-capital-case

# yarn
yarn add text-capital-case

# pnpm
pnpm add text-capital-case

# bun
bun add text-capital-case

🎯 Quick Start

import { capitalCase } from "text-capital-case";

console.log(capitalCase("hello world")); // "Hello World"
console.log(capitalCase("user_profile_data")); // "User Profile Data"
console.log(capitalCase("backgroundColor")); // "Background Color"

📖 Usage

ES Modules (Recommended)

import { capitalCase } from "text-capital-case";

console.log(capitalCase("hello world")); // "Hello World"

CommonJS

const { capitalCase } = require("text-capital-case");

console.log(capitalCase("hello world")); // "Hello World"

TypeScript

import { capitalCase, Options } from "text-capital-case";

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

🔄 Transformation Examples

Basic Transformations

import { capitalCase } from "text-capital-case";

// From different cases
capitalCase("hello world"); // "Hello World"
capitalCase("Hello World"); // "Hello World"
capitalCase("HELLO WORLD"); // "Hello World"
capitalCase("camelCase"); // "Camel Case"
capitalCase("PascalCase"); // "Pascal Case"
capitalCase("snake_case"); // "Snake Case"
capitalCase("kebab-case"); // "Kebab Case"
capitalCase("dot.case"); // "Dot Case"

// Complex examples
capitalCase("XMLHttpRequest"); // "Xml Http Request"
capitalCase("iPhone"); // "I Phone"
capitalCase("version 1.2.3"); // "Version 1 2 3"
capitalCase("userProfileData"); // "User Profile Data"

Advanced Options

import { capitalCase } from "text-capital-case";

// Custom word splitting
capitalCase("XMLHttpRequest", {
  splitRegexp: /([a-z])([A-Z])/g,
}); // "Xml Http Request"

// Custom character stripping
capitalCase("[email protected]", {
  stripRegexp: /[@.]/g,
}); // "Hello World Com"

// Custom transformation function
capitalCase("api-v2-endpoint", {
  transform: (word, index) => {
    if (word === "api") return "API";
    if (word === "v2") return "V2";
    return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
  },
}); // "API V2 Endpoint"

🌍 Real-World Examples

Business Titles and Names

import { capitalCase } from "text-capital-case";

// Job titles
capitalCase("chief executive officer"); // "Chief Executive Officer"
capitalCase("senior software engineer"); // "Senior Software Engineer"
capitalCase("product manager"); // "Product Manager"
capitalCase("data scientist"); // "Data Scientist"
capitalCase("marketing director"); // "Marketing Director"

Document Headings

import { capitalCase } from "text-capital-case";

// Document sections
capitalCase("table of contents"); // "Table Of Contents"
capitalCase("executive summary"); // "Executive Summary"
capitalCase("financial overview"); // "Financial Overview"
capitalCase("risk assessment"); // "Risk Assessment"
capitalCase("implementation plan"); // "Implementation Plan"

Product and Service Names

import { capitalCase } from "text-capital-case";

// Product names
capitalCase("premium subscription"); // "Premium Subscription"
capitalCase("enterprise solution"); // "Enterprise Solution"
capitalCase("mobile application"); // "Mobile Application"
capitalCase("cloud storage"); // "Cloud Storage"
capitalCase("customer support"); // "Customer Support"

Form Labels and UI Text

import { capitalCase } from "text-capital-case";

// Form fields
capitalCase("billing information"); // "Billing Information"
capitalCase("shipping address"); // "Shipping Address"
capitalCase("payment method"); // "Payment Method"
capitalCase("contact details"); // "Contact Details"
capitalCase("account settings"); // "Account Settings"

Content Categories

import { capitalCase } from "text-capital-case";

// Transform content categories
const categories = [
  "web_development",
  "machine-learning",
  "data.analysis",
  "userExperience",
  "projectManagement",
];

const formattedCategories = categories.map(capitalCase);
console.log(formattedCategories);
// [
//   "Web Development",
//   "Machine Learning",
//   "Data Analysis",
//   "User Experience",
//   "Project Management"
// ]

📖 API Reference

capitalCase(input, options?)

Converts a string to Capital Case.

Parameters

  • input (string): The string to convert
  • options (Options, optional): Configuration options

Returns

  • string: The Capital Case formatted string

Options

interface Options {
  // Custom transform function for word processing
  transform?: (word: string, index: number, words: string[]) => string;

  // Regex to strip characters before processing
  stripRegexp?: RegExp;

  // Custom split function
  split?: (value: string) => string[];
}

🔧 Advanced Configuration

Custom Word Splitting

import { capitalCase } from "text-capital-case";

// Split on specific patterns
capitalCase("XMLHttpRequest", {
  splitRegexp: /([a-z])([A-Z])/g,
}); // "Xml Http Request"

// Split on numbers
capitalCase("user123data", {
  splitRegexp: /([a-zA-Z])(\d)/g,
}); // "User 123 Data"

Custom Character Stripping

import { capitalCase } from "text-capital-case";

// Strip specific characters
capitalCase("[email protected]", {
  stripRegexp: /[@.]/g,
}); // "Hello World Com"

// Strip all non-alphanumeric
capitalCase("hello!@#world", {
  stripRegexp: /[^a-zA-Z0-9]/g,
}); // "Hello World"

Custom Transform Functions

import { capitalCase } from "text-capital-case";

// Preserve acronyms
capitalCase("xml-http-request", {
  transform: (word, index) => {
    const acronyms = ["xml", "http", "api", "url", "html", "css", "js"];
    if (acronyms.includes(word.toLowerCase())) {
      return word.toUpperCase();
    }
    return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
  },
}); // "XML HTTP Request"

// Custom business logic
capitalCase("user-v2-api", {
  transform: (word, index) => {
    if (word === "v2") return "V2";
    if (word === "api") return "API";
    return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
  },
}); // "User V2 API"

📊 Bundle Size

This package is optimized for minimal bundle size:

  • Minified: ~450B
  • Gzipped: ~250B
  • 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