Skip to content

Instantly share code, notes, and snippets.

@desandro desandro/round-svg.js
Last active Oct 14, 2017

Embed
What would you like to do?
var paths = document.querySelectorAll('path')
for ( var i=0; i < paths.length; i++ ) {
var path = paths[i];
var d = path.getAttribute('d');
// 10.2.3 -> 10.2 0.3
d = d.replace( /(\d?\.\d)\.(\d)/g, function( match, $1, $2 ) {
return $1 + ' 0.' + $2
});
// round numbers
d = d.replace( /(\D)(\d*\.\d+)/g, function( match, firstChar, num ) {
num = Math.round( parseFloat( num ) );
return firstChar + num;
});
// commas to spaces
d = d.replace( /,/g, ' ' );
path.setAttribute( 'd', d );
}
document.body.innerHTML
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.