Skip to content

Commit c0e6286

Browse files
committed
Core: fix formatting dimensionless input when empty target
1 parent 0edbeab commit c0e6286

File tree

6 files changed

+6
-4
lines changed

6 files changed

+6
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ node_modules
1212
dist
1313
dist-ssr
1414
*.local
15+
*.tgz
1516

1617
# Editor directories and files
1718
.vscode/*

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "uuc-core",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Ultimate Unit Converter Core Library",
55
"homepage": "https://github.com/Lemonexe/UUC#readme",
66
"author": "Jiri Zbytovsky",

packages/core/src/__tests__/utils.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe(balanceBrackets.name, () => {
1616

1717
describe(vector2text.name, () => {
1818
it('converts a simple vector to text', () => {
19+
expect(vector2text([0, 0, 0, 0, 0, 0, 0, 0])).toBe('');
1920
expect(vector2text([0, 1, 0, 0, 0, 0, 0, 0])).toBe('kg');
2021
expect(vector2text([0, 0, 0, 0, 0, 0, -1, 0])).toBe('1/cd');
2122
});

packages/core/src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export const vector2text = (v: V): string => {
9494
if (v[i] > 0) text += v[i];
9595
else if (v[i] < 0) text += -v[i];
9696
}
97+
if (text === '1') return ''; // dimensionless; representing it would be superfluous
9798
return text.replace(/^1\*/, ''); // remove leading 1*, we need only leading 1/
9899
};
99100

packages/frontend/src/components/Reference.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ function getUnitList(filter: string): GetUnitListResult {
122122
function buildUnitEntry(unit: Unit) {
123123
const aliases = unit.alias ? ', ' + unit.alias.join(', ') : '';
124124
let text = ` (${unit.id + aliases}) `;
125-
let dim = vector2text(unit.v);
126-
dim = dim === '1' ? '' : dim;
125+
const dim = vector2text(unit.v);
127126
text += unit.basic || isNaN(unit.k) ? '' : ` = ${unit.k} ${dim}\n`;
128127

129128
if (unit.constant) {

0 commit comments

Comments
 (0)