-
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
622dde5
commit dc5380b
Showing
9 changed files
with
57 additions
and
67 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
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
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
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
This file was deleted.
Oops, something went wrong.
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,8 @@ | ||
export function groupBy<T>(arr: T[], key: (item: T) => string): Record<string, T[]> { | ||
return arr.reduce((groups, item) => { | ||
const k = key(item); | ||
if (!groups[k]) groups[k] = []; | ||
groups[k].push(item); | ||
return groups; | ||
}, {} as Record<string, T[]>); | ||
} |
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,5 @@ | ||
export * from './string.utils'; | ||
export * from './color.utils'; | ||
export * from './array.utils'; | ||
export * from './gradient.utils'; | ||
export * from './node.utils'; |
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
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,29 @@ | ||
export function toBase64(str: string): string { | ||
const base64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; | ||
const utf8str = encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, | ||
(_, p1) => String.fromCharCode(parseInt(p1, 16)) | ||
); | ||
let i = 0; | ||
let result = ''; | ||
while (i < utf8str.length) { | ||
const char1 = utf8str.charCodeAt(i++); | ||
const char2 = i < utf8str.length ? utf8str.charCodeAt(i++) : NaN; | ||
const char3 = i < utf8str.length ? utf8str.charCodeAt(i++) : NaN; | ||
const enc1 = char1 >> 2; | ||
const enc2 = ((char1 & 3) << 4) | (char2 >> 4); | ||
const enc3 = ((char2 & 15) << 2) | (char3 >> 6); | ||
const enc4 = char3 & 63; | ||
result += base64chars[enc1] + base64chars[enc2] + | ||
(isNaN(char2) ? '=' : base64chars[enc3]) + | ||
(isNaN(char3) ? '=' : base64chars[enc4]); | ||
} | ||
return result; | ||
} | ||
|
||
export function sanitizeName(name: string): string { | ||
return name.toLowerCase().replace(/[^a-z0-9]/g, '-'); | ||
} | ||
|
||
export function sanitizeSegment(segment: string): string { | ||
return segment.toLowerCase().replace(/[^a-z0-9]/g, '-'); | ||
} |