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