Skip to content

Instantly share code, notes, and snippets.

@seanchas116
Created February 10, 2023 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanchas116/4064263b5d524dea8a6e63942c8e1bca to your computer and use it in GitHub Desktop.
Save seanchas116/4064263b5d524dea8a6e63942c8e1bca to your computer and use it in GitHub Desktop.
Generate IconifyIcon from SVG data
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