Created
February 10, 2023 05:19
-
-
Save seanchas116/4064263b5d524dea8a6e63942c8e1bca to your computer and use it in GitHub Desktop.
Generate IconifyIcon from SVG data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toIconifyIcon(svg: string): IconifyIcon { | |
const body = svg.replace(/<svg[^>]*>/, "").replace(/<\/svg>/, ""); | |
const width = svg.match(/width="(\d+)"/)?.[1]; | |
const height = svg.match(/height="(\d+)"/)?.[1]; | |
return { | |
body: `<g fill="currentColor">${body}</g>`, | |
width: width ? Number.parseInt(width) : undefined, | |
height: height ? Number.parseInt(height) : undefined, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment