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 e5fa551
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "radash",
"version": "12.1.0",
"version": "12.1.1",
"description": "Functional utility library - modern, simple, typed, powerful",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand Down
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 e5fa551

Please sign in to comment.