capitalize
type: function
The capitalize function capitalizes either:
- the first character in the whole string, or
- each token after splitting by a separator.
Usage
import { capitalize } from '@mustib/utils';
capitalize('hello world'); // Hello Worldcapitalize('hello world', { onlyFirstWord: true }); // Hello worldcapitalize('hello-world', { splitter: '-', joiner: ' ' }); // Hello WorldDefinition
function capitalize( str: string, options?: { onlyFirstWord?: boolean; splitter?: string; joiner?: string; },): string { }Parameters
-
strtype str = string;- Input string to capitalize.
-
optionstype options = {onlyFirstWord?: boolean,splitter?: string,joiner?: string,};options.onlyFirstWord- When true, only the first word is capitalized.
- default: false
options.splitter- Delimiter used to split the input string before capitalization.
- default: ' '
options.joiner- Delimiter used to join transformed parts.
- default: splitter
Returns
type T = string;- Capitalized output string. If input is empty, returns the original value.