Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stringifyPathData needs space before scientific notation. #1961

Merged
merged 3 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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