refactor(cli): extract shared node media helpers

This commit is contained in:
Peter Steinberger
2026-02-18 23:32:32 +00:00
parent 65ef7fb4a4
commit 3b7c8fe79a
5 changed files with 76 additions and 47 deletions

View File

@@ -0,0 +1,30 @@
import { randomUUID } from "node:crypto";
import * as os from "node:os";
export function asRecord(value: unknown): Record<string, unknown> {
return typeof value === "object" && value !== null ? (value as Record<string, unknown>) : {};
}
export function asString(value: unknown): string | undefined {
return typeof value === "string" ? value : undefined;
}
export function asNumber(value: unknown): number | undefined {
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
}
export function asBoolean(value: unknown): boolean | undefined {
return typeof value === "boolean" ? value : undefined;
}
export function resolveTempPathParts(opts: { ext: string; tmpDir?: string; id?: string }): {
ext: string;
tmpDir: string;
id: string;
} {
return {
tmpDir: opts.tmpDir ?? os.tmpdir(),
id: opts.id ?? randomUUID(),
ext: opts.ext.startsWith(".") ? opts.ext : `.${opts.ext}`,
};
}