Files
openclaw/ui/src/lib/select-options.ts
2026-07-06 08:04:18 -07:00

26 lines
597 B
TypeScript

// Control UI module implements select options behavior.
import { normalizeLowercaseStringOrEmpty } from "./string-coerce.ts";
type SelectOption = {
value: string;
label: string;
};
export function pushUniqueTrimmedSelectOption(
options: SelectOption[],
seen: Set<string>,
value: string,
labelForValue: (trimmed: string) => string,
) {
const trimmed = value.trim();
if (!trimmed) {
return;
}
const key = normalizeLowercaseStringOrEmpty(trimmed);
if (seen.has(key)) {
return;
}
seen.add(key);
options.push({ value: trimmed, label: labelForValue(trimmed) });
}