-
-
Notifications
You must be signed in to change notification settings - Fork 551
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add previously uncommited utils.ts file
- Loading branch information
1 parent
6997973
commit 320fe96
Showing
1 changed file
with
28 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Converts string to kebab case | ||
* | ||
* @param {string} string | ||
* @returns {string} A kebabized string | ||
*/ | ||
export const toKebabCase = (string: string) => | ||
string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(); | ||
|
||
/** | ||
* Merges classes into a single string | ||
* | ||
* @param {array} classes | ||
* @returns {string} A string of classes | ||
*/ | ||
export const mergeClasses = <ClassType = string | undefined | null>( | ||
...classes: ClassType[] | ||
) => | ||
classes | ||
.filter((className, index, array) => { | ||
return ( | ||
Boolean(className) && | ||
(className as string).trim() !== "" && | ||
array.indexOf(className) === index | ||
); | ||
}) | ||
.join(" ") | ||
.trim(); |