Skip to content

Instantly share code, notes, and snippets.

@desandro
Last active October 14, 2017 17:16
Show Gist options
  • Save desandro/ccb79c1fd4008e327712fca3966bc389 to your computer and use it in GitHub Desktop.
Save desandro/ccb79c1fd4008e327712fca3966bc389 to your computer and use it in GitHub Desktop.
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