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

Switch to binary prefixes #7218

Merged
merged 10 commits into from
Oct 3, 2023
15 changes: 14 additions & 1 deletion app/helpers/pretty-bytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,17 @@ import { helper } from '@ember/component/helper';

import prettyBytes from 'pretty-bytes';

export default helper(([bytes], options) => prettyBytes(bytes, options));
/**
* See https://github.com/rust-lang/crates.io/discussions/7177
*
* Here we set fraction digits to 1 because `cargo publish`
* uses this format (see https://github.com/rust-lang/cargo/blob/master/src/cargo/ops/cargo_package.rs#L168-L171)
Copy link
Member

Choose a reason for hiding this comment

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

Could you please use a tag instead of the master branch here?
Using a fixed version can make sure we can always find it.

Copy link
Contributor Author

@kanarus kanarus Oct 3, 2023

Choose a reason for hiding this comment

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

Thanks, I see! I'll fix them...

*/
export default helper(([bytes], options) =>
prettyBytes(bytes, {
...options,
binary: true,
minimumFractionDigits: 1,
maximumFractionDigits: 1,
Turbo87 marked this conversation as resolved.
Show resolved Hide resolved
Turbo87 marked this conversation as resolved.
Show resolved Hide resolved
}),
);
26 changes: 26 additions & 0 deletions tests/unit/helpers/pretty-bytes-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { render } from '@ember/test-helpers';
import { module, test } from 'qunit';

import { hbs } from 'ember-cli-htmlbars';

import { setupRenderingTest } from 'cargo/tests/helpers';

module('Unit | Helper | pretty-bytes', function (hooks) {
setupRenderingTest(hooks);

test('it displays as expected', async function (assert) {
this.owner.lookup('service:intl').locale = 'en';

await render(hbs`{{pretty-bytes 42}}`);
assert.dom().hasText('42.0 B');

await render(hbs`{{pretty-bytes 42000}}`);
assert.dom().hasText('41.0 KiB');

await render(hbs`{{pretty-bytes 42420}}`);
assert.dom().hasText('41.4 KiB');

await render(hbs`{{pretty-bytes 42424242}}`);
assert.dom().hasText('40.5 MiB');
});
});
Loading