mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-03-28 19:49:25 +01:00
25 lines
768 B
TypeScript
25 lines
768 B
TypeScript
export function formatSpeed(bytesPerSecond: number): string {
|
|
if (bytesPerSecond < 1024) return `${bytesPerSecond.toFixed(0)} B/s`
|
|
if (bytesPerSecond < 1024 * 1024) return `${(bytesPerSecond / 1024).toFixed(1)} KB/s`
|
|
return `${(bytesPerSecond / (1024 * 1024)).toFixed(1)} MB/s`
|
|
}
|
|
|
|
export function toTitleCase(str: string): string {
|
|
return str
|
|
.toLowerCase()
|
|
.split(' ')
|
|
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
.join(' ')
|
|
}
|
|
|
|
export function parseBoolean(value: any): boolean {
|
|
if (typeof value === 'boolean') return value
|
|
if (typeof value === 'string') {
|
|
const lower = value.toLowerCase()
|
|
return lower === 'true' || lower === '1'
|
|
}
|
|
if (typeof value === 'number') {
|
|
return value === 1
|
|
}
|
|
return false
|
|
} |