Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const fastFormatDecimal = (n: string, digits: string[], minInt: number): string => {
let r = '';
const len = n.length;
for (let i = 0; i < len; i++) {
const c = n.charCodeAt(i);
switch (c) {
case Chars.DIGIT0:
case Chars.DIGIT1:
case Chars.DIGIT2:
case Chars.DIGIT3:
case Chars.DIGIT4:
case Chars.DIGIT5:
case Chars.DIGIT6:
case Chars.DIGIT7:
case Chars.DIGIT8:
case Chars.DIGIT9:
r += digits[c - Chars.DIGIT0];
break;
}
}
// Left pad zeros if minimum integer digits > formatted length
let diff = minInt - r.length;
if (diff > 0) {
let p = '';
while (diff-- > 0) {
p += digits[0];
}
return p + r;
}
return r;
};