mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
fix: ip and integer wrong merge
This commit is contained in:
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
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user