- add lower case first letter string util func
This commit is contained in:
1 parent
5df7ddbe0f
commit
0759b16f9e
1 file changed
+19
@@ -15,3 +15,22 @@ export const capitalizeFirstLetter = (str) => {
|
|||||||
}
|
}
|
||||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
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);
|
||||||
|
};
|
||||||
Reference in new issue
Block a user