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

all-in-one-text-case-converter

v1.0.0

Published

A comprehensive text case conversion library with TypeScript support and regex capabilities

Readme

Text Case Converter

A comprehensive TypeScript/JavaScript library for text case conversion with regex-based transformation capabilities.

Features

  • 🔄 Multiple Case Types: Convert between camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE, Title Case, Sentence case, UPPERCASE, and lowercase
  • 🎯 Regex Support: Advanced text transformations using custom regex patterns
  • 🔍 Case Detection: Automatically detect the case type of input text
  • 📦 TypeScript Support: Full TypeScript definitions included
  • 🧪 Well Tested: Comprehensive test suite with 100% coverage
  • 🚀 Zero Dependencies: Lightweight with no external dependencies
  • 🛠️ Flexible Options: Customizable separators, whitespace preservation, and word boundary patterns

Installation

npm install text-case-converter

Quick Start

import { TextCaseConverter } from 'text-case-converter';

// Basic case conversion
TextCaseConverter.convert('hello world', 'camel');     // 'helloWorld'
TextCaseConverter.convert('hello world', 'pascal');    // 'HelloWorld'
TextCaseConverter.convert('hello world', 'snake');     // 'hello_world'
TextCaseConverter.convert('hello world', 'kebab');     // 'hello-world'

// Convert to all case types at once
const allCases = TextCaseConverter.convertToAll('hello world');
console.log(allCases);
// {
//   camel: 'helloWorld',
//   pascal: 'HelloWorld',
//   snake: 'hello_world',
//   kebab: 'hello-world',
//   constant: 'HELLO_WORLD',
//   title: 'Hello World',
//   sentence: 'Hello world',
//   upper: 'HELLO WORLD',
//   lower: 'hello world'
// }

// Detect case type
TextCaseConverter.detectCase('helloWorld');    // 'camel'
TextCaseConverter.detectCase('HelloWorld');    // 'pascal'
TextCaseConverter.detectCase('hello_world');   // 'snake'

API Reference

TextCaseConverter

convert(text: string, caseType: CaseType, options?: ConversionOptions): string

Convert text to the specified case type.

Parameters:

  • text - The input text to convert
  • caseType - Target case type ('camel', 'pascal', 'snake', 'kebab', 'constant', 'title', 'sentence', 'upper', 'lower')
  • options - Optional conversion options

Example:

TextCaseConverter.convert('hello world', 'camel', {
  preserveWhitespace: true,
  separator: '_'
});

convertBatch(texts: string[], caseType: CaseType, options?: ConversionOptions): string[]

Convert multiple texts to the same case type.

const texts = ['hello world', 'foo bar', 'test case'];
TextCaseConverter.convertBatch(texts, 'camel');
// ['helloWorld', 'fooBar', 'testCase']

convertToAll(text: string, options?: ConversionOptions): Record<CaseType, string>

Convert text to all supported case types.

detectCase(text: string): CaseType | 'mixed' | 'unknown'

Detect the case type of input text.

regexTransform(text: string, options: RegexTransformOptions): string

Apply regex-based transformation to text.

TextCaseConverter.regexTransform('hello world', {
  pattern: /world/g,
  replacement: 'universe'
});
// 'hello universe'

RegexTransformer

Advanced regex-based text transformations.

Predefined Transformations

import { RegexTransformer } from 'text-case-converter';

// Normalize whitespace
RegexTransformer.transformations.normalizeWhitespace('hello    world');
// 'hello world'

// Remove special characters
RegexTransformer.transformations.removeSpecialChars('hello@#$world!');
// 'helloworld'

// Extract words
RegexTransformer.transformations.extractWords('hello, world! 123');
// ['hello', 'world', '123']

// Mask emails
RegexTransformer.transformations.maskEmails('Contact [email protected]');
// 'Contact [EMAIL]'

// Format phone numbers
RegexTransformer.transformations.formatPhoneNumbers('Call 1234567890');
// 'Call (123) 456-7890'

// Split camelCase
RegexTransformer.transformations.splitCamelCase('helloWorldTest');
// 'hello World Test'

Custom Patterns

// Use predefined patterns
RegexTransformer.patterns.email;           // Email regex pattern
RegexTransformer.patterns.url;             // URL regex pattern
RegexTransformer.patterns.phone;           // Phone number pattern
RegexTransformer.patterns.camelCaseBoundaries; // camelCase boundaries

// Custom transformation
RegexTransformer.transform('ABC123DEF456', {
  pattern: /([A-Z]+)(\d+)/g,
  replacement: '$1-$2'
});
// 'ABC-123DEF-456'

Individual Converters

You can also import and use individual converter classes:

import { CaseConverter } from 'text-case-converter';

CaseConverter.toCamelCase('hello world');    // 'helloWorld'
CaseConverter.toPascalCase('hello world');   // 'HelloWorld'
CaseConverter.toSnakeCase('hello world');    // 'hello_world'
CaseConverter.toKebabCase('hello world');    // 'hello-world'
CaseConverter.toConstantCase('hello world'); // 'HELLO_WORLD'
CaseConverter.toTitleCase('hello world');    // 'Hello World'
CaseConverter.toSentenceCase('hello world'); // 'Hello world'
CaseConverter.toUpperCase('hello world');    // 'HELLO WORLD'
CaseConverter.toLowerCase('HELLO WORLD');    // 'hello world'

Configuration Options

ConversionOptions

interface ConversionOptions {
  separator?: string;           // Custom separator for words
  preserveWhitespace?: boolean; // Preserve leading/trailing whitespace
  wordBoundaryPattern?: RegExp; // Custom word boundary pattern
}

RegexTransformOptions

interface RegexTransformOptions {
  pattern: RegExp;              // Regex pattern to match
  replacement: string | ((match: string, ...args: any[]) => string);
  global?: boolean;             // Apply transformation globally
}

Advanced Examples

Custom Word Boundaries

TextCaseConverter.convert('hello123world', 'camel', {
  wordBoundaryPattern: /\d+/  // Split on numbers
});
// Result depends on custom pattern

Preserve Whitespace

TextCaseConverter.convert('  hello world  ', 'camel', {
  preserveWhitespace: true
});
// '  helloWorld  '

Complex Regex Transformations

// Convert currency format
TextCaseConverter.regexTransform('price: $10.50', {
  pattern: /\$(\d+)\.(\d+)/g,
  replacement: (match, dollars, cents) => {
    const total = parseInt(dollars) * 100 + parseInt(cents);
    return `${total} cents`;
  }
});
// 'price: 1050 cents'

Chaining Transformations

let text = '[email protected] world';

// First mask emails
text = RegexTransformer.transformations.maskEmails(text);
// 'hello [EMAIL] world'

// Then convert to title case
text = TextCaseConverter.convert(text, 'title');
// 'Hello [EMAIL] World'

Browser Support

This library works in all modern browsers and Node.js environments. It's written in TypeScript and compiled to ES5 for maximum compatibility.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite: npm test
  6. Submit a pull request

License

MIT License - see LICENSE file for details.

Changelog

1.0.0

  • Initial release
  • Support for 9 case types
  • Regex transformation capabilities
  • TypeScript support
  • Comprehensive test suite