mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 20:51:10 +00:00
refactor: dedupe locale lowercase helpers
This commit is contained in:
@@ -380,6 +380,7 @@ export async function snapshotDom(opts: {
|
||||
const expression = `(() => {
|
||||
const maxNodes = ${JSON.stringify(limit)};
|
||||
const maxText = ${JSON.stringify(maxTextChars)};
|
||||
const lower = (value) => String(value || "").toLocaleLowerCase();
|
||||
const nodes = [];
|
||||
const root = document.documentElement;
|
||||
if (!root) return { nodes };
|
||||
@@ -389,7 +390,7 @@ export async function snapshotDom(opts: {
|
||||
const el = cur.el;
|
||||
if (!el || el.nodeType !== 1) continue;
|
||||
const ref = "n" + String(nodes.length + 1);
|
||||
const tag = (el.tagName || "").toLowerCase();
|
||||
const tag = lower(el.tagName);
|
||||
const id = el.id ? String(el.id) : undefined;
|
||||
const className = el.className ? String(el.className).slice(0, 300) : undefined;
|
||||
const role = el.getAttribute && el.getAttribute("role") ? String(el.getAttribute("role")) : undefined;
|
||||
@@ -510,9 +511,10 @@ export async function querySelector(opts: {
|
||||
const lim = ${JSON.stringify(limit)};
|
||||
const maxText = ${JSON.stringify(maxText)};
|
||||
const maxHtml = ${JSON.stringify(maxHtml)};
|
||||
const lower = (value) => String(value || "").toLocaleLowerCase();
|
||||
const els = Array.from(document.querySelectorAll(sel)).slice(0, lim);
|
||||
return els.map((el, i) => {
|
||||
const tag = (el.tagName || "").toLowerCase();
|
||||
const tag = lower(el.tagName);
|
||||
const id = el.id ? String(el.id) : undefined;
|
||||
const className = el.className ? String(el.className).slice(0, 300) : undefined;
|
||||
let text = "";
|
||||
|
||||
@@ -42,7 +42,10 @@ import {
|
||||
type ResolvedQmdConfig,
|
||||
type ResolvedQmdMcporterConfig,
|
||||
} from "openclaw/plugin-sdk/memory-core-host-engine-storage";
|
||||
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
|
||||
import {
|
||||
localeLowercasePreservingWhitespace,
|
||||
normalizeLowercaseStringOrEmpty,
|
||||
} from "openclaw/plugin-sdk/text-runtime";
|
||||
import { asRecord } from "../dreaming-shared.js";
|
||||
import { resolveQmdCollectionPatternFlags, type QmdCollectionPatternFlag } from "./qmd-compat.js";
|
||||
|
||||
@@ -2206,17 +2209,15 @@ export class QmdMemoryManager implements MemorySearchManager {
|
||||
}
|
||||
const parsed = path.posix.parse(trimmed);
|
||||
const normalizePart = (value: string): string =>
|
||||
value
|
||||
.normalize("NFKD")
|
||||
.toLocaleLowerCase()
|
||||
localeLowercasePreservingWhitespace(value.normalize("NFKD"))
|
||||
.replace(/[^\p{Letter}\p{Number}]+/gu, "-")
|
||||
.replace(/-{2,}/g, "-")
|
||||
.replace(/^-+|-+$/g, "");
|
||||
const normalizedName = normalizePart(parsed.name);
|
||||
const normalizedExt = parsed.ext
|
||||
.normalize("NFKD")
|
||||
.toLocaleLowerCase()
|
||||
.replace(/[^\p{Letter}\p{Number}.]+/gu, "");
|
||||
const normalizedExt = localeLowercasePreservingWhitespace(parsed.ext.normalize("NFKD")).replace(
|
||||
/[^\p{Letter}\p{Number}.]+/gu,
|
||||
"",
|
||||
);
|
||||
const fallbackName = normalizeLowercaseStringOrEmpty(parsed.name.normalize("NFKD")).replace(
|
||||
/\s+/g,
|
||||
"-",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { extractKeywords, isQueryStopWordToken } from "../../memory-host-sdk/query.js";
|
||||
import { localeLowercasePreservingWhitespace } from "../../shared/string-coerce.js";
|
||||
import type { CompactionSummarizationInstructions } from "../compaction.js";
|
||||
import { wrapUntrustedPromptDataBlock } from "../sanitize-for-prompt.js";
|
||||
|
||||
@@ -166,7 +167,7 @@ export function extractOpaqueIdentifiers(text: string): string[] {
|
||||
}
|
||||
|
||||
function tokenizeAskOverlapText(text: string): string[] {
|
||||
const normalized = text.toLocaleLowerCase().normalize("NFKC").trim();
|
||||
const normalized = localeLowercasePreservingWhitespace(text.normalize("NFKC")).trim();
|
||||
if (!normalized) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
(() => {
|
||||
const normalizeLower = (value) => {
|
||||
const trimmed = String(value || "").trim();
|
||||
return trimmed.toLowerCase();
|
||||
return trimmed.toLocaleLowerCase();
|
||||
};
|
||||
try {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
|
||||
@@ -29,6 +29,7 @@ export * from "../utils/reaction-level.js";
|
||||
export * from "../utils/with-timeout.js";
|
||||
export {
|
||||
hasNonEmptyString,
|
||||
localeLowercasePreservingWhitespace,
|
||||
lowercasePreservingWhitespace,
|
||||
normalizeLowercaseStringOrEmpty,
|
||||
normalizeNullableString,
|
||||
|
||||
@@ -26,6 +26,10 @@ export function lowercasePreservingWhitespace(value: string): string {
|
||||
return value.toLowerCase();
|
||||
}
|
||||
|
||||
export function localeLowercasePreservingWhitespace(value: string): string {
|
||||
return value.toLocaleLowerCase();
|
||||
}
|
||||
|
||||
export function resolvePrimaryStringValue(value: unknown): string | undefined {
|
||||
if (typeof value === "string") {
|
||||
return normalizeOptionalString(value);
|
||||
|
||||
Reference in New Issue
Block a user