-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0074592
commit a777df9
Showing
2 changed files
with
20 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,35 @@ | ||
/** | ||
* Capitalize a string | ||
* @param string - String to capitalize | ||
* @param lowercase - Whether to lowercase rest of the string | ||
*/ | ||
export const capitalize = (string: string, lowercase = false) => | ||
lowercase ? | ||
string.charAt(0).toUpperCase() + string.slice(1).toLocaleLowerCase() : | ||
string.charAt(0).toUpperCase() + string.slice(1); | ||
|
||
/** | ||
* | ||
* @param str | ||
* Change case of a string to camel case | ||
* @param string - String to change case of | ||
* @source - https://stackoverflow.com/a/2970667/1656944 | ||
*/ | ||
export const camelCase = (str: string) => | ||
str.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => | ||
export const camelCase = (string: string) => | ||
string.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => | ||
index == 0 ? word.toLowerCase() : word.toUpperCase() | ||
).replace(/\s+/g, ""); | ||
|
||
|
||
/** | ||
* | ||
* @param string | ||
* Change case of a string to kebab case | ||
* @param string - String to change case of | ||
* @source - https://gist.github.com/thevangelist/8ff91bac947018c9f3bfaad6487fa149#gistcomment-2183914 | ||
*/ | ||
export const kebabCase = (string: string) => | ||
string.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/\s+/g, "-").toLowerCase(); | ||
|
||
/** | ||
* Change case of a string to snake case | ||
* @param string - String to change case of | ||
*/ | ||
export const snakeCase = (string: string) => | ||
kebabCase(string).replace(/-/g, "_"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters