Skip to content

Commit

Permalink
feat(capitalize): make types for capitalize infer format for constant…
Browse files Browse the repository at this point in the history
… strings
  • Loading branch information
rafawendel committed Jun 24, 2024
1 parent 069b26c commit c043ccf
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
* capitalize('hello') -> 'Hello'
* capitalize('va va voom') -> 'Va va voom'
*/
export const capitalize = (str: string): string => {
if (!str || str.length === 0) return ''
export const capitalize = <Str extends string>(str: Str): Capitalize<Str> => {
if (!str || str.length === 0) return '' as Capitalize<Str>
const lower = str.toLowerCase()
return lower.substring(0, 1).toUpperCase() + lower.substring(1, lower.length)
return (lower.substring(0, 1).toUpperCase() +
lower.substring(1, lower.length)) as Capitalize<Str>
}

/**
Expand Down

0 comments on commit c043ccf

Please sign in to comment.