mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 04:41:25 +00:00
refactor: extract shared string normalization helpers
This commit is contained in:
@@ -1,21 +1,20 @@
|
||||
import type { AllowlistMatch } from "../../channels/allowlist-match.js";
|
||||
import {
|
||||
normalizeHyphenSlug,
|
||||
normalizeStringEntries,
|
||||
normalizeStringEntriesLower,
|
||||
} from "../../shared/string-normalization.js";
|
||||
|
||||
export function normalizeSlackSlug(raw?: string) {
|
||||
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, "");
|
||||
return normalizeHyphenSlug(raw);
|
||||
}
|
||||
|
||||
export function normalizeAllowList(list?: Array<string | number>) {
|
||||
return (list ?? []).map((entry) => String(entry).trim()).filter(Boolean);
|
||||
return normalizeStringEntries(list);
|
||||
}
|
||||
|
||||
export function normalizeAllowListLower(list?: Array<string | number>) {
|
||||
return normalizeAllowList(list).map((entry) => entry.toLowerCase());
|
||||
return normalizeStringEntriesLower(list);
|
||||
}
|
||||
|
||||
export type SlackAllowListMatch = AllowlistMatch<
|
||||
|
||||
Reference in New Issue
Block a user