refactor: dedupe cli cron trimmed readers

This commit is contained in:
Peter Steinberger
2026-04-08 00:17:07 +01:00
parent ca8685d5f2
commit df91db906f
27 changed files with 131 additions and 81 deletions

View File

@@ -1,4 +1,7 @@
import { normalizeLowercaseStringOrEmpty } from "../shared/string-coerce.js";
import {
normalizeLowercaseStringOrEmpty,
normalizeOptionalString,
} from "../shared/string-coerce.js";
export type BytesParseOptions = {
defaultUnit?: "b" | "kb" | "mb" | "gb" | "tb";
@@ -17,7 +20,7 @@ const UNIT_MULTIPLIERS: Record<string, number> = {
};
export function parseByteSize(raw: string, opts?: BytesParseOptions): number {
const trimmed = normalizeLowercaseStringOrEmpty(String(raw ?? "").trim());
const trimmed = normalizeLowercaseStringOrEmpty(normalizeOptionalString(raw) ?? "");
if (!trimmed) {
throw new Error("invalid byte size (empty)");
}