FIX-1847 added methods in string utils in order to utilise in our code.
This commit is contained in:
1 parent
43cf79f93e
commit
0eebd2929b
2 files changed
+35
-15
No files matched your search
+33
-14
@@ -3,8 +3,8 @@
|
||||
* @param {string} str String whose first letter is to be capitalized
|
||||
* @returns A string with first letter capitalized
|
||||
*/
|
||||
export const capitalizeFirstLetter = (str) => {
|
||||
if (str === null || str === undefined) {
|
||||
export const capitalizeFirstLetter = (str) => {
|
||||
if (str === null || str === undefined) {
|
||||
return "";
|
||||
}
|
||||
if (typeof str !== "string") {
|
||||
@@ -12,7 +12,7 @@ export const capitalizeFirstLetter = (str) => {
|
||||
}
|
||||
if (str.length === 0) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||
};
|
||||
|
||||
@@ -22,15 +22,34 @@ export const capitalizeFirstLetter = (str) => {
|
||||
* @returns A string with first letter lower cased
|
||||
*/
|
||||
|
||||
export const toLowerCaseFirstLetter = (str) => {
|
||||
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);
|
||||
};
|
||||
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);
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if a string is null, undefined, or empty (including strings with only whitespace).
|
||||
* @param {string} str - The string to check.
|
||||
* @returns {boolean} - Returns true if the string is null, undefined, or empty.
|
||||
*/
|
||||
export const isEmpty = (str) => {
|
||||
// Check if string is null, undefined, or empty (including whitespace only)
|
||||
return str === null || str === undefined || str.trim().length === 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if a string is not null, undefined, and not empty (including strings with only whitespace).
|
||||
* @param {string} str - The string to check.
|
||||
* @returns {boolean} - Returns true if the string is not null, undefined, and not empty.
|
||||
*/
|
||||
export const isNotEmpty = (str) => {
|
||||
return !isEmpty(str);
|
||||
};
|
||||
Reference in new issue
Block a user