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-pascal-case

v1.2.9

Published

Convert into a text of capitalized words without separators

Readme

Pascal Case

NPM version NPM downloads Bundle size License: MIT TypeScript

Transform text into PascalCase format where the first letter of each word is capitalized with no separators.

🚀 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-pascal-case

# yarn
yarn add text-pascal-case

# pnpm
pnpm add text-pascal-case

# bun
bun add text-pascal-case

🎯 Quick Start

import { pascalCase } from "text-pascal-case";

console.log(pascalCase("hello world")); // "HelloWorld"
console.log(pascalCase("user_profile_data")); // "UserProfileData"
console.log(pascalCase("background-color")); // "BackgroundColor"

📖 Usage

ES Modules (Recommended)

import { pascalCase } from "text-pascal-case";

console.log(pascalCase("hello world")); // "HelloWorld"

CommonJS

const { pascalCase } = require("text-pascal-case");

console.log(pascalCase("hello world")); // "HelloWorld"

TypeScript

import {
  pascalCase,
  pascalCaseTransformMerge,
  Options,
} from "text-pascal-case";

const result: string = pascalCase("hello world");
console.log(result); // "HelloWorld"

🔄 Transformation Examples

Basic Transformations

import { pascalCase } from "text-pascal-case";

// From different cases
pascalCase("hello world"); // "HelloWorld"
pascalCase("Hello World"); // "HelloWorld"
pascalCase("HELLO WORLD"); // "HelloWorld"
pascalCase("snake_case"); // "SnakeCase"
pascalCase("kebab-case"); // "KebabCase"
pascalCase("dot.case"); // "DotCase"
pascalCase("camelCase"); // "CamelCase"
pascalCase("CONSTANT_CASE"); // "ConstantCase"

// Complex examples
pascalCase("XMLHttpRequest"); // "XmlHttpRequest"
pascalCase("iPhone"); // "IPhone"
pascalCase("version 1.2.3"); // "Version123"
pascalCase("user-profile-data"); // "UserProfileData"

Advanced Options

import { pascalCase, pascalCaseTransformMerge } from "text-pascal-case";

// Custom transform to merge numbers without separator
pascalCase("version 1.2.3", {
  transform: pascalCaseTransformMerge,
}); // "Version123"

// Custom word splitting
pascalCase("XMLHttpRequest", {
  splitRegexp: /([a-z])([A-Z])/g,
}); // "XmlHttpRequest"

// Custom character stripping
pascalCase("[email protected]", {
  stripRegexp: /[@.]/g,
}); // "HelloWorldCom"

// Custom transformation function
pascalCase("api-v2-endpoint", {
  transform: (word, index) => {
    if (word === "api") return "API";
    if (word === "v2") return "V2";
    return word;
  },
}); // "APIV2Endpoint"

🌍 Real-World Examples

Class Names

import { pascalCase } from "text-pascal-case";

// Component names
pascalCase("user_profile"); // "UserProfile"
pascalCase("email_validator"); // "EmailValidator"
pascalCase("data_service"); // "DataService"
pascalCase("auth_middleware"); // "AuthMiddleware"
pascalCase("payment_gateway"); // "PaymentGateway"

React Components

import { pascalCase } from "text-pascal-case";

// Component file names
pascalCase("user-profile"); // "UserProfile"
pascalCase("navigation-bar"); // "NavigationBar"
pascalCase("modal-dialog"); // "ModalDialog"
pascalCase("search-input"); // "SearchInput"
pascalCase("loading-spinner"); // "LoadingSpinner"

Database Models

import { pascalCase } from "text-pascal-case";

// Model class names
pascalCase("user_account"); // "UserAccount"
pascalCase("order_item"); // "OrderItem"
pascalCase("product_category"); // "ProductCategory"
pascalCase("shipping_address"); // "ShippingAddress"

API Endpoints to Types

import { pascalCase } from "text-pascal-case";

// Convert API endpoints to TypeScript interface names
const endpoints = [
  "user_profile",
  "order_history",
  "payment_method",
  "shipping_address",
];

const typeNames = endpoints.map(
  (endpoint) => `${pascalCase(endpoint)}Response`,
);
console.log(typeNames);
// ["UserProfileResponse", "OrderHistoryResponse", "PaymentMethodResponse", "ShippingAddressResponse"]

📖 API Reference

pascalCase(input, options?)

Converts a string to PascalCase.

Parameters

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

Returns

  • string: The PascalCase 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[];
}

pascalCaseTransformMerge

A transform function that merges numeric characters without separation.

import { pascalCase, pascalCaseTransformMerge } from "text-pascal-case";

pascalCase("version 1.2.3", { transform: pascalCaseTransformMerge }); // "Version123"

🔧 Advanced Configuration

Custom Word Splitting

import { pascalCase } from "text-pascal-case";

// Split on specific patterns
pascalCase("XMLHttpRequest", {
  splitRegexp: /([a-z])([A-Z])/g,
}); // "XmlHttpRequest"

// Split on numbers
pascalCase("user123data", {
  splitRegexp: /([a-zA-Z])(\d)/g,
}); // "User123Data"

Custom Character Stripping

import { pascalCase } from "text-pascal-case";

// Strip specific characters
pascalCase("[email protected]", {
  stripRegexp: /[@.]/g,
}); // "HelloWorldCom"

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

Custom Transform Functions

import { pascalCase } from "text-pascal-case";

// Preserve acronyms
pascalCase("xml-http-request", {
  transform: (word, index) => {
    const acronyms = ["xml", "http", "api", "url"];
    if (acronyms.includes(word.toLowerCase())) {
      return word.toUpperCase();
    }
    return word;
  },
}); // "XMLHTTPRequest"

// Custom business logic
pascalCase("user-v2-api", {
  transform: (word, index) => {
    if (word === "v2") return "V2";
    if (word === "api") return "API";
    return word;
  },
}); // "UserV2API"

📊 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