MCPcopy
hub / github.com/21st-dev/magic-mcp / convertToFormat

Method convertToFormat

src/tools/logo-search.ts:96–132  ·  view source on GitHub ↗
(
    svgContent: string,
    format: "JSX" | "TSX" | "SVG",
    componentName: string = "Icon"
  )

Source from the content-addressed store, hash-verified

94 }
95
96 private async convertToFormat(
97 svgContent: string,
98 format: "JSX" | "TSX" | "SVG",
99 componentName: string = "Icon"
100 ): Promise<string> {
101 if (format === "SVG") {
102 return svgContent;
103 }
104
105 // Convert to JSX/TSX
106 const jsxContent = svgContent
107 .replace(/class=/g, "className=")
108 .replace(/style="([^"]*)"/g, (match: string, styles: string) => {
109 const cssObject = styles
110 .split(";")
111 .filter(Boolean)
112 .map((style: string) => {
113 const [property, value] = style
114 .split(":")
115 .map((s: string) => s.trim());
116 const camelProperty = property.replace(/-([a-z])/g, (g: string) =>
117 g[1].toUpperCase()
118 );
119 return `${camelProperty}: "${value}"`;
120 })
121 .join(", ");
122 return `style={{${cssObject}}}`;
123 });
124
125 // Make sure we use the full component name (with Icon suffix)
126 const finalComponentName = componentName.endsWith("Icon")
127 ? componentName
128 : `${componentName}Icon`;
129 return format === "TSX"
130 ? `const ${finalComponentName}: React.FC = () => (${jsxContent})`
131 : `function ${finalComponentName}() { return (${jsxContent}) }`;
132 }
133
134 private async saveTestResult(data: {
135 queries: string[];

Callers 1

executeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected