Skip to content

Commit

Permalink
fix(morpho-ts): fix formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
oumar-fall committed Oct 17, 2024
1 parent 16ea741 commit dc75689
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/morpho-ts/src/format/format/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ describe("format", () => {

describe("short", () => {
describe("should properly format number in short format", () => {
it("with small integers", () => {
expect(format.short.of(123)).toEqual("123");
});
it("without option", () => {
expect(format.short.of(number)).toEqual("12.3456789k");
});
Expand Down Expand Up @@ -212,6 +215,9 @@ describe("format", () => {
});
});
describe("should properly format bigint in short format", () => {
it("with small integers", () => {
expect(format.short.of(123n, 0)).toEqual("123");
});
it("without option", () => {
expect(format.short.of(bigint, decimals)).toEqual("12.3456789k");
});
Expand Down
6 changes: 5 additions & 1 deletion packages/morpho-ts/src/format/format/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const _formatShort = (
const params = RANGES.find(
(range) => stringValue.length > range.minDecimals + decimals,
);
console.log({ bi, decimals, stringValue, params });
if (params) {
return (
_applyOptions(
Expand All @@ -126,7 +127,10 @@ const _formatShort = (
if (formatOptions.smallValuesWithCommas) {
return _formatCommas(bi, decimals, formatOptions);
}
return _applyOptions(stringValue.insert(-decimals, ".", "0"), formatOptions);
return _applyOptions(
decimals ? stringValue.insert(-decimals, ".", "0") : stringValue,
formatOptions,
);
};

const _formatCommas = (
Expand Down

0 comments on commit dc75689

Please sign in to comment.