mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 02:20:22 +00:00
refactor: share trimmed string entry normalization
This commit is contained in:
@@ -9,6 +9,11 @@ import {
|
||||
describe("shared/string-normalization", () => {
|
||||
it("normalizes mixed allow-list entries", () => {
|
||||
expect(normalizeStringEntries([" a ", 42, "", " ", "z"])).toEqual(["a", "42", "z"]);
|
||||
expect(normalizeStringEntries([" ok ", null, { toString: () => " obj " }])).toEqual([
|
||||
"ok",
|
||||
"null",
|
||||
"obj",
|
||||
]);
|
||||
expect(normalizeStringEntries(undefined)).toEqual([]);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
export function normalizeStringEntries(list?: Array<string | number>) {
|
||||
export function normalizeStringEntries(list?: ReadonlyArray<unknown>) {
|
||||
return (list ?? []).map((entry) => String(entry).trim()).filter(Boolean);
|
||||
}
|
||||
|
||||
export function normalizeStringEntriesLower(list?: Array<string | number>) {
|
||||
export function normalizeStringEntriesLower(list?: ReadonlyArray<unknown>) {
|
||||
return normalizeStringEntries(list).map((entry) => entry.toLowerCase());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user