@flxwkg/case-converter
v1.0.0
Published
Zero-dependency utility to convert strings between camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE, dot.case, Title Case and more.
Maintainers
Readme
case-converter
Zero-dependency utility to convert strings between all common case formats.
Features
- 🔄 8 case formats supported
- 🔍 Automatic case detection
- 🌍 Accent removal (
héllo→hello) - 🔢 Digit-aware tokenization (
hello2World→hello2_world) - 📦 Zero dependencies
- 🟦 TypeScript types included
- ⚡ Works in Node.js (ESM & CJS)
Install
npm install case-converterUsage
import {
toCamelCase,
toPascalCase,
toSnakeCase,
toKebabCase,
toConstantCase,
toDotCase,
toTitleCase,
toFlatCase,
detectCase,
convertCase,
} from 'case-converter';Converters
| Function | Input | Output |
|-------------------|-----------------|-----------------|
| toCamelCase | hello world | helloWorld |
| toPascalCase | hello world | HelloWorld |
| toSnakeCase | hello world | hello_world |
| toKebabCase | hello world | hello-world |
| toConstantCase | hello world | HELLO_WORLD |
| toDotCase | hello world | hello.world |
| toTitleCase | hello world | Hello World |
| toFlatCase | helloWorld | hello world |
All converters accept any input format:
toCamelCase('hello_world') // 'helloWorld'
toCamelCase('hello-world') // 'helloWorld'
toCamelCase('HelloWorld') // 'helloWorld'
toCamelCase('héllo wörld') // 'helloWorld'
toCamelCase('hello2World') // 'hello2World'detectCase(str)
Detect the case format of a string:
detectCase('helloWorld') // 'camel'
detectCase('HelloWorld') // 'pascal'
detectCase('hello_world') // 'snake'
detectCase('hello-world') // 'kebab'
detectCase('HELLO_WORLD') // 'constant'
detectCase('hello.world') // 'dot'
detectCase('Hello World') // 'title'
detectCase('hello world') // 'flat'
detectCase('???') // 'unknown'convertCase(str, to)
Convert from any format to a target format:
convertCase('hello_world', 'camel') // 'helloWorld'
convertCase('helloWorld', 'kebab') // 'hello-world'
convertCase('hello world', 'constant') // 'HELLO_WORLD'Valid target values: 'camel', 'pascal', 'snake', 'kebab', 'constant', 'dot', 'title', 'flat'
ESM & CommonJS
You don't have to choose — Node.js picks the right format automatically based on your project setup thanks to the npm run build command.
// Modern project (ESM) — package.json has "type": "module"
import { toCamelCase } from 'case-converter';
// Older project (CJS) — default Node.js setup
const { toCamelCase } = require('case-converter');Both work out of the box, no configuration needed.
License
MIT
