Skip to content

Commit

Permalink
✨ - feat: update field2caption function to add spaces to captions
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvandescheur committed Mar 8, 2024
1 parent d8f7a55 commit 3b825ef
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/lib/format/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ export const REGEX_URL = /https?:\/\/[^\s]+$/;
export const isLink = (string: string): boolean =>
Boolean(string.match(REGEX_URL));

/**
* Converts "fieldName" to "field Name".
* @param string
*/
export const addSpaces = (string: string) =>
string.replaceAll(/(?<=[a-z])([A-Z])/g, (match) => " " + match);

/**
* Converts "field_name" to "FIELD NAME".
* @param field
Expand All @@ -19,7 +26,8 @@ export const field2Caption = (field: string): string =>
* Converts "field_name" to "Field name".
* @param field
*/
export const field2Title = (field: string): string => ucFirst(unHyphen(field));
export const field2Title = (field: string): string =>
ucFirst(addSpaces(unHyphen(field)).toLowerCase());

/**
* Converts "Some object name" to "some-object-name".
Expand Down

0 comments on commit 3b825ef

Please sign in to comment.