Skip to content

Commit

Permalink
enhanced with suggestions 2
Browse files Browse the repository at this point in the history
  • Loading branch information
SwanandBhuskute committed Nov 14, 2024
1 parent cc88800 commit f13a324
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/Utils/stringUtils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Converts a string to camelCase format, first word - lowercase and each subsequent word - uppercase letter, with no spaces.
export const camelCase = (str: string) => {
if (!str) return "";
return str
.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, (match, index) =>
index === 0 ? match.toLowerCase() : match.toUpperCase(),
)
.replace(/\s+/g, "")
.replace(/([A-Z])/g, (match) => match.toLowerCase());
.trim()
.replace(/[-_\s]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ""))
.replace(/^[A-Z]/, (c) => c.toLowerCase());
};

// Capitalize the first letter of each word in a string, handling edge cases
Expand All @@ -23,5 +22,7 @@ export const startCase = (str: string): string => {

// Capitalize the first letter of a string
export const capitalize = (str: string) => {
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
if (!str) return "";
if (str.length === 1) return str.toUpperCase();
return str.charAt(0).toUpperCase() + str.slice(1);
};
4 changes: 3 additions & 1 deletion src/components/Facility/Investigations/Reports/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const memoize = <T extends (...args: any[]) => any>(fn: T): T => {
const key = args
.map((arg) =>
typeof arg === "object"
? JSON.stringify(Object.entries(arg).sort())
? arg instanceof Date
? arg.getTime().toString()
: JSON.stringify(Object.entries(arg).sort())
: String(arg),
)
.join("|");
Expand Down

0 comments on commit f13a324

Please sign in to comment.