blakeembrey / change-case

Convert strings between camelCase, PascalCase, Capital Case, snake_case and more
MIT License
2.21k stars 92 forks source link

TypeScript template literal support (`const camel: "fooBar" = camelCase("foo_bar")`) #294

Closed WofWca closed 9 months ago

WofWca commented 1 year ago

Currently the functions output simple TypeScript strings. Template literals were introduced not too long ago, so now the following is possible:

image

const camel: 'fooBar' = camelCase('foo_bar')

That is, the exact string literal is derived from the input string literal.

Here's an article on how to achieve this: https://dev.to/svehla/typescript-transform-case-strings-450b And another library already implements this (MIT license as well): https://github.com/madonoharu/literal-case/blob/8d190d865cdcaf65ed639bdc40447410202f97a8/src/types.ts

Would be cool to see it at, least for some of the functions of this library.

blakeembrey commented 9 months ago

I took a look but it's honestly too complex for me to consider maintaining for the marginal benefit it provides. You're welcome to type and maintain them here though if you'd like, but I'd probably consider keeping them separate from the main package due to the type complexity and potential build perf issues.