mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-24 00:36:14 -04:00
chore(lint): switched to a better lint config
This commit is contained in:
parent
4d2b037dbe
commit
33c9b6643f
178 changed files with 4105 additions and 3371 deletions
|
@ -1,4 +1,4 @@
|
|||
import { test, expect } from '@playwright/test';
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
test.describe('Tool - IPv4 range expander', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { expect, describe, it } from 'vitest';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { calculateCidr } from './ipv4-range-expander.service';
|
||||
|
||||
describe('ipv4RangeExpander', () => {
|
||||
|
|
|
@ -1,20 +1,25 @@
|
|||
import type { Ipv4RangeExpanderResult } from './ipv4-range-expander.types';
|
||||
import { convertBase } from '../integer-base-converter/integer-base-converter.model';
|
||||
import { ipv4ToInt } from '../ipv4-address-converter/ipv4-address-converter.service';
|
||||
import type { Ipv4RangeExpanderResult } from './ipv4-range-expander.types';
|
||||
|
||||
export { calculateCidr };
|
||||
|
||||
function bits2ip(ipInt: number) {
|
||||
return (ipInt >>> 24) + '.' + ((ipInt >> 16) & 255) + '.' + ((ipInt >> 8) & 255) + '.' + (ipInt & 255);
|
||||
return `${ipInt >>> 24}.${(ipInt >> 16) & 255}.${(ipInt >> 8) & 255}.${ipInt & 255}`;
|
||||
}
|
||||
|
||||
function getRangesize(start: string, end: string) {
|
||||
if (start == null || end == null) return -1;
|
||||
if (start == null || end == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1 + parseInt(end, 2) - parseInt(start, 2);
|
||||
}
|
||||
|
||||
function getCidr(start: string, end: string) {
|
||||
if (start == null || end == null) return null;
|
||||
if (start == null || end == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const range = getRangesize(start, end);
|
||||
if (range < 1) {
|
||||
|
@ -32,7 +37,7 @@ function getCidr(start: string, end: string) {
|
|||
const newStart = start.substring(0, mask) + '0'.repeat(32 - mask);
|
||||
const newEnd = end.substring(0, mask) + '1'.repeat(32 - mask);
|
||||
|
||||
return { start: newStart, end: newEnd, mask: mask };
|
||||
return { start: newStart, end: newEnd, mask };
|
||||
}
|
||||
|
||||
function calculateCidr({ startIp, endIp }: { startIp: string; endIp: string }) {
|
||||
|
@ -52,7 +57,7 @@ function calculateCidr({ startIp, endIp }: { startIp: string; endIp: string }) {
|
|||
const result: Ipv4RangeExpanderResult = {};
|
||||
result.newEnd = bits2ip(parseInt(cidr.end, 2));
|
||||
result.newStart = bits2ip(parseInt(cidr.start, 2));
|
||||
result.newCidr = result.newStart + '/' + cidr.mask;
|
||||
result.newCidr = `${result.newStart}/${cidr.mask}`;
|
||||
result.newSize = getRangesize(cidr.start, cidr.end);
|
||||
|
||||
result.oldSize = getRangesize(start, end);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
export type Ipv4RangeExpanderResult = {
|
||||
oldSize?: number;
|
||||
newStart?: string;
|
||||
newEnd?: string;
|
||||
newCidr?: string;
|
||||
newSize?: number;
|
||||
};
|
||||
export interface Ipv4RangeExpanderResult {
|
||||
oldSize?: number
|
||||
newStart?: string
|
||||
newEnd?: string
|
||||
newCidr?: string
|
||||
newSize?: number
|
||||
}
|
||||
|
|
|
@ -1,3 +1,61 @@
|
|||
<script setup lang="ts">
|
||||
import { Exchange } from '@vicons/tabler';
|
||||
import { isValidIpv4 } from '../ipv4-address-converter/ipv4-address-converter.service';
|
||||
import type { Ipv4RangeExpanderResult } from './ipv4-range-expander.types';
|
||||
import { calculateCidr } from './ipv4-range-expander.service';
|
||||
import ResultRow from './result-row.vue';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
|
||||
const rawStartAddress = useStorage('ipv4-range-expander:startAddress', '192.168.1.1');
|
||||
const rawEndAddress = useStorage('ipv4-range-expander:endAddress', '192.168.6.255');
|
||||
|
||||
const result = computed(() => calculateCidr({ startIp: rawStartAddress.value, endIp: rawEndAddress.value }));
|
||||
|
||||
const calculatedValues: {
|
||||
label: string
|
||||
getOldValue: (result: Ipv4RangeExpanderResult | undefined) => string | undefined
|
||||
getNewValue: (result: Ipv4RangeExpanderResult | undefined) => string | undefined
|
||||
}[] = [
|
||||
{
|
||||
label: 'Start address',
|
||||
getOldValue: () => rawStartAddress.value,
|
||||
getNewValue: result => result?.newStart,
|
||||
},
|
||||
{
|
||||
label: 'End address',
|
||||
getOldValue: () => rawEndAddress.value,
|
||||
getNewValue: result => result?.newEnd,
|
||||
},
|
||||
{
|
||||
label: 'Addresses in range',
|
||||
getOldValue: result => result?.oldSize?.toLocaleString(),
|
||||
getNewValue: result => result?.newSize?.toLocaleString(),
|
||||
},
|
||||
{
|
||||
label: 'CIDR',
|
||||
getOldValue: () => '',
|
||||
getNewValue: result => result?.newCidr,
|
||||
},
|
||||
];
|
||||
|
||||
const startIpValidation = useValidation({
|
||||
source: rawStartAddress,
|
||||
rules: [{ message: 'Invalid ipv4 address', validator: ip => isValidIpv4({ ip }) }],
|
||||
});
|
||||
const endIpValidation = useValidation({
|
||||
source: rawEndAddress,
|
||||
rules: [{ message: 'Invalid ipv4 address', validator: ip => isValidIpv4({ ip }) }],
|
||||
});
|
||||
|
||||
const showResult = computed(() => endIpValidation.isValid && startIpValidation.isValid && result.value !== undefined);
|
||||
|
||||
function onSwitchStartEndClicked() {
|
||||
const tmpStart = rawStartAddress.value;
|
||||
rawStartAddress.value = rawEndAddress.value;
|
||||
rawEndAddress.value = tmpStart;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div mb-4 flex gap-4>
|
||||
|
@ -21,13 +79,19 @@
|
|||
<n-table v-if="showResult" data-test-id="result">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col"> </th>
|
||||
<th scope="col">old value</th>
|
||||
<th scope="col">new value</th>
|
||||
<th scope="col">
|
||||
|
||||
</th>
|
||||
<th scope="col">
|
||||
old value
|
||||
</th>
|
||||
<th scope="col">
|
||||
new value
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<result-row
|
||||
<ResultRow
|
||||
v-for="{ label, getOldValue, getNewValue } in calculatedValues"
|
||||
:key="label"
|
||||
:label="label"
|
||||
|
@ -53,62 +117,3 @@
|
|||
</n-alert>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useValidation } from '@/composable/validation';
|
||||
import { Exchange } from '@vicons/tabler';
|
||||
import { isValidIpv4 } from '../ipv4-address-converter/ipv4-address-converter.service';
|
||||
import type { Ipv4RangeExpanderResult } from './ipv4-range-expander.types';
|
||||
import { calculateCidr } from './ipv4-range-expander.service';
|
||||
import ResultRow from './result-row.vue';
|
||||
|
||||
const rawStartAddress = useStorage('ipv4-range-expander:startAddress', '192.168.1.1');
|
||||
const rawEndAddress = useStorage('ipv4-range-expander:endAddress', '192.168.6.255');
|
||||
|
||||
const result = computed(() => calculateCidr({ startIp: rawStartAddress.value, endIp: rawEndAddress.value }));
|
||||
|
||||
const calculatedValues: {
|
||||
label: string;
|
||||
getOldValue: (result: Ipv4RangeExpanderResult | undefined) => string | undefined;
|
||||
getNewValue: (result: Ipv4RangeExpanderResult | undefined) => string | undefined;
|
||||
}[] = [
|
||||
{
|
||||
label: 'Start address',
|
||||
getOldValue: () => rawStartAddress.value,
|
||||
getNewValue: (result) => result?.newStart,
|
||||
},
|
||||
{
|
||||
label: 'End address',
|
||||
getOldValue: () => rawEndAddress.value,
|
||||
getNewValue: (result) => result?.newEnd,
|
||||
},
|
||||
{
|
||||
label: 'Addresses in range',
|
||||
getOldValue: (result) => result?.oldSize?.toLocaleString(),
|
||||
getNewValue: (result) => result?.newSize?.toLocaleString(),
|
||||
},
|
||||
{
|
||||
label: 'CIDR',
|
||||
getOldValue: () => '',
|
||||
getNewValue: (result) => result?.newCidr,
|
||||
},
|
||||
];
|
||||
|
||||
const showResult = computed(() => endIpValidation.isValid && startIpValidation.isValid && result.value !== undefined);
|
||||
const startIpValidation = useValidation({
|
||||
source: rawStartAddress,
|
||||
rules: [{ message: 'Invalid ipv4 address', validator: (ip) => isValidIpv4({ ip }) }],
|
||||
});
|
||||
const endIpValidation = useValidation({
|
||||
source: rawEndAddress,
|
||||
rules: [{ message: 'Invalid ipv4 address', validator: (ip) => isValidIpv4({ ip }) }],
|
||||
});
|
||||
|
||||
function onSwitchStartEndClicked() {
|
||||
const tmpStart = rawStartAddress.value;
|
||||
rawStartAddress.value = rawEndAddress.value;
|
||||
rawEndAddress.value = tmpStart;
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
||||
|
|
|
@ -1,18 +1,6 @@
|
|||
<template>
|
||||
<tr>
|
||||
<td>
|
||||
<n-text strong>{{ label }}</n-text>
|
||||
</td>
|
||||
<td :data-test-id="testId + '.old'"><span-copyable :value="oldValue" class="monospace" /></td>
|
||||
<td :data-test-id="testId + '.new'">
|
||||
<span-copyable :value="newValue"></span-copyable>
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import SpanCopyable from '@/components/SpanCopyable.vue';
|
||||
import _ from 'lodash';
|
||||
import SpanCopyable from '@/components/SpanCopyable.vue';
|
||||
|
||||
const props = withDefaults(defineProps<{ label: string; oldValue?: string; newValue?: string }>(), {
|
||||
label: '',
|
||||
|
@ -24,4 +12,18 @@ const { label, oldValue, newValue } = toRefs(props);
|
|||
const testId = computed(() => _.kebabCase(label.value));
|
||||
</script>
|
||||
|
||||
<style scoped lang="less"></style>
|
||||
<template>
|
||||
<tr>
|
||||
<td>
|
||||
<n-text strong>
|
||||
{{ label }}
|
||||
</n-text>
|
||||
</td>
|
||||
<td :data-test-id="`${testId}.old`">
|
||||
<SpanCopyable :value="oldValue" class="monospace" />
|
||||
</td>
|
||||
<td :data-test-id="`${testId}.new`">
|
||||
<SpanCopyable :value="newValue" />
|
||||
</td>
|
||||
</tr>
|
||||
</template>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue