mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-26 09:46:15 -04:00
feat(new-tool): ipv4 address converter
This commit is contained in:
parent
8930e139b2
commit
28145e0ffe
5 changed files with 152 additions and 1 deletions
64
src/tools/ipv4-address-converter/ipv4-address-converter.vue
Normal file
64
src/tools/ipv4-address-converter/ipv4-address-converter.vue
Normal file
|
@ -0,0 +1,64 @@
|
|||
<template>
|
||||
<div>
|
||||
<n-form-item label="An ipv4 address:" v-bind="validationAttrs">
|
||||
<n-input v-model:value="rawIpAddress" placeholder="An ipv4 address..." />
|
||||
</n-form-item>
|
||||
|
||||
<n-divider style="margin-top: 0" mt-0 />
|
||||
|
||||
<n-form-item
|
||||
v-for="{ label, value } of convertedSections"
|
||||
:key="label"
|
||||
:label="label"
|
||||
label-placement="left"
|
||||
label-width="100"
|
||||
>
|
||||
<input-copyable
|
||||
:value="validationAttrs.validationStatus === 'error' ? '' : value"
|
||||
placeholder="Set a correct ipv4 address"
|
||||
/>
|
||||
</n-form-item>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useValidation } from '@/composable/validation';
|
||||
import { convertBase } from '../integer-base-converter/integer-base-converter.model';
|
||||
import { ipv4ToInt, ipv4ToIpv6, isValidIpv4 } from './ipv4-address-converter.service';
|
||||
|
||||
const rawIpAddress = ref('192.168.1.1');
|
||||
|
||||
const convertedSections = computed(() => {
|
||||
const ipInDecimal = ipv4ToInt({ ip: rawIpAddress.value });
|
||||
|
||||
return [
|
||||
{
|
||||
label: 'Decimal : ',
|
||||
value: String(ipInDecimal),
|
||||
},
|
||||
{
|
||||
label: 'Hexadecimal: ',
|
||||
value: convertBase({ fromBase: 10, toBase: 16, value: String(ipInDecimal) }).toUpperCase(),
|
||||
},
|
||||
{
|
||||
label: 'Binary: ',
|
||||
value: convertBase({ fromBase: 10, toBase: 2, value: String(ipInDecimal) }),
|
||||
},
|
||||
{
|
||||
label: 'Ipv6: ',
|
||||
value: ipv4ToIpv6({ ip: rawIpAddress.value }),
|
||||
},
|
||||
{
|
||||
label: 'Ipv6 (short): ',
|
||||
value: ipv4ToIpv6({ ip: rawIpAddress.value, prefix: '::ffff:' }),
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
const { attrs: validationAttrs } = useValidation({
|
||||
source: rawIpAddress,
|
||||
rules: [{ message: 'Invalid ipv4 address', validator: (ip) => isValidIpv4({ ip }) }],
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
Loading…
Add table
Add a link
Reference in a new issue