upperFirst
string
Converts the first character of string to upper case.
Installation
Import
import { upperFirst } from '@tulx/utils';Source Code
Implementation
/**
* Converts the first character of string to upper case.
*
* @param string - The string to convert.
* @returns Returns the converted string.
*
* @example
* ```ts
* upperFirst('fred'); // 'Fred'
* upperFirst('FRED'); // 'FRED'
* ```
*/
export function upperFirst(string: string): string {
if (string.length === 0) {
return string;
}
return string.charAt(0).toUpperCase() + string.slice(1);
}
Example
import { upperFirst } from '@tulx/utils';
upperFirst('fred'); // 'Fred'
upperFirst('FRED'); // 'FRED'Related Functions
camelCase
Converts string to camel case.
capitalize
Converts the first character of string to upper case and the remaining to lower case.
deburr
Deburrs string by converting Latin-1 Supplement and Latin Extended-A letters to basic Latin letters and removing combining diacritical marks.
endsWith
Checks if string ends with the given target string.
escape
Converts the characters "&", "<", ">", '"', and "'" in string to their corresponding HTML entities.
escapeRegExp
Escapes the RegExp special characters "^", "$", "\", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in string.