mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:51:36 +00:00
31 lines
934 B
TypeScript
31 lines
934 B
TypeScript
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}`,
|
|
};
|
|
}
|