diff --git a/src/tools/index.ts b/src/tools/index.ts
index b6f93785..f701fa89 100644
--- a/src/tools/index.ts
+++ b/src/tools/index.ts
@@ -208,6 +208,7 @@ import { tool as htmlToMarkdown } from './html-to-markdown';
import { tool as pdfUnlock } from './pdf-unlock';
import { tool as ipCidrToRange } from './ip-cidr-to-range';
import { tool as ipRangeToCidr } from './ip-range-to-cidr';
+import { tool as ipv6AddressConverter } from './ipv6-address-converter';
export const toolsByCategory: ToolCategory[] = [
{
@@ -407,6 +408,7 @@ export const toolsByCategory: ToolCategory[] = [
ipv4AddressConverter,
// ipv6AddressConverter,
ipInRange,
+ ipv6AddressConverter,
ipv4RangeExpander,
macAddressLookup,
macAddressGenerator,
diff --git a/src/tools/integer-base-converter/integer-base-converter.model.test.ts b/src/tools/integer-base-converter/integer-base-converter.model.test.ts
index b7bcf95b..ed16c142 100644
--- a/src/tools/integer-base-converter/integer-base-converter.model.test.ts
+++ b/src/tools/integer-base-converter/integer-base-converter.model.test.ts
@@ -26,6 +26,9 @@ describe('integer-base-converter', () => {
expect(convertBase({ value: '0b10101010', fromBase: -1, toBase: 10 })).toEqual('170');
expect(convertBase({ value: '0b_1010_1010', fromBase: -1, toBase: 10 })).toEqual('170');
expect(convertBase({ value: '192,654', fromBase: 10, toBase: 8 })).toEqual('570216');
+ expect(convertBase({ value: '42540766411283223938465490632011909384', fromBase: 10, toBase: 10 })).toEqual('42540766411283223938465490632011909384');
+ expect(convertBase({ value: '42540766411283223938465490632011909384', fromBase: 10, toBase: 16 })).toEqual('20010db8000085a300000000ac1f8908');
+ expect(convertBase({ value: '20010db8000085a300000000ac1f8908', fromBase: 16, toBase: 10 })).toEqual('42540766411283223938465490632011909384');
});
});
});
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..51cfab17 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(fromBase) ** 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/tools/ipv6-address-converter/cidr-tools.d.ts b/src/tools/ipv6-address-converter/cidr-tools.d.ts
new file mode 100644
index 00000000..a0504c0d
--- /dev/null
+++ b/src/tools/ipv6-address-converter/cidr-tools.d.ts
@@ -0,0 +1,43 @@
+declare module 'cidr-tools' {
+ type IPv4Address = string;
+ type IPv4CIDR = string;
+ type IPv6Address = string;
+ type IPv6CIDR = string;
+
+ type Network = IPv4Address | IPv4CIDR | IPv6Address | IPv6CIDR;
+ type Networks = Network | Network[];
+
+ type Parsed = {
+ cidr: string;
+ version: number;
+ prefix: string;
+ start: bigint;
+ end: bigint;
+ single: boolean;
+ ip: string;
+ };
+
+ type NormalizeOpts = {
+ compress?: boolean;
+ hexify?: boolean;
+ };
+
+ export function merge(networks: Networks): Network[];
+ export function exclude(baseNetworks: Networks, excludeNetworks: Networks): Network[];
+ export function expand(networks: Networks): Network[];
+ export function overlap(networksA: Networks, networksB: Networks): boolean;
+ export function normalize(cidr: Networks, opts?: NormalizeOpts): Networks;
+ export function contains(networksA: Networks, networksB: Networks): boolean;
+ export function parse(network: Network): Parsed;
+
+ declare const _default: {
+ merge: typeof merge;
+ exclude: typeof exclude;
+ expand: typeof expand;
+ overlap: typeof overlap;
+ normalize: typeof normalize;
+ contains: typeof contains;
+ parse: typeof parse;
+ };
+ export default _default;
+}
\ No newline at end of file
diff --git a/src/tools/ipv6-address-converter/index.ts b/src/tools/ipv6-address-converter/index.ts
new file mode 100644
index 00000000..50928ae6
--- /dev/null
+++ b/src/tools/ipv6-address-converter/index.ts
@@ -0,0 +1,12 @@
+import { Binary } from '@vicons/tabler';
+import { defineTool } from '../tool';
+
+export const tool = defineTool({
+ name: 'Ipv6 address converter',
+ path: '/ipv6-address-converter',
+ description: 'Convert an ip address into decimal, binary, hexadecimal and get infos',
+ keywords: ['ipv6', 'address', 'converter', 'decimal', 'hexadecimal', 'binary', 'ipv4'],
+ component: () => import('./ipv6-address-converter.vue'),
+ icon: Binary,
+ createdAt: new Date('2024-01-10'),
+});
diff --git a/src/tools/ipv6-address-converter/ip-bigint.d.ts b/src/tools/ipv6-address-converter/ip-bigint.d.ts
new file mode 100644
index 00000000..eff26030
--- /dev/null
+++ b/src/tools/ipv6-address-converter/ip-bigint.d.ts
@@ -0,0 +1,17 @@
+declare module 'ip-bigint' {
+ type IPInfo = {
+ number: bigint;
+ version: number;
+ ipv4mapped?: boolean;
+ scopeid?:string;
+ };
+ type StringifyOptions = {
+ compress?:boolean;
+ hexify?:boolean;
+ };
+
+ export function normalizeIp(ip: string, options: StringifyOptions = {compress = true, hexify = false} = {})
+ export function stringifyIp(ip: IPInfo, options: StringifyOptions = {compress = true, hexify = false}): string;
+ export function ipVersion(ip: string): number;
+ export function parseIp(ip): IPInfo;
+}
\ No newline at end of file
diff --git a/src/tools/ipv6-address-converter/ipv6-address-converter.vue b/src/tools/ipv6-address-converter/ipv6-address-converter.vue
new file mode 100644
index 00000000..19c04b01
--- /dev/null
+++ b/src/tools/ipv6-address-converter/ipv6-address-converter.vue
@@ -0,0 +1,84 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/tools/ipv6-address-converter/is-ip.d.ts b/src/tools/ipv6-address-converter/is-ip.d.ts
new file mode 100644
index 00000000..67709a81
--- /dev/null
+++ b/src/tools/ipv6-address-converter/is-ip.d.ts
@@ -0,0 +1,63 @@
+declare module 'is-ip' {
+
+ /**
+ Check if `string` is IPv6 or IPv4.
+
+ @example
+ ```
+ import {isIP} from 'is-ip';
+
+ isIP('1:2:3:4:5:6:7:8');
+ //=> true
+
+ isIP('192.168.0.1');
+ //=> true
+ ```
+ */
+ export function isIP(string: string): boolean; // eslint-disable-line @typescript-eslint/naming-convention
+
+ /**
+ Check if `string` is IPv6.
+
+ @example
+ ```
+ import {isIPv6} from 'is-ip';
+
+ isIPv6('1:2:3:4:5:6:7:8');
+ //=> true
+ ```
+ */
+ export function isIPv6(string: string): boolean; // eslint-disable-line @typescript-eslint/naming-convention
+
+ /**
+ Check if `string` is IPv4.
+
+ @example
+ ```
+ import {isIPv4} from 'is-ip';
+
+ isIPv4('192.168.0.1');
+ //=> true
+ ```
+ */
+ export function isIPv4(string: string): boolean; // eslint-disable-line @typescript-eslint/naming-convention
+
+ /**
+ @returns `6` if `string` is IPv6, `4` if `string` is IPv4, or `undefined` if `string` is neither.
+
+ @example
+ ```
+ import {ipVersion} from 'is-ip';
+
+ ipVersion('1:2:3:4:5:6:7:8');
+ //=> 6
+
+ ipVersion('192.168.0.1');
+ //=> 4
+
+ ipVersion('abc');
+ //=> undefined
+ ```
+ */
+ export function ipVersion(string: string): 6 | 4 | undefined;
+}
\ No newline at end of file