fix: ip and integer wrong merge

This commit is contained in:
ShareVB committed 2024-11-11 20:27:29 +01:00
1 parent 675e5bffa8
commit fd3ca2380c
2 files changed
+7 -7

No files matched your search

@@ -46,16 +46,16 @@ export function convertBase(
let decValue = cleanedValue let decValue = cleanedValue
.split('') .split('')
.reverse() .reverse()
.reduce((carry: number, digit: string, index: number) => { .reduce((carry: bigint, digit: string, index: number) => {
if (!fromRange.includes(digit)) { if (!fromRange.includes(digit)) {
throw new Error(`Invalid digit "${digit}" for base ${finalFromBase}.`); throw new Error(`Invalid digit "${digit}" for base ${finalFromBase}.`);
} }
return (carry += fromRange.indexOf(digit) * finalFromBase ** index); return (carry += BigInt(fromRange.indexOf(digit)) * BigInt(finalFromBase) ** BigInt(index));
}, 0); }, 0n);
let newValue = ''; let newValue = '';
while (decValue > 0) { while (decValue > 0) {
newValue = toRange[decValue % toBase] + newValue; newValue = toRange[Number(decValue % BigInt(toBase))] + newValue;
decValue = (decValue - (decValue % toBase)) / toBase; decValue = (decValue - (decValue % BigInt(toBase))) / BigInt(toBase);
} }
return newValue || '0'; return newValue || '0';
} }
+2 -2
View File
@@ -26,9 +26,9 @@ export function parseAsCIDR(form: string) {
return (ipMatch as IPSubnetwork).toString(); return (ipMatch as IPSubnetwork).toString();
} }
if (ipMatch instanceof IPMask) { if (ipMatch instanceof IPMask) {
return (ipMatch as IPMask).convertToSubnet()?.toString(); return (ipMatch as IPMask).convertToSubnet()?.toString() || '';
} }
return (ipMatch.convertToMasks() || [])[0]?.convertToSubnet()?.toString(); return (ipMatch.convertToMasks() || [])[0]?.convertToSubnet()?.toString() || '';
} }
export function getSubnets(cidr: string) { export function getSubnets(cidr: string) {