Skip to content

Commit f96d269

Browse files
committed
refactor: move formatSize to shared utility
Assisted-by: OpenCode (Claude Sonnet 4)
1 parent 3b7c347 commit f96d269

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

packages/opencode/src/cli/cmd/uninstall.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { UI } from "../ui"
33
import * as prompts from "@clack/prompts"
44
import { Installation } from "../../installation"
55
import { Global } from "../../global"
6+
import { formatSize } from "../../util/format"
67
import { $ } from "bun"
78
import fs from "fs/promises"
89
import path from "path"
@@ -341,13 +342,6 @@ async function getDirectorySize(dir: string): Promise<number> {
341342
return total
342343
}
343344

344-
function formatSize(bytes: number): string {
345-
if (bytes < 1024) return `${bytes} B`
346-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`
347-
if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`
348-
return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`
349-
}
350-
351345
function shortenPath(p: string): string {
352346
const home = os.homedir()
353347
if (p.startsWith(home)) {

packages/opencode/src/util/format.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
export function formatSize(bytes: number): string {
2+
if (bytes < 1024) return `${bytes} B`
3+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`
4+
if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`
5+
return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`
6+
}
7+
18
export function formatDuration(secs: number) {
29
if (secs <= 0) return ""
310
if (secs < 60) return `${secs}s`

0 commit comments

Comments
 (0)