1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-29 20:21:14 +03:00

Simplify number rendering and fix -0 in path

Ref https://github.com/svg/svgo/issues/1422
This commit is contained in:
Bogdan Chadkin
2021-03-22 14:38:06 +03:00
parent 316a002299
commit 3d4adb6b04
4 changed files with 16 additions and 26 deletions

View File

@ -241,20 +241,12 @@ exports.parsePathData = parsePathData;
* @param {StringifyNumberOptions} param
*/
const stringifyNumber = ({ number, precision }) => {
let result;
if (precision == null) {
result = number.toString();
} else {
result = number.toFixed(precision);
if (result.includes('.')) {
result = result.replace(/\.?0+$/, '');
}
if (precision != null) {
const ratio = 10 ** precision;
number = Math.round(number * ratio) / ratio;
}
// remove zero whole from decimal number
if (result !== '0') {
result = result.replace(/^0/, '').replace(/^-0/, '-');
}
return result;
return number.toString().replace(/^0\./, '.').replace(/^-0\./, '-.');
};
/**