mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-13 02:01:16 +00:00
refactor: dedupe plugin string list helpers
This commit is contained in:
@@ -6,6 +6,25 @@ export function normalizeStringEntriesLower(list?: ReadonlyArray<unknown>) {
|
||||
return normalizeStringEntries(list).map((entry) => entry.toLowerCase());
|
||||
}
|
||||
|
||||
export function normalizeTrimmedStringList(value: unknown): string[] {
|
||||
if (!Array.isArray(value)) {
|
||||
return [];
|
||||
}
|
||||
return value.flatMap((entry) =>
|
||||
typeof entry === "string" && entry.trim() ? [entry.trim()] : [],
|
||||
);
|
||||
}
|
||||
|
||||
export function normalizeSingleOrTrimmedStringList(value: unknown): string[] {
|
||||
if (Array.isArray(value)) {
|
||||
return normalizeTrimmedStringList(value);
|
||||
}
|
||||
if (typeof value === "string" && value.trim()) {
|
||||
return [value.trim()];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
export function normalizeHyphenSlug(raw?: string | null) {
|
||||
const trimmed = raw?.trim().toLowerCase() ?? "";
|
||||
if (!trimmed) {
|
||||
|
||||
Reference in New Issue
Block a user