mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: auto detect syntax from file extension on drag and drop; syntax from extension function
refactor: syntax type with display and extension
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { syntaxes } from "$lib/consts";
|
||||
|
||||
export function formatBytes(bytes: number, decimals = 2): string {
|
||||
if (bytes === 0) return '0 Bytes';
|
||||
|
||||
@@ -56,6 +58,16 @@ export function extractError(resData: unknown): string | null {
|
||||
return null;
|
||||
}
|
||||
|
||||
export function syntaxFromExtension(extension: string): string | null {
|
||||
const ext = extension.startsWith('.') ? extension.slice(1) : extension;
|
||||
for (const [key, value] of Object.entries(syntaxes)) {
|
||||
if (value.extension === `.${ext}`) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function dateToRelativeString(
|
||||
date: Date,
|
||||
useSuffix = true,
|
||||
|
||||
Reference in New Issue
Block a user