Commit a7652553 authored by kushalpandya's avatar kushalpandya

Add `bytesToMiB` converter method

parent 233d1ee8
...@@ -42,3 +42,13 @@ export function formatRelevantDigits(number) { ...@@ -42,3 +42,13 @@ export function formatRelevantDigits(number) {
export function bytesToKiB(number) { export function bytesToKiB(number) {
return number / BYTES_IN_KIB; return number / BYTES_IN_KIB;
} }
/**
* Utility function that calculates MiB of the given bytes.
*
* @param {Number} number bytes
* @return {Number} MiB
*/
export function bytesToMiB(number) {
return number / (BYTES_IN_KIB * BYTES_IN_KIB);
}
import { formatRelevantDigits, bytesToKiB } from '~/lib/utils/number_utils'; import { formatRelevantDigits, bytesToKiB, bytesToMiB } from '~/lib/utils/number_utils';
describe('Number Utils', () => { describe('Number Utils', () => {
describe('formatRelevantDigits', () => { describe('formatRelevantDigits', () => {
...@@ -45,4 +45,11 @@ describe('Number Utils', () => { ...@@ -45,4 +45,11 @@ describe('Number Utils', () => {
expect(bytesToKiB(1000)).toEqual(0.9765625); expect(bytesToKiB(1000)).toEqual(0.9765625);
}); });
}); });
describe('bytesToMiB', () => {
it('calculates MiB for the given bytes', () => {
expect(bytesToMiB(1048576)).toEqual(1);
expect(bytesToMiB(1000000)).toEqual(0.95367431640625);
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment