From b11a6bcbb52c698a9d611680c667132d835b7e77 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sun, 30 Nov 2025 18:58:34 -0500 Subject: [PATCH] refactor: SVG attribute matching to use RegExp.exec Replaces String.match with RegExp.exec for extracting viewBox, width, and height attributes from SVG content. This improves consistency and clarity in how regex matches are handled. --- configs/sponsors/svg-utils.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/configs/sponsors/svg-utils.ts b/configs/sponsors/svg-utils.ts index 81a98ad..f0fee27 100644 --- a/configs/sponsors/svg-utils.ts +++ b/configs/sponsors/svg-utils.ts @@ -9,7 +9,8 @@ */ export function extractSvgDimensions(svgContent: string): { width: number; height: number } { // Try to get dimensions from viewBox first - const viewBoxMatch = svgContent.match(/viewBox=['"]([^'"]*)['"]/); + const viewBoxRegex = /viewBox=['"]([^'"]*)['"]/; + const viewBoxMatch = viewBoxRegex.exec(svgContent); if (viewBoxMatch) { const [, , width, height] = viewBoxMatch[1].split(/\s+/).map(Number); // Check that both width and height are valid numbers (not NaN and not undefined) @@ -19,8 +20,10 @@ export function extractSvgDimensions(svgContent: string): { width: number; heigh } // Try to get from width/height attributes - const widthMatch = svgContent.match(/width=['"]([^'"]*)['"]/); - const heightMatch = svgContent.match(/height=['"]([^'"]*)['"]/); + const widthRegex = /width=['"]([^'"]*)['"]/; + const widthMatch = widthRegex.exec(svgContent); + const heightRegex = /height=['"]([^'"]*)['"]/; + const heightMatch = heightRegex.exec(svgContent); const width = widthMatch ? Number.parseInt(widthMatch[1], 10) : 200; const height = heightMatch ? Number.parseInt(heightMatch[1], 10) : 100;