A modern TypeScript utility to convert strings and object keys between various case styles like camelCase, snake_case, PascalCase, kebab-case, spongeCase, and more.
npm install 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
---
- 📦 Supported Case Styles
- 🔧 Installation
- 🚀 Quick Usage
- 🔹 String Case Conversion
- 🔹 Object Key Case Conversion
- 📘 API Reference
- 🔹 String Methods
- 🔹 Object Key Methods
- 🌐 Live Demo
- 🔗 Links
- 📄 License
- 📬 Contact
---
- camel, pascal, snake, kebab, constant, dot, path, title, sentence, capital, train
- sponge, swap, upper, lower, no, localeUpper, localeLower, lowerFirst, upperFirst
- ... and more!
---
```bash
npm install case-converters
#### CommonJS
`js
const { camel, upper } = require("case-converters");
console.log(camel("test string")); // testString
console.log(upper("test string")); // TEST STRING
``
#### ES Modules / TypeScript
`ts
import { Case } from "case-converters";
console.log(Case.camel("test string")); // testString
console.log(Case.upper("test string")); // TEST STRING
`
---
Convert keys of an object (or array of objects):
`js
const { objToCamel, objToPascal } = require("case-converters");
const input = [{ user_name: "Alice" }, { user_name: "Bob" }];
console.log(objToCamel(input));
console.log(objToPascal(input));
`
---
You can use either the Case class or direct function imports:
`ts
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:
`ts
import { Case } from "case-converters";
Case.kebab(str);
Case.title(str);
`
---
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:
`js``
const obj = { first_name: "John", last_name: "Doe" };
console.log(objToCamel(obj));
---
Try it online:
👉 StackBlitz Live Demo
---
- 🧠 GitHub: cvchauhan/case-converter
- 📦 npm: case-converters
---
ISC © Chirag Chauhan
---
For questions, suggestions, or collaborations:
- GitHub: @cvchauhan
- Email: chiragvchauhan93@gmail.com