Skip to content

Commit 44f5e9f

Browse files
refactor: SVG attribute matching to use RegExp.exec (#52)
1 parent 8f7ec95 commit 44f5e9f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

configs/sponsors/svg-utils.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
*/
1010
export function extractSvgDimensions(svgContent: string): { width: number; height: number } {
1111
// Try to get dimensions from viewBox first
12-
const viewBoxMatch = svgContent.match(/viewBox=['"]([^'"]*)['"]/);
12+
const viewBoxRegex = /viewBox=['"]([^'"]*)['"]/;
13+
const viewBoxMatch = viewBoxRegex.exec(svgContent);
1314
if (viewBoxMatch) {
1415
const [, , width, height] = viewBoxMatch[1].split(/\s+/).map(Number);
1516
// 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
1920
}
2021

2122
// Try to get from width/height attributes
22-
const widthMatch = svgContent.match(/width=['"]([^'"]*)['"]/);
23-
const heightMatch = svgContent.match(/height=['"]([^'"]*)['"]/);
23+
const widthRegex = /width=['"]([^'"]*)['"]/;
24+
const widthMatch = widthRegex.exec(svgContent);
25+
const heightRegex = /height=['"]([^'"]*)['"]/;
26+
const heightMatch = heightRegex.exec(svgContent);
2427

2528
const width = widthMatch ? Number.parseInt(widthMatch[1], 10) : 200;
2629
const height = heightMatch ? Number.parseInt(heightMatch[1], 10) : 100;

0 commit comments

Comments
 (0)