Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(new-tool):-ipv6-address-converter #221

Open
wants to merge 5 commits into
base: developing/2.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ declare module '@vue/runtime-core' {
Ipv4AddressConverter: typeof import('./src/tools/ipv4-address-converter/ipv4-address-converter.vue')['default']
Ipv4RangeExpander: typeof import('./src/tools/ipv4-range-expander/ipv4-range-expander.vue')['default']
Ipv4SubnetCalculator: typeof import('./src/tools/ipv4-subnet-calculator/ipv4-subnet-calculator.vue')['default']
Ipv6AddressConverter: typeof import('./src/tools/ipv6-address-converter/ipv6-address-converter.vue')['default']
Ipv6UlaGenerator: typeof import('./src/tools/ipv6-ula-generator/ipv6-ula-generator.vue')['default']
JsonDiff: typeof import('./src/tools/json-diff/json-diff.vue')['default']
JsonMinify: typeof import('./src/tools/json-minify/json-minify.vue')['default']
Expand Down
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@vueuse/router": "^10.0.0",
"bcryptjs": "^2.4.3",
"change-case": "^4.1.2",
"cidr-tools": "^7.0.4",
"colord": "^2.9.3",
"composerize-ts": "^0.6.2",
"country-code-lookup": "^0.1.0",
Expand All @@ -64,6 +65,12 @@
"highlight.js": "^11.7.0",
"iarna-toml-esm": "^3.0.5",
"ibantools": "^4.3.3",
"ip-address": "^9.0.5",
"ip-bigint": "^8.0.2",
"ip-cidr": "^4.0.0",
"ip-matching": "^2.1.2",
"is-cidr": "^5.0.3",
"is-ip": "^5.0.1",
"json5": "^2.2.3",
"jwt-decode": "^3.1.2",
"libphonenumber-js": "^1.10.28",
Expand Down
127 changes: 124 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import { tool as uuidGenerator } from './uuid-generator';
import { tool as macAddressLookup } from './mac-address-lookup';
import { tool as xmlFormatter } from './xml-formatter';
import { tool as yamlViewer } from './yaml-viewer';
import { tool as ipv6AddressConverter } from './ipv6-address-converter';

export const toolsByCategory: ToolCategory[] = [
{
Expand Down Expand Up @@ -152,7 +153,15 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Network',
components: [ipv4SubnetCalculator, ipv4AddressConverter, ipv4RangeExpander, macAddressLookup, macAddressGenerator, ipv6UlaGenerator],
components: [
ipv4SubnetCalculator,
ipv4AddressConverter,
ipv6AddressConverter,
ipv4RangeExpander,
macAddressLookup,
macAddressGenerator,
ipv6UlaGenerator,
],
},
{
name: 'Math',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ describe('integer-base-converter', () => {
expect(convertBase({ value: '10100101', fromBase: 2, toBase: 16 })).toEqual('a5');
expect(convertBase({ value: '192654', fromBase: 10, toBase: 8 })).toEqual('570216');
expect(convertBase({ value: 'zz', fromBase: 64, toBase: 10 })).toEqual('2275');
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');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ export function convertBase({ value, fromBase, toBase }: { value: string; fromBa
let decValue = value
.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 ${fromBase}.`);
}
return (carry += fromRange.indexOf(digit) * fromBase ** 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';
}
43 changes: 43 additions & 0 deletions src/tools/ipv6-address-converter/cidr-tools.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 12 additions & 0 deletions src/tools/ipv6-address-converter/index.ts
Original file line number Diff line number Diff line change
@@ -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'),
});
Loading