Registry / devops / case-formatter

case-formatter

JSON →
library1.1.2jsnpmunverified

A lightweight JavaScript/TypeScript library (v1.1.2, stable) for converting strings and object keys between camelCase, snake_case, PascalCase, and kebab-case. Provides bidirectional converters for all 4 cases via a single default export with method chaining. Supports type-safe conversions on Records using generics. Ships TypeScript types. Differentiator: simple API, full matrix of conversions (12 methods), and generic typing for object key transforms. No dependencies, works in Node and browser.

npm install case-formatter
INSTALL
IMPORT
SIG · CASE-FORMATTER
C
case-formatter
devopsjavascriptv1.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

caseFormatter
import caseFormatter from 'case-formatter';
import { caseFormatter } from 'case-formatter';
Default export only. Named import does not work.
snakeToCamel (method)
caseFormatter.snakeToCamel('my_string')
caseFormatter.snakeToCamel({my_string: 1}) // returns Record with camel keys, but no type inference without generic
For Records, pass generic to get typed result: caseFormatter.snakeToCamel<{myString: number}>({my_string: 1})
camelToSnake (method)
caseFormatter.camelToSnake('myString')
caseFormatter.snakeToCamel('myString') // wrong direction
All 12 methods are available: camelToSnake, camelToPascal, camelToKebab, snakeToCamel, snakeToPascal, snakeToKebab, pascalToCamel, pascalToSnake, pascalToKebab, kebabToCamel, kebabToSnake, kebabToPascal

Demonstrates string and object key conversion between snake_case and camelCase, plus PascalCase to kebab-case, using the library's default export.

import caseFormatter from 'case-formatter'; // Convert string const camelStr = caseFormatter.snakeToCamel('hello_world'); console.log(camelStr); // 'helloWorld' // Convert object keys const orig = { first_name: 'John', last_name: 'Doe' }; const camelObj = caseFormatter.snakeToCamel<{firstName: string, lastName: string}>(orig); console.log(camelObj); // { firstName: 'John', lastName: 'Doe' } // Other directions console.log(caseFormatter.camelToSnake('myVar')); // 'my_var' console.log(caseFormatter.pascalToKebab('MyVar')); // 'my-var' console.log(caseFormatter.kebabToPascal('my-var')); // 'MyVar'
Debug
Known issues
gotchaWhen converting object keys, the result type is Record<string, unknown> unless you pass a generic type parameter.
fix
Use generics: caseFormatter.snakeToCamel<YourType>(obj)
affects: >=1.0.0
gotchaOnly supports 4 cases (camel, snake, pascal, kebab). Other casing styles (train-case, dot.case, etc.) are not supported.
fix
Use a different library like change-case for more cases.
affects: all
gotchaThe library does not handle nested objects or arrays with object keys recursively.
fix
Manually apply conversion to nested structures or use a library like humps for recursive conversion.
affects: >=1.0.0
gotchaDefault import only; named imports cause runtime error.
fix
Use `import caseFormatter from 'case-formatter'`
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: caseFormatter.snakeToCamel is not a function
Using named import instead of default import.
fix
Change to: import caseFormatter from 'case-formatter';
Property 'snakeToCamel' does not exist on type 'typeof import("case-formatter")'
Using named import in TypeScript without default import.
fix
Use default import: import caseFormatter from 'case-formatter';
Argument of type '{ my_string: number; }' is not assignable to parameter of type 'string'.
Passing an object to the string overload of a conversion method.
fix
Pass a generic type parameter: caseFormatter.snakeToCamel<{myString: number}>({my_string: 1})
Upgrade
Version history
1.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
case-formatter — npm install case-formatter · libregistry