Skip to content

Commit fd3ca23

Browse files
committed
fix: ip and integer wrong merge
1 parent 675e5bf commit fd3ca23

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/tools/integer-base-converter/integer-base-converter.model.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ export function convertBase(
4646
let decValue = cleanedValue
4747
.split('')
4848
.reverse()
49-
.reduce((carry: number, digit: string, index: number) => {
49+
.reduce((carry: bigint, digit: string, index: number) => {
5050
if (!fromRange.includes(digit)) {
5151
throw new Error(`Invalid digit "${digit}" for base ${finalFromBase}.`);
5252
}
53-
return (carry += fromRange.indexOf(digit) * finalFromBase ** index);
54-
}, 0);
53+
return (carry += BigInt(fromRange.indexOf(digit)) * BigInt(finalFromBase) ** BigInt(index));
54+
}, 0n);
5555
let newValue = '';
5656
while (decValue > 0) {
57-
newValue = toRange[decValue % toBase] + newValue;
58-
decValue = (decValue - (decValue % toBase)) / toBase;
57+
newValue = toRange[Number(decValue % BigInt(toBase))] + newValue;
58+
decValue = (decValue - (decValue % BigInt(toBase))) / BigInt(toBase);
5959
}
6060
return newValue || '0';
6161
}

src/utils/ip.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ export function parseAsCIDR(form: string) {
2626
return (ipMatch as IPSubnetwork).toString();
2727
}
2828
if (ipMatch instanceof IPMask) {
29-
return (ipMatch as IPMask).convertToSubnet()?.toString();
29+
return (ipMatch as IPMask).convertToSubnet()?.toString() || '';
3030
}
31-
return (ipMatch.convertToMasks() || [])[0]?.convertToSubnet()?.toString();
31+
return (ipMatch.convertToMasks() || [])[0]?.convertToSubnet()?.toString() || '';
3232
}
3333

3434
export function getSubnets(cidr: string) {

0 commit comments

Comments
 (0)