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

react-case-formatter

v0.1.1

Published

A lightweight React utility for formatting text cases (camelCase, PascalCase, etc.)

Readme

react-case-formatter

A lightweight React utility library for formatting text cases (camelCase, PascalCase, etc.).

npm version npm downloads bundle size

Features

  • 🔠 Multiple Formatting Options: camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE, Title Case, Sentence case, and more.
  • ⚛️ React Components: Ready-to-use React components for each formatting style.
  • 🪝 React Hooks: Custom hooks for easily implementing case formatting in functional components.
  • 🔧 Utility Functions: Standalone formatter functions for use in any context.
  • 📦 Zero Dependencies: Lightweight with zero runtime dependencies.
  • 📱 TypeScript Support: Built with TypeScript for enhanced developer experience.

Installation

# npm
npm install react-case-formatter

# yarn
yarn add react-case-formatter

# pnpm
pnpm add react-case-formatter

Quick Start

import React, { useState } from "react";
import {
  CamelCase,
  PascalCase,
  SnakeCase,
  useCaseFormatter,
} from "react-case-formatter";

function App() {
  // Using individual components
  return (
    <div>
      <h3>Component Examples:</h3>
      <p>
        <CamelCase>Hello World Example</CamelCase>
      </p> {/* helloWorldExample */}
      <p>
        <PascalCase>Hello World Example</PascalCase>
      </p>{" "}
      {/* HelloWorldExample */}
      <p>
        <SnakeCase>Hello World Example</SnakeCase>
      </p> {/* hello_world_example */}
      <FormatterDemo />
    </div>
  );
}

// Using the hook
function FormatterDemo() {
  const [input, setInput] = useState("Hello World Example");
  const [formatted, updateFormatted] = useCaseFormatter(input);

  const handleChange = (e) => {
    const newValue = e.target.value;
    setInput(newValue);
    updateFormatted(newValue);
  };

  return (
    <div>
      <h3>Hook Example:</h3>
      <input
        type="text"
        value={input}
        onChange={handleChange}
        placeholder="Type something..."
      />

      <div style={{ marginTop: "10px" }}>
        <p>camelCase: {formatted.camelCase}</p>
        <p>PascalCase: {formatted.pascalCase}</p>
        <p>snake_case: {formatted.snakeCase}</p>
        <p>kebab-case: {formatted.kebabCase}</p>
        <p>CONSTANT_CASE: {formatted.constantCase}</p>
        <p>Title Case: {formatted.titleCase}</p>
        <p>Sentence case: {formatted.sentenceCase}</p>
      </div>
    </div>
  );
}

export default App;

API

Utility Functions

import {
  toCamelCase,
  toPascalCase,
  toSnakeCase,
  toKebabCase,
  toConstantCase,
  toTitleCase,
  toSentenceCase,
  toLowerCase,
  toUpperCase,
  capitalizeFirstLetter,
  capitalizeWords,
} from "react-case-formatter";

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

React Components

import {
  CamelCase,
  PascalCase,
  SnakeCase,
  KebabCase,
  ConstantCase,
  TitleCase,
  SentenceCase,
  UpperCase,
  LowerCase,
  Capitalized,
  CapitalizedWords,
  CaseFormatter
} from 'react-case-formatter';

// Examples
<CamelCase>Hello World</CamelCase>              // helloWorld
<PascalCase>Hello World</PascalCase>            // HelloWorld
<SnakeCase>Hello World</SnakeCase>              // hello_world
<KebabCase>Hello World</KebabCase>              // hello-world
<ConstantCase>Hello World</ConstantCase>        // HELLO_WORLD
<TitleCase>hello of the world</TitleCase>       // Hello of the World
<SentenceCase>HELLO WORLD</SentenceCase>        // Hello world
<UpperCase>Hello World</UpperCase>              // HELLO WORLD
<LowerCase>Hello World</LowerCase>              // hello world
<Capitalized>hello world</Capitalized>          // Hello world
<CapitalizedWords>hello world</CapitalizedWords>// Hello World

// Dynamic formatter
<CaseFormatter format="camel">Hello World</CaseFormatter>  // helloWorld
<CaseFormatter format="pascal">Hello World</CaseFormatter> // HelloWorld

// Use with custom element type
<CamelCase as="div">Hello World</CamelCase>
<PascalCase as="h1">Hello World</PascalCase>

// Use with text prop instead of children
<CamelCase text="Hello World" />

React Hooks

import {
  useCamelCase,
  usePascalCase,
  useSnakeCase,
  useKebabCase,
  useConstantCase,
  useTitleCase,
  useSentenceCase,
  useCaseFormatter,
} from "react-case-formatter";

function MyComponent() {
  // Individual case hooks
  const [camelCaseValue, updateCamelCase] = useCamelCase("Hello World");
  const [pascalCaseValue, updatePascalCase] = usePascalCase("Hello World");

  // Or use the combined hook to get all formats at once
  const [formattedValues, updateAllFormats] = useCaseFormatter("Hello World");

  return (
    <div>
      <p>Camel Case: {camelCaseValue}</p>
      <p>Pascal Case: {pascalCaseValue}</p>

      <button onClick={() => updateCamelCase("New Example Text")}>
        Update Camel Case
      </button>

      <hr />

      <h3>All Formats:</h3>
      <p>Original: {formattedValues.original}</p>
      <p>Camel: {formattedValues.camelCase}</p>
      <p>Pascal: {formattedValues.pascalCase}</p>
      <p>Snake: {formattedValues.snakeCase}</p>
      <p>Kebab: {formattedValues.kebabCase}</p>
      <p>Constant: {formattedValues.constantCase}</p>
      <p>Title: {formattedValues.titleCase}</p>
      <p>Sentence: {formattedValues.sentenceCase}</p>

      <button onClick={() => updateAllFormats("Updated All Formats")}>
        Update All Formats
      </button>
    </div>
  );
}

Authors