@billdaddy/casekit
v0.1.1
Published
Tiny, type-safe case conversion — camel/snake/kebab/Pascal/CONSTANT/title, acronym-aware word splitting, and deep object-key transformers. Zero dependencies.
Maintainers
Readme
casekit
Tiny, type-safe case conversion — camel / snake / kebab / Pascal / CONSTANT / title, acronym-aware splitting, and deep object-key transformers. Zero dependencies.
Every codebase ends up with a toSnake/toCamel helper that almost works —
until it hits parseHTTPSResponse or a nested API payload. casekit does the
word-splitting correctly (acronyms included), gives you every common case, and —
the part most libraries skip — recursively rewrites object keys so a
snake_case API response becomes idiomatic camelCase. Zero dependencies.
import { camelCase, camelKeys } from "@billdaddy/casekit";
camelCase("parseHTTPSResponse"); // "parseHttpsResponse"
camelKeys({ user_id: 1, home_address: { zip_code: 0 } });
// { userId: 1, homeAddress: { zipCode: 0 } }Why casekit?
- Correct word splitting. Understands
camelCase,PascalCase,snake_case,kebab-case, spaces, digits, and acronym runs (XMLHttpRequest→XML·Http·Request). - Every common case. camel, Pascal, snake, kebab, CONSTANT, dot, path, Title,
Sentence, and
no case. - Deep key transformers.
camelKeys/snakeKeys/kebabKeys/pascalKeys/constantKeysrecurse through objects and arrays — immutable, and they drop prototype-pollution keys. - Unicode-aware. Splits on real letter/number boundaries, so accented text works.
- Typed & tiny. Full types, ESM + CJS, zero dependencies.
Install
npm install @billdaddy/casekit
# or: pnpm add @billdaddy/casekit / yarn add @billdaddy/casekit / bun add @billdaddy/casekitString cases
import {
camelCase, pascalCase, snakeCase, kebabCase, constantCase,
dotCase, pathCase, titleCase, sentenceCase, noCase, words,
} from "@billdaddy/casekit";
camelCase("foo_bar"); // "fooBar"
pascalCase("foo-bar"); // "FooBar"
snakeCase("fooBar"); // "foo_bar"
kebabCase("FooBar"); // "foo-bar"
constantCase("fooBar"); // "FOO_BAR"
dotCase("fooBar"); // "foo.bar"
pathCase("fooBar"); // "foo/bar"
titleCase("foo_bar"); // "Foo Bar"
sentenceCase("foo_bar"); // "Foo bar"
noCase("fooBarBaz"); // "foo bar baz"
words("parseHTTPSResponse"); // ["parse", "HTTPS", "Response"]All converters accept any casing as input and are idempotent.
Object keys
import { camelKeys, snakeKeys } from "@billdaddy/casekit";
// Normalize an API response to idiomatic JS:
const user = camelKeys(await res.json());
// { userId, homeAddress: { zipCode }, orderItems: [{ itemId }] }
// Serialize back to the API's convention:
const body = snakeKeys({ userId: 1, homeAddress: { zipCode: "x" } });
// { user_id: 1, home_address: { zip_code: "x" } }interface KeysOptions {
deep?: boolean; // recurse into nested objects/arrays (default true)
}Date, Map, class instances, and other non-plain values pass through by
reference; only plain-object keys are rewritten.
Pairs well with
| Need | Use |
| --- | --- |
| Slugify text for URLs | slugkit |
| Deep merge config objects | @billdaddy/mergekit |
| Deep equal / clone | equalkit |
Contributors ✨
This project follows the all-contributors specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the emoji key for how each contribution is recognized, and open a PR or issue to get involved.
Thanks goes to these wonderful people:
License
MIT © Tung Tran
