mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 17:21:37 +00:00
refactor(cli): extract shared node media helpers
This commit is contained in:
30
src/cli/nodes-media-utils.ts
Normal file
30
src/cli/nodes-media-utils.ts
Normal 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}`,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user