mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 04:31:10 +00:00
refactor: dedupe cli lowercase helpers
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { normalizeLowercaseStringOrEmpty } from "../shared/string-coerce.js";
|
||||
|
||||
export type BytesParseOptions = {
|
||||
defaultUnit?: "b" | "kb" | "mb" | "gb" | "tb";
|
||||
};
|
||||
@@ -15,9 +17,7 @@ const UNIT_MULTIPLIERS: Record<string, number> = {
|
||||
};
|
||||
|
||||
export function parseByteSize(raw: string, opts?: BytesParseOptions): number {
|
||||
const trimmed = String(raw ?? "")
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
const trimmed = normalizeLowercaseStringOrEmpty(String(raw ?? "").trim());
|
||||
if (!trimmed) {
|
||||
throw new Error("invalid byte size (empty)");
|
||||
}
|
||||
@@ -32,7 +32,7 @@ export function parseByteSize(raw: string, opts?: BytesParseOptions): number {
|
||||
throw new Error(`invalid byte size: ${raw}`);
|
||||
}
|
||||
|
||||
const unit = (m[2] ?? opts?.defaultUnit ?? "b").toLowerCase();
|
||||
const unit = normalizeLowercaseStringOrEmpty(m[2] ?? opts?.defaultUnit ?? "b");
|
||||
const multiplier = UNIT_MULTIPLIERS[unit];
|
||||
if (!multiplier) {
|
||||
throw new Error(`invalid byte size unit: ${raw}`);
|
||||
|
||||
Reference in New Issue
Block a user