Last active
April 18, 2020 19:12
-
-
Save MoOx/d5bc9ebef1a463cf4348 to your computer and use it in GitHub Desktop.
Cleanup svg
This file contains hidden or 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
cleanupSvg(svg) { | |
return [ | |
// some useless stuff for us | |
// that svgo doesn't remove | |
/<title>.*<\/title>/gi, | |
// remove hardcoded dimensions | |
/ +width="\d+(\.\d+)?(px)?"/gi, | |
/ +height="\d+(\.\d+)?(px)?"/gi, | |
// remove fill | |
/ +fill=\"(none|#[0-9a-f]+)\"/gi, | |
// Sketch.app shit | |
/ +sketch:type=\"MSShapeGroup\"/gi, | |
/ +sketch:type=\"MSPage\"/gi, | |
/ +sketch:type=\"MSLayerGroup\"/gi, | |
] | |
.reduce((acc, re) => { | |
return acc.replace(re, "") | |
}, svg) | |
.trim() | |
} |
Like I said to Kud, "xmlns:sketch" isn't mandatory, you can remove it too ;)
<title>
is important for accessibility though
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@kud I've added some of your removal