Files
rclone-ui/lib/format.ts
T

34 lines
922 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export function formatBytes(bytes: number) {
// format bytes in to a readable format like (MB, GB, etc), depending on how big the number is
if (bytes < 1024) {
return `${bytes} B`
}
if (bytes < 1024 * 1024) {
return `${(bytes / 1024).toFixed(2)} KB`
}
if (bytes < 1024 * 1024 * 1024) {
return `${(bytes / 1024 / 1024).toFixed(2)} MB`
}
return `${(bytes / 1024 / 1024 / 1024).toFixed(2)} GB`
}
export function replaceSmartQuotes(value: string) {
const replacements: { [key: string]: string } = {
'': "'",
'': "'",
'': "'",
'“': '"',
'”': '"',
'„': '"',
}
return value.replace(/[‘’‚“”„]/g, (match) => replacements[match])
}
export function getRemoteName(path?: string) {
if (!path?.includes(':')) return null // Return null for local paths
return path.split(':')[0]
}