mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 14:30:22 +00:00
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { normalizeLowercaseStringOrEmpty } from "../shared/string-coerce.js";
|
|
|
|
export function resolveAccountEntry<T>(
|
|
accounts: Record<string, T> | undefined,
|
|
accountId: string,
|
|
): T | undefined {
|
|
if (!accounts || typeof accounts !== "object") {
|
|
return undefined;
|
|
}
|
|
if (Object.hasOwn(accounts, accountId)) {
|
|
return accounts[accountId];
|
|
}
|
|
const normalized = normalizeLowercaseStringOrEmpty(accountId);
|
|
const matchKey = Object.keys(accounts).find(
|
|
(key) => normalizeLowercaseStringOrEmpty(key) === normalized,
|
|
);
|
|
return matchKey ? accounts[matchKey] : undefined;
|
|
}
|
|
|
|
export function resolveNormalizedAccountEntry<T>(
|
|
accounts: Record<string, T> | undefined,
|
|
accountId: string,
|
|
normalizeAccountId: (accountId: string) => string,
|
|
): T | undefined {
|
|
if (!accounts || typeof accounts !== "object") {
|
|
return undefined;
|
|
}
|
|
if (Object.hasOwn(accounts, accountId)) {
|
|
return accounts[accountId];
|
|
}
|
|
const normalized = normalizeAccountId(accountId);
|
|
const matchKey = Object.keys(accounts).find((key) => normalizeAccountId(key) === normalized);
|
|
return matchKey ? accounts[matchKey] : undefined;
|
|
}
|