capitalize
Type : function
The capitalize
function capitalizes the first letter of a string or each word in a string with a custom splitter and joiner.
Usage
console.log(capitalize('hello world')); // Hello world
console.log(capitalize('hello world', { onlyFirstWord: true })); // Hello world
console.log(capitalize('hello-world')); // Hello-world
console.log(capitalize('hello-world'), { splitter: '-'}); // Hello-World
console.log(capitalize('hello-world'), { splitter: '-', joiner: ' '}); // Hello World
console.log(capitalize('hello world'), { joiner: '-'}); // Hello-World
Definition
export function capitalize(str: string, options?: Options): string {}
parameters:
str:
string- The string to capitalize
options?:
Options
returns:
string
Types
Options
type Options = { onlyFirstWord?: boolean; splitter?: string; joiner?: string;}
-
onlyFirstWord
- Whether to capitalize only the first word.
- default value is:
false
-
splitter
- The delimiter to split the string into words.
- default value is:
' '
-
joiner
- The delimiter to join the capitalized words.
- default value is:
splitter