Skip to content

Commit

Permalink
fix: stringifyPathData needs space before scientific notation (#1961)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkenny54 authored Feb 25, 2024
1 parent 573a5c7 commit 473c5a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 1 addition & 6 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,7 @@ const stringifyArgs = (command, args, precision, disableSpaceAfterFlags) => {
} else if (i === 0 || rounded < 0) {
// avoid space before first and negative numbers
result += roundedStr;
} else if (
!Number.isInteger(previous) &&
rounded != 0 &&
rounded < 1 &&
rounded > -1
) {
} else if (!Number.isInteger(previous) && !isDigit(roundedStr[0])) {
// remove space before decimal with zero whole
// only when previous number is also decimal
result += roundedStr;
Expand Down
11 changes: 11 additions & 0 deletions lib/path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ describe('stringify path data', () => {
}),
).toBe('M0-1.2.3 4 5-.6 7 .8');
});
it('should have a space before scientific notation', () => {
expect(
stringifyPathData({
pathData: [
{ command: 'M', args: [0.1, 1e-7] },
{ command: 'L', args: [2, 2] },
],
precision: 7,
}),
).toBe('M.1 1e-7 2 2');
});
it('should configure precision', () => {
/**
* @type {PathDataItem[]}
Expand Down

0 comments on commit 473c5a6

Please sign in to comment.