|
| 1 | +/** |
| 2 | + * Number of bytes in a Kilobyte. |
| 3 | + * @const |
| 4 | + * @type {number} |
| 5 | + */ |
| 6 | +export const BYTES_PER_KB = 1024; |
| 7 | + |
| 8 | +/** |
| 9 | + * Convert bytes to megabytes. |
| 10 | + * @param {number} bytes - The number of bytes. |
| 11 | + * @return {number} The equivalent number of megabytes. |
| 12 | + */ |
| 13 | +export function bytesToMb(bytes) { |
| 14 | + return bytes / BYTES_PER_KB / BYTES_PER_KB; |
| 15 | +} |
| 16 | + |
| 17 | +/** |
| 18 | + * Convert bytes to gigabytes. |
| 19 | + * @param {number} bytes - The number of bytes. |
| 20 | + * @return {number} The equivalent number of gigabytes. |
| 21 | + */ |
| 22 | +export function bytesToGb(bytes) { |
| 23 | + return bytes / BYTES_PER_KB / BYTES_PER_KB / BYTES_PER_KB; |
| 24 | +} |
| 25 | + |
| 26 | +/** |
| 27 | + * Convert megabytes to bytes. |
| 28 | + * @param {number} mb - The number of megabytes. |
| 29 | + * @return {number} The equivalent number of bytes. |
| 30 | + */ |
| 31 | +export function mbToBytes(mb) { |
| 32 | + return mb * BYTES_PER_KB * BYTES_PER_KB; |
| 33 | +} |
| 34 | + |
| 35 | +/** |
| 36 | + * Convert megabytes to gigabytes. |
| 37 | + * @param {number} mb - The number of megabytes. |
| 38 | + * @return {number} The equivalent number of gigabytes. |
| 39 | + */ |
| 40 | +export function mbToGb(mb) { |
| 41 | + return mb / BYTES_PER_KB; |
| 42 | +} |
| 43 | + |
| 44 | +/** |
| 45 | + * Convert gigabytes to bytes. |
| 46 | + * @param {number} gb - The number of gigabytes. |
| 47 | + * @return {number} The equivalent number of bytes. |
| 48 | + */ |
| 49 | +export function gbToBytes(gb) { |
| 50 | + return gb * BYTES_PER_KB * BYTES_PER_KB * BYTES_PER_KB; |
| 51 | +} |
| 52 | + |
| 53 | +/** |
| 54 | + * Convert gigabytes to megabytes. |
| 55 | + * @param {number} gb - The number of gigabytes. |
| 56 | + * @return {number} The equivalent number of megabytes. |
| 57 | + */ |
| 58 | +export function gbToMb(gb) { |
| 59 | + return gb * BYTES_PER_KB; |
| 60 | +} |
0 commit comments