FIX-1847 added methods in string utils in order to utilise in our code.

This commit is contained in:
Owaise Imdad committed 2025-03-04 09:00:37 +05:30
1 parent 43cf79f93e
commit 0eebd2929b
2 files changed
+35 -15

No files matched your search

+2 -1
View File
@@ -1,4 +1,5 @@
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { isEmpty } from "../stringUtils";
/** /**
* Utility function to render a truncated value with an optional title. * Utility function to render a truncated value with an optional title.
@@ -15,7 +16,7 @@ export const renderTruncatedValue = function (
maxLength, maxLength,
placeholder placeholder
) { ) {
if (!displayName || displayName === "0") return placeholder; if (isEmpty(displayName)) return placeholder;
const truncateTextWithDottedEnds = function (text, maxLength) { const truncateTextWithDottedEnds = function (text, maxLength) {
if (!text || text.length <= maxLength) return text; if (!text || text.length <= maxLength) return text;
+33 -14
View File
@@ -3,8 +3,8 @@
* @param {string} str String whose first letter is to be capitalized * @param {string} str String whose first letter is to be capitalized
* @returns A string with first letter capitalized * @returns A string with first letter capitalized
*/ */
export const capitalizeFirstLetter = (str) => { export const capitalizeFirstLetter = (str) => {
if (str === null || str === undefined) { if (str === null || str === undefined) {
return ""; return "";
} }
if (typeof str !== "string") { if (typeof str !== "string") {
@@ -12,7 +12,7 @@ export const capitalizeFirstLetter = (str) => {
} }
if (str.length === 0) { if (str.length === 0) {
return ""; return "";
} }
return str.charAt(0).toUpperCase() + str.slice(1); return str.charAt(0).toUpperCase() + str.slice(1);
}; };
@@ -22,15 +22,34 @@ export const capitalizeFirstLetter = (str) => {
* @returns A string with first letter lower cased * @returns A string with first letter lower cased
*/ */
export const toLowerCaseFirstLetter = (str) => { export const toLowerCaseFirstLetter = (str) => {
if (str === null || str === undefined) { if (str === null || str === undefined) {
return ""; return "";
} }
if (typeof str !== "string") { if (typeof str !== "string") {
throw new TypeError("Input must be a string"); throw new TypeError("Input must be a string");
} }
if (str.length === 0) { if (str.length === 0) {
return ""; return "";
} }
return str.charAt(0).toLowerCase() + str.slice(1); 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);
};