diff --git a/web/comfyui/lora_loader.js b/web/comfyui/lora_loader.js index 23400d36..07fdf8b5 100644 --- a/web/comfyui/lora_loader.js +++ b/web/comfyui/lora_loader.js @@ -1,13 +1,15 @@ import { app } from "../../scripts/app.js"; import { addLorasWidget } from "./loras_widget.js"; +// Extract pattern into a constant for consistent use +const LORA_PATTERN = //g; + function mergeLoras(lorasText, lorasJson) { const result = []; - const pattern = //g; let match; // Parse text input and create initial entries - while ((match = pattern.exec(lorasText)) !== null) { + while ((match = LORA_PATTERN.exec(lorasText)) !== null) { const name = match[1]; const inputStrength = Number(match[2]); @@ -69,10 +71,10 @@ app.registerExtension({ try { // Remove loras that are not in the value array const inputWidget = node.widgets[0]; - const pattern = //g; const currentLoras = value.map(l => l.name); - let newText = inputWidget.value.replace(pattern, (match, name, strength) => { + // Use the constant pattern here as well + let newText = inputWidget.value.replace(LORA_PATTERN, (match, name, strength) => { return currentLoras.includes(name) ? match : ''; });