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