-
Notifications
You must be signed in to change notification settings - Fork 17
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
fix: Screaming snake case #5
fix: Screaming snake case #5
Conversation
Quero iniciar a conversação, mas eu tentarei resolver o problema. |
@jly36963 thanks for finding this out.. does the error only happens at runtime or type-level is consistent? Would you mind filing an issue meanwhile so other folks can relate to if they find such bug? |
Yup, moved the code example to an issue |
@gustavoguichard Se eu precisar mudar alguma coisa, deixe-me saber 👍 |
@jly36963 thank you very much for catching the bug and fixing it! Amazing contribution!! |
src/casing.ts
Outdated
type CamelCase<T extends string> = Words<T> extends [infer first, ...infer rest] | ||
? Join<[Lowercase<Is<first, string>>, ...CapitalizeAll<Is<rest, string[]>>]> | ||
? Join< | ||
[ | ||
Lowercase<Is<first, string>>, | ||
...CapitalizeAll<LowercaseAll<Is<rest, string[]>>>, | ||
] | ||
> | ||
: T |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the type functions in this file are mapping to the same logic as the runtime logic.
So to keep that pattern this type should probably be defined as follows:
type CamelCase<T extends string> = PascalCase<T> extends `${infer first}${infer rest}`
? `${Lowercase<first>}${rest}`
: T
function toPascalCase<T extends string>(str: T): PascalCase<T> { | ||
return capitalize(toCamelCase(str)) | ||
return words(str) | ||
.map((v) => capitalize(toLowerCase(v))) | ||
.join('') as PascalCase<T> | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whereas this type should probably be defined as:
type PascalCase<T extends string> = Join<CapitalizeAll<LowercaseAll<Words<T>>>, ''>
The
toCamelCase
anddeepCamelKeys
functions have unexpected behavior when the argument involves SCREAMING_SNAKE_CASE.Related to: #6