From fd3ca2380c5f36b0b4d1347b9d0cc95c675514ca Mon Sep 17 00:00:00 2001 From: ShareVB Date: Mon, 11 Nov 2024 20:27:29 +0100 Subject: [PATCH] fix: ip and integer wrong merge --- .../integer-base-converter.model.ts | 10 +++++----- src/utils/ip.ts | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/tools/integer-base-converter/integer-base-converter.model.ts b/src/tools/integer-base-converter/integer-base-converter.model.ts index 431876f3..89154000 100644 --- a/src/tools/integer-base-converter/integer-base-converter.model.ts +++ b/src/tools/integer-base-converter/integer-base-converter.model.ts @@ -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'; } diff --git a/src/utils/ip.ts b/src/utils/ip.ts index bd1c561e..9ad17390 100644 --- a/src/utils/ip.ts +++ b/src/utils/ip.ts @@ -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) {