diff --git a/lib/path.js b/lib/path.js index 5a68e8fdf..fb02d184f 100644 --- a/lib/path.js +++ b/lib/path.js @@ -1,5 +1,7 @@ 'use strict'; +const { removeLeadingZero } = require('./svgo/tools'); + /** * @typedef {import('./types').PathDataItem} PathDataItem * @typedef {import('./types').PathDataCommand} PathDataCommand @@ -249,7 +251,7 @@ const stringifyNumber = (number, precision) => { number = Math.round(number * ratio) / ratio; } // remove zero whole from decimal number - return number.toString().replace(/^0\./, '.').replace(/^-0\./, '-.'); + return removeLeadingZero(number); }; /** diff --git a/lib/svgo/tools.js b/lib/svgo/tools.js index 43bfee95a..971397595 100644 --- a/lib/svgo/tools.js +++ b/lib/svgo/tools.js @@ -128,10 +128,10 @@ exports.cleanupOutData = (data, params, command) => { const removeLeadingZero = (num) => { var strNum = num.toString(); - if (0 < num && num < 1 && strNum.charAt(0) === '0') { - strNum = strNum.slice(1); - } else if (-1 < num && num < 0 && strNum.charAt(1) === '0') { - strNum = strNum.charAt(0) + strNum.slice(2); + if (0 < num && num < 1) { + return strNum.slice(1); + } else if (-1 < num && num < 0) { + return '-' + strNum.slice(2); } return strNum; };