- add lower case first letter string util func

This commit is contained in:
Shemy Gan
2024-12-04 13:33:42 -05:00
parent 5df7ddbe0f
commit 0759b16f9e

View File

@@ -15,3 +15,22 @@ export const capitalizeFirstLetter = (str) => {
}
return str.charAt(0).toUpperCase() + str.slice(1);
};
/**
* Helper function to get first letter as a lower case string
* @param {string} str String whose first letter is to be lower cased
* @returns A string with first letter lower cased
*/
export const toLowerCaseFirstLetter = (str) => {
if (str === null || str === undefined) {
return "";
}
if (typeof str !== "string") {
throw new TypeError("Input must be a string");
}
if (str.length === 0) {
return "";
}
return str.charAt(0).toLowerCase() + str.slice(1);
};