mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 23:40:45 +00:00
29 lines
1014 B
TypeScript
29 lines
1014 B
TypeScript
export function normalizeStringEntries(list?: Array<string | number>) {
|
|
return (list ?? []).map((entry) => String(entry).trim()).filter(Boolean);
|
|
}
|
|
|
|
export function normalizeStringEntriesLower(list?: Array<string | number>) {
|
|
return normalizeStringEntries(list).map((entry) => entry.toLowerCase());
|
|
}
|
|
|
|
export function normalizeHyphenSlug(raw?: string | null) {
|
|
const trimmed = raw?.trim().toLowerCase() ?? "";
|
|
if (!trimmed) {
|
|
return "";
|
|
}
|
|
const dashed = trimmed.replace(/\s+/g, "-");
|
|
const cleaned = dashed.replace(/[^a-z0-9#@._+-]+/g, "-");
|
|
return cleaned.replace(/-{2,}/g, "-").replace(/^[-.]+|[-.]+$/g, "");
|
|
}
|
|
|
|
export function normalizeAtHashSlug(raw?: string | null) {
|
|
const trimmed = raw?.trim().toLowerCase() ?? "";
|
|
if (!trimmed) {
|
|
return "";
|
|
}
|
|
const withoutPrefix = trimmed.replace(/^[@#]+/, "");
|
|
const dashed = withoutPrefix.replace(/[\s_]+/g, "-");
|
|
const cleaned = dashed.replace(/[^a-z0-9-]+/g, "-");
|
|
return cleaned.replace(/-{2,}/g, "-").replace(/^-+|-+$/g, "");
|
|
}
|