Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

case-converters

cvchauhan61ISC4.2.4TypeScript support: included

A modern TypeScript utility to convert strings and object keys between various case styles like camelCase, snake_case, PascalCase, kebab-case, spongeCase, and more.

case converter, string case, object key converter, camelCase, snake_case, PascalCase, kebab-case, train-case, title-case, sentence-case, constant-case, spongeCase, swapCase, upper-case, lower-case, text transform, case transformation, typescript, javascript, convert case, string casing, camel, capital, constant, dot, no, pascal, path, sentence, snake, train, kebab, sponge, swap, title, upper, locale-upper, lower, locale-lower, lower-first, upper-first, is-upper, is-lower

readme

case-converters

npm version npm downloads license

⚠️ Not to be confused with the deprecated case-converter.
case-converters is a modern, actively maintained package with full TypeScript support, robust object key transformation, and support for 15+ string casing styles.


case-converters is a lightweight yet powerful utility to convert strings and object keys into a wide range of naming conventions — like camelCase, PascalCase, snake_case, kebab-case, Train-Case, SpongeCase, and more.

  • ✔ Supports string and object key transformation
  • ✔ Works with arrays of objects
  • ✔ ESM & CommonJS compatible
  • ✔ 100% written in TypeScript

📚 Table of Contents


📦 Supported Case Styles

  • camel, pascal, snake, kebab, constant, dot, path, title, sentence, capital, train
  • sponge, swap, upper, lower, no, localeUpper, localeLower, lowerFirst, upperFirst
  • ... and more!

🔧 Installation

npm install case-converters

## 🚀 Quick Usage

### 🔹 String Case Conversion

#### CommonJS

```js
const { camel, upper } = require("case-converters");

console.log(camel("test string")); // testString
console.log(upper("test string")); // TEST STRING

ES Modules / TypeScript

import { Case } from "case-converters";

console.log(Case.camel("test string")); // testString
console.log(Case.upper("test string")); // TEST STRING

🔹 Object Key Case Conversion

Convert keys of an object (or array of objects):

const { objToCamel, objToPascal } = require("case-converters");

const input = [{ user_name: "Alice" }, { user_name: "Bob" }];

console.log(objToCamel(input));
console.log(objToPascal(input));

📘 API Reference

🔹 String Methods

You can use either the Case class or direct function imports:

import {
  camel,
  capital,
  constant,
  dot,
  no,
  pascal,
  path,
  sentence,
  snake,
  train,
  kebab,
  sponge,
  swap,
  title,
  upper,
  localeUpper,
  lower,
  localeLower,
  lowerFirst,
  upperFirst,
  isUpper,
  isLower,
} from "case-converters";

const str = "test string";

camel(str);
pascal(str);
snake(str);
// ...

Or use the class style:

import { Case } from "case-converters";

Case.kebab(str);
Case.title(str);

🔹 Object Key Methods

Available functions:

  • objToCamel(obj)
  • objToPascal(obj)
  • objToSnake(obj)
  • objToKebab(obj)
  • objToConstant(obj)
  • objToCapital(obj)
  • objToTrain(obj)
  • objToTitle(obj)
  • objToSentence(obj)
  • objToDot(obj)
  • objToPath(obj)
  • objToNot(obj)
  • objToSponge(obj)
  • objToSwap(obj)
  • objToUpper(obj)
  • objToLower(obj)

Example:

const obj = { first_name: "John", last_name: "Doe" };
console.log(objToCamel(obj));

🌐 Live Demo

Try it online:
👉 StackBlitz Live Demo



📄 License

ISC © Chirag Chauhan


📬 Contact

For questions, suggestions, or collaborations: