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:
16
lib/path.js
16
lib/path.js
@ -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\./, '-.');
|
||||
};
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user