Skip to content

Commit

Permalink
Fallback to default bytes when not provided
Browse files Browse the repository at this point in the history
Fix #558
  • Loading branch information
BenjaminVanRyseghem committed Jul 8, 2020
1 parent 4c27cab commit 873d350
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/formatting.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ function formatByte(instance, providedFormat, state, numbro) {
const { binarySuffixes: localBinarySuffixes, decimalSuffixes: localDecimalSuffixes } = state.currentBytes();

const localBytes = {
general: { scale: 1024, suffixes: localDecimalSuffixes, marker: "bd" },
binary: { scale: 1024, suffixes: localBinarySuffixes, marker: "b" },
decimal: { scale: 1000, suffixes: localDecimalSuffixes, marker: "d" }
general: { scale: 1024, suffixes: localDecimalSuffixes || decimalSuffixes, marker: "bd" },
binary: { scale: 1024, suffixes: localBinarySuffixes || binarySuffixes, marker: "b" },
decimal: { scale: 1000, suffixes: localDecimalSuffixes || decimalSuffixes, marker: "d" }
};
let baseInfo = localBytes[base];

Expand Down
2 changes: 1 addition & 1 deletion src/globalState.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ state.currentLanguage = () => currentLanguageTag;
*
* @return {{}}
*/
state.currentBytes = () => currentLanguageData().bytes;
state.currentBytes = () => currentLanguageData().bytes || {};

/**
* Return the current language currency data
Expand Down
15 changes: 14 additions & 1 deletion tests/src/globalState-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,29 @@ describe("globalState-tests", () => {
describe("currentByteDefaults", () => {
let languages = undefined;
let revert = undefined;
let currentLanguageData = undefined;

beforeEach(() => {
languages = {"en-US": Object.assign({}, enUS)};
revert = globalState.__set__({languages});
currentLanguageData = jasmine.createSpy("currentLanguageData");
let realFn = globalState.__get__("currentLanguageData");
currentLanguageData.and.callFake(realFn);
revert = globalState.__set__({
languages,
currentLanguageData
});
});

afterEach(() => {
revert();
});

it("returns empty bytes if not provided by the language", () => {
currentLanguageData.and.returnValue({});
let result = globalState.currentBytes();
expect(result).toEqual({});
});

it("returns the byte defaults for the current language", () => {
let byteFormat = jasmine.createSpy("byteFormat");
languages["en-US"].byteFormat = byteFormat;
Expand Down

2 comments on commit 873d350

@seedy
Copy link

@seedy seedy commented on 873d350 Jul 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BenjaminVanRyseghem Wouldn't you mind releasing a version with this commit please ?
Thanks 🙏

@BenjaminVanRyseghem
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in numbro 2.3.2

Please sign in to comment.