Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
timonson committed Mar 15, 2024
1 parent ae8f597 commit 79f280b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions strings/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ function replaceAll(toBeReplaced) {

export const replaceSpacesWithHyphens = replaceAll(/\s+/)("-");
export const replaceSpacesWithUnderscores = replaceAll(/\s+/)("_");
export const replaceHyphensWithSpaces = replaceAll(/-/)(" ");
export const replaceUnderscoresWithSpaces = replaceAll(/_+/)(" ");
export const replaceHyphensWithUnderscores = replaceAll(/-+/)("_");
export const replaceUnderscoresWithHyphens = replaceAll(/_+/)("-");

function pad(character) {
return (minimumLength) => (input) => {
Expand Down
60 changes: 60 additions & 0 deletions units.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Number of bytes in a Kilobyte.
* @const
* @type {number}
*/
export const BYTES_PER_KB = 1024;

/**
* Convert bytes to megabytes.
* @param {number} bytes - The number of bytes.
* @return {number} The equivalent number of megabytes.
*/
export function bytesToMb(bytes) {
return bytes / BYTES_PER_KB / BYTES_PER_KB;
}

/**
* Convert bytes to gigabytes.
* @param {number} bytes - The number of bytes.
* @return {number} The equivalent number of gigabytes.
*/
export function bytesToGb(bytes) {
return bytes / BYTES_PER_KB / BYTES_PER_KB / BYTES_PER_KB;
}

/**
* Convert megabytes to bytes.
* @param {number} mb - The number of megabytes.
* @return {number} The equivalent number of bytes.
*/
export function mbToBytes(mb) {
return mb * BYTES_PER_KB * BYTES_PER_KB;
}

/**
* Convert megabytes to gigabytes.
* @param {number} mb - The number of megabytes.
* @return {number} The equivalent number of gigabytes.
*/
export function mbToGb(mb) {
return mb / BYTES_PER_KB;
}

/**
* Convert gigabytes to bytes.
* @param {number} gb - The number of gigabytes.
* @return {number} The equivalent number of bytes.
*/
export function gbToBytes(gb) {
return gb * BYTES_PER_KB * BYTES_PER_KB * BYTES_PER_KB;
}

/**
* Convert gigabytes to megabytes.
* @param {number} gb - The number of gigabytes.
* @return {number} The equivalent number of megabytes.
*/
export function gbToMb(gb) {
return gb * BYTES_PER_KB;
}

0 comments on commit 79f280b

Please sign in to comment.