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

Handle CamelCase with non-literal strings #531

Merged
merged 1 commit into from Dec 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion source/camel-case.d.ts
Expand Up @@ -74,5 +74,7 @@ const dbResult: CamelCasedProperties<RawOptions> = {
@category Template literal
*/
export type CamelCase<Type, Options extends CamelCaseOptions = {preserveConsecutiveUppercase: true}> = Type extends string
? Uncapitalize<CamelCaseFromArray<SplitWords<Type extends Uppercase<Type> ? Lowercase<Type> : Type>, Options>>
? string extends Type
? Type
: Uncapitalize<CamelCaseFromArray<SplitWords<Type extends Uppercase<Type> ? Lowercase<Type> : Type>, Options>>
: Type;
3 changes: 3 additions & 0 deletions test-d/camel-case.ts
Expand Up @@ -75,3 +75,6 @@ expectType<CamelCase<'fooBARBiz', {preserveConsecutiveUppercase: false}>>('fooBa

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

expectType<CamelCase<string>>('string' as string);
expectType<CamelCase<string, {preserveConsecutiveUppercase: false}>>('string' as string);