mirror of
https://github.com/20kaushik02/spotify-manager-web.git
synced 2026-01-25 16:14:06 +00:00
formatting
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
/**
|
||||
* Returns a string with zero padding of the number
|
||||
*
|
||||
*
|
||||
* @param {number} num Input number (positive integer only, for now)
|
||||
* @param {number} places Number of zeroes to pad
|
||||
* @param {"before" | "after"} position Position of zeroes
|
||||
* @returns {string} Zero-padded string
|
||||
*/
|
||||
export const zeroPaddedString = (num, places, position) => {
|
||||
if (num < 0) throw new Error("negative number");
|
||||
if (places < 0) throw new Error("invalid number of zeroes");
|
||||
if (position !== "before" && position !== "after") throw new Error("invalid position (before or after only)");
|
||||
if (num < 0) throw new Error("negative number");
|
||||
if (places < 0) throw new Error("invalid number of zeroes");
|
||||
if (position !== "before" && position !== "after") throw new Error("invalid position (before or after only)");
|
||||
|
||||
const zeroes = "0".repeat(places);
|
||||
return position === "before" ? '' + zeroes + num : '' + num + zeroes;
|
||||
}
|
||||
const zeroes = "0".repeat(places);
|
||||
return position === "before" ? '' + zeroes + num : '' + num + zeroes;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user