From 879f8eb10ecd9cb61676f7f2a691f20f2a6310f9 Mon Sep 17 00:00:00 2001 From: pheralb Date: Wed, 27 Aug 2025 19:29:41 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Create=20custom=20utility=20to=20pa?= =?UTF-8?q?rse=20SVG=20code=20with=20SWC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/parseReactSvgContent.ts | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/utils/parseReactSvgContent.ts diff --git a/src/utils/parseReactSvgContent.ts b/src/utils/parseReactSvgContent.ts new file mode 100644 index 0000000..0d8c677 --- /dev/null +++ b/src/utils/parseReactSvgContent.ts @@ -0,0 +1,33 @@ +import { parse, print, type Module } from "@swc/core"; + +interface ParseReactSvgOptions { + componentName: string; + svgCode: string; + typescript: boolean; + minify?: boolean; +} + +export const parseReactSvgContent = async ({ + componentName, + svgCode, + typescript, + minify = false, +}: ParseReactSvgOptions) => { + let structuredCode = ""; + + if (typescript) { + structuredCode = + `import * as React from 'react';\n\n` + + `const ${componentName} = (props: React.SVGProps) => (\n ${svgCode.replace(" (\n ${svgCode.replace("