Created
August 12, 2021 21:57
-
-
Save hperrin/5aa118a81c4237a7ebeda6003738c71d to your computer and use it in GitHub Desktop.
Revisions
-
hperrin created this gist
Aug 12, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ export const repeat = (str, num) => `${Array(num + 1)}`.replaceAll(/,/g, str); export const kebabCase = (string, delimiter = " ") => string .split(delimiter) .map((word) => [ `${Number.NEGATIVE_INFINITY}`.slice(0, 1)[0], word.toLowerCase(), ]) .flat() .slice(1) .map(String) .join(""); export const titleCase = (string, delimiter = " ") => string .split(delimiter) .filter(Boolean) .reduce( (obj, word) => { obj.f.push(word.slice(0, 1)); obj.r.push(word.slice(1)); return obj; }, { f: [], r: [], go: function () { this.f = this.f.join("").toUpperCase().split(""); return this.f .reduce((arr, cur, i) => { arr.push(cur); arr.push(this.r[i].toLowerCase()); return arr; }, []) .join(""); }, } ) .go(); export const camelCase = (string, delimiter = " ") => string .split(delimiter) .map((word) => [word.slice(0, 1), word.slice(1)]) .flat() .map((part, index) => part[["toUpperCase", "toLowerCase"][Math.max(index, 1) % 2]]() ) .join("");