Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preserveConsecutiveUppercase option to CamelCase and add SplitWords type #501

Merged
merged 10 commits into from
Nov 4, 2022

Conversation

skarab42
Copy link
Collaborator

@skarab42 skarab42 commented Oct 21, 2022

Fix #224
Fix #488

expectType<CamelCase<'fooBAR'>>('fooBAR');
expectType<CamelCase<'fooBAR', {preserveConsecutiveUppercase: false}>>('fooBar');

expectType<CamelCase<'fooBARBiz'>>('fooBARBiz');
expectType<CamelCase<'fooBARBiz', {preserveConsecutiveUppercase: false}>>('fooBarBiz');

expectType<CamelCase<'foo BAR-Biz_BUZZ'>>('fooBARBizBUZZ');
expectType<CamelCase<'foo BAR-Biz_BUZZ', {preserveConsecutiveUppercase: false}>>('fooBarBizBuzz');

In anticipation for #336 this PR also adds the SplitWords type (internal for now).

type Words0 = SplitWords<'helloWorld'>; // ['hello', 'World']
type Words1 = SplitWords<'helloWORLD'>; // ['hello', 'WORLD']
type Words2 = SplitWords<'hello-world'>; // ['hello', 'world']
type Words3 = SplitWords<'--hello the_world'>; // ['hello', 'the', 'world']
type Words4 = SplitWords<'lifeIs42'>; // ['life', 'Is', '42']

@skarab42 skarab42 requested a review from voxpelli as a code owner October 21, 2022 14:56
@skarab42 skarab42 requested a review from sindresorhus November 4, 2022 06:11
@sindresorhus sindresorhus merged commit b11f017 into sindresorhus:main Nov 4, 2022
@sindresorhus
Copy link
Owner

Nice work 👍

@RichiCoder1
Copy link

RichiCoder1 commented Mar 6, 2023

It seems like this PR and camelcase have two different behaviors:

  • camelCase("TPSCode", { preserveConsecutiveUppercase: true}) => TPSCode
  • CamelCase<'TPSCode', {preserveConsecutiveUppercase: true}> => tPSCode

Is there anyway to fix or consolidate this behavior?

@skarab42
Copy link
Collaborator Author

skarab42 commented Mar 7, 2023

Is there anyway to fix or consolidate this behavior?

@RichiCoder1 As a temporary fix you can use Capitalize

@ulken
Copy link
Contributor

ulken commented Nov 13, 2023

Since PascalCase uses CamelCase under the hood, I'd expect the options to propagate. Upgrading broke existing usages of PascalCase, without (seemingly) any way to get the old behavior back.

I can work around it, but I still think it should be configurable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants