forked from Vali-98/ChatterUI
-
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.
refactor: moved functions out of general util folder
- Loading branch information
Showing
19 changed files
with
144 additions
and
220 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 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 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 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,11 @@ | ||
export function groupBy(array: any[], key: string) { | ||
if (array.length === 0) return [] | ||
return array.reduce((result, obj) => { | ||
const keyValue = obj[key] | ||
if (!result[keyValue]) { | ||
result[keyValue] = [] | ||
} | ||
result[keyValue].push(obj) | ||
return result | ||
}, {}) | ||
} |
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,34 @@ | ||
import { DownloadDirectoryPath, writeFile } from 'cui-fs' | ||
|
||
/** | ||
* | ||
* @param data string data of file | ||
* @param filename filename to be written, include extension | ||
* @param encoding encoding of file | ||
*/ | ||
export const saveStringToDownload = async ( | ||
data: string, | ||
filename: string, | ||
encoding: 'ascii' | 'base64' | `utf8` | ||
) => { | ||
if (encoding === 'utf8') data = btoa(data) | ||
await writeFile(`${DownloadDirectoryPath}/${filename}`, data, { encoding: encoding }) | ||
} | ||
|
||
const gb = 1000 ** 3 | ||
const mb = 1000 ** 2 | ||
|
||
/** | ||
* Gets a human friendly version of file size | ||
* @param size size in bytes | ||
* @returns string containing readable file size | ||
*/ | ||
export const readableFileSize = (size: number) => { | ||
if (size < gb) { | ||
const sizeInMB = size / mb | ||
return `${sizeInMB.toFixed(2)} MB` | ||
} else { | ||
const sizeInGB = size / gb | ||
return `${sizeInGB.toFixed(2)} GB` | ||
} | ||
} |
Oops, something went wrong.