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

v1.2.9

Published

Convert text between `camelCase`, `PascalCase`, `Capital Case`, `Header-Case`, `Title Case`, `path/case`, `snake_case`, `param-case`, `kebab-case`, `dot.case`, `CONSTANT_CASE`, `lower case`, `lOWER CASE FIRST`, `UPPER CASE`, `Upper case first` and other

Readme

Text Case

NPM version NPM downloads Bundle size License: MIT TypeScript

The ultimate text case transformation library for JavaScript and TypeScript. Convert text between camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE, Title Case, Sentence case, dot.case, path/case, Header-Case, and many more formats with comprehensive TypeScript support.

🚀 Features

  • 21 case transformation functions covering all common text formatting needs
  • Type-safe with comprehensive TypeScript definitions
  • Zero dependencies - lightweight and fast
  • Tree-shakeable - import only what you need
  • Universal - works in browsers, Node.js, and serverless environments
  • Comprehensive testing - 100% test coverage with extensive edge cases
  • Professional documentation - detailed examples and API references
  • Modern tooling - ES modules, CommonJS, and UMD support

📦 Installation

# npm
npm install text-case

# yarn
yarn add text-case

# pnpm
pnpm add text-case

# bun
bun add text-case

🎯 Quick Start

import {
  camelCase, // userProfileData
  pascalCase, // UserProfileData
  kebabCase, // user-profile-data
  snakeCase, // user_profile_data
  titleCase, // User Profile Data
  sentenceCase, // User profile data
  constantCase, // USER_PROFILE_DATA
  dotCase, // user.profile.data
  pathCase, // user/profile/data
  headerCase, // User-Profile-Data
  capitalCase, // User Profile Data
  noCase, // user profile data
  paramCase, // user-profile-data (alias for kebab-case)
  upperCase, // USER PROFILE DATA
  lowerCase, // user profile data
  upperCaseFirst, // User profile data
  lowerCaseFirst, // user Profile Data
  swapCase, // uSER pROFILE dATA
  isUpperCase, // Boolean check
  isLowerCase, // Boolean check
} from "text-case";

// Transform any text format
const input = "user_profile_data";

console.log(camelCase(input)); // "userProfileData"
console.log(pascalCase(input)); // "UserProfileData"
console.log(kebabCase(input)); // "user-profile-data"
console.log(titleCase(input)); // "User Profile Data"

📚 Available Functions

Core Transformations

| Function | Output Example | Description | | ---------------- | ------------------- | -------------------------------------------------- | | camelCase() | userProfileData | First word lowercase, subsequent words capitalized | | pascalCase() | UserProfileData | All words capitalized, no separators | | snakeCase() | user_profile_data | Lowercase words separated by underscores | | kebabCase() | user-profile-data | Lowercase words separated by hyphens | | titleCase() | User Profile Data | All words capitalized, separated by spaces | | sentenceCase() | User profile data | First word capitalized, rest lowercase |

Specialized Formats

| Function | Output Example | Description | | ---------------- | ------------------- | -------------------------------------------- | | constantCase() | USER_PROFILE_DATA | Uppercase words separated by underscores | | dotCase() | user.profile.data | Lowercase words separated by dots | | pathCase() | user/profile/data | Lowercase words separated by forward slashes | | headerCase() | User-Profile-Data | Capitalized words separated by hyphens | | capitalCase() | User Profile Data | All words capitalized, separated by spaces | | noCase() | user profile data | Lowercase words separated by spaces | | paramCase() | user-profile-data | Alias for kebab-case |

Character Transformations

| Function | Output Example | Description | | ------------------ | ------------------- | --------------------------- | | upperCase() | USER PROFILE DATA | All characters uppercase | | lowerCase() | user profile data | All characters lowercase | | upperCaseFirst() | User profile data | First character uppercase | | lowerCaseFirst() | user Profile Data | First character lowercase | | swapCase() | uSER pROFILE dATA | Swap case of all characters |

Validation Utilities

| Function | Output Example | Description | | --------------- | -------------- | ---------------------------- | | isUpperCase() | true/false | Check if string is uppercase | | isLowerCase() | true/false | Check if string is lowercase |

🛠️ Advanced Usage

Custom Options

All transformation functions accept an optional second parameter for customization:

import { camelCase, snakeCase } from "text-case";

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

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

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

TypeScript Support

Full TypeScript support with comprehensive type definitions:

import { camelCase, Options } from "text-case";

// Type-safe options
const options: Options = {
  splitRegexp: /([a-z])([A-Z])/g,
  stripRegexp: /[^a-zA-Z0-9]/g,
  transform: (word: string, index: number, words: string[]) =>
    word.toLowerCase(),
};

// Type inference
const result: string = camelCase("hello-world", options);

Real-World Examples

API Development

import { camelCase, snakeCase, kebabCase } from "text-case";

// Convert database columns to JavaScript
const dbUser = {
  first_name: "John",
  last_name: "Doe",
  email_address: "[email protected]",
};
const jsUser = Object.fromEntries(
  Object.entries(dbUser).map(([key, value]) => [camelCase(key), value]),
);
// { firstName: "John", lastName: "Doe", emailAddress: "[email protected]" }

// Generate API endpoints
const createEndpoint = (resource, action) =>
  `/api/${kebabCase(resource)}/${kebabCase(action)}`;

createEndpoint("UserProfile", "GetById"); // "/api/user-profile/get-by-id"

React Development

import { pascalCase, camelCase } from "text-case";

// Component generation
const createComponent = (name) => `
  import React from 'react';

  interface ${pascalCase(name)}Props {
    ${camelCase(name)}Data?: any;
  }

  export const ${pascalCase(name)}: React.FC<${pascalCase(name)}Props> = ({ ${camelCase(name)}Data }) => {
    return <div>{/* ${pascalCase(name)} component */}</div>;
  };
`;

console.log(createComponent("user_profile_card"));

Configuration Management

import { constantCase, camelCase } from "text-case";

// Environment variables to config object
const envToConfig = (envVars) => {
  return Object.fromEntries(
    Object.entries(envVars)
      .filter(([key]) => key.startsWith("APP_"))
      .map(([key, value]) => [camelCase(key.replace("APP_", "")), value]),
  );
};

const env = {
  APP_DATABASE_URL: "postgres://...",
  APP_API_SECRET_KEY: "secret123",
  APP_MAX_FILE_SIZE: "10MB",
};

const config = envToConfig(env);
// { databaseUrl: "postgres://...", apiSecretKey: "secret123", maxFileSize: "10MB" }

📖 API Reference

Options Interface

interface Options {
  // RegExp to split input into words
  splitRegexp?: RegExp;

  // RegExp to strip unwanted characters
  stripRegexp?: RegExp;

  // Custom word transformation function
  transform?: (word: string, index: number, words: string[]) => string;

  // Custom split function (alternative to splitRegexp)
  split?: (value: string) => string[];

  // Delimiter between words (for spaced formats)
  delimiter?: string;
}

Common Patterns

// Split on camelCase and PascalCase boundaries
const camelSplit = { splitRegexp: /([a-z])([A-Z])/g };

// Preserve numbers as separate words
const numberSplit = { splitRegexp: /([a-zA-Z])(\d)/g };

// Strip special characters
const stripSpecial = { stripRegexp: /[^a-zA-Z0-9]/g };

// Custom acronym handling
const acronymTransform = {
  transform: (word) => {
    const acronyms = ["API", "URL", "HTTP", "JSON", "XML"];
    return acronyms.includes(word.toUpperCase()) ? word.toUpperCase() : word;
  },
};

📊 Bundle Size

This package is optimized for minimal bundle size:

  • Minified: ~8KB (all functions)
  • Gzipped: ~3KB (all functions)
  • Tree-shakeable: Yes
  • Side effects: None

For even smaller bundles, consider using individual packages:

// ❌ Imports entire library (~8KB)
import { camelCase } from "text-case";

// ✅ Imports only camelCase (~450B)
import { camelCase } from "text-camel-case";

🌍 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

🔗 Individual Packages

For optimal bundle size, you can install individual 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