mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-24 16:56:14 -04:00
fix(integer-base-converter): handle non-decimal char and better error message
This commit is contained in:
parent
0ff853437b
commit
8476cf319b
4 changed files with 93 additions and 11 deletions
|
@ -7,7 +7,7 @@ export function convertBase({ value, fromBase, toBase }: { value: string; fromBa
|
|||
.reverse()
|
||||
.reduce((carry: number, digit: string, index: number) => {
|
||||
if (!fromRange.includes(digit)) {
|
||||
throw new Error('Invalid digit `' + digit + '` for base ' + fromBase + '.');
|
||||
throw new Error('Invalid digit "' + digit + '" for base ' + fromBase + '.');
|
||||
}
|
||||
return (carry += fromRange.indexOf(digit) * Math.pow(fromBase, index));
|
||||
}, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue