import/export data

This commit is contained in:
2025-03-17 21:28:22 -07:00
parent 62fedaafea
commit 8c909929d1
7 changed files with 319 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
const zeroPaddedString = (
num: number,
requiredDigits: number,
position: "before" | "after"
): string => {
if (num < 0) throw new RangeError("negative number");
if (requiredDigits < 0) throw new RangeError("invalid number of zeroes");
if (position !== "before" && position !== "after")
throw new TypeError("invalid position (before or after only)");
const requiredZeroes = requiredDigits - (num + "").replace(".", "").length;
const zeroes = "0".repeat(requiredZeroes);
return position === "before" ? "" + zeroes + num : "" + num + zeroes;
};
export { zeroPaddedString };