it-tools/src/tools/url-parser/url-parser.vue

77 lines
1.9 KiB
Vue
Raw Normal View History

2022-04-19 00:12:44 +02:00
<template>
<c-card>
<c-input-text
v-model:value="urlToParse"
label="Your url to parse:"
placeholder="Your url to parse..."
raw-text
:validation-rules="urlValidationRules"
/>
2022-04-19 00:12:44 +02:00
<n-divider />
2022-04-19 00:12:44 +02:00
<input-copyable
v-for="{ title, key } in properties"
:key="key"
:label="title"
:value="(urlParsed?.[key] as string) ?? ''"
readonly
label-position="left"
label-width="110px"
mb-2
placeholder=" "
/>
2022-04-19 00:12:44 +02:00
<div
v-for="[k, v] in Object.entries(Object.fromEntries(urlParsed?.searchParams.entries() ?? []))"
:key="k"
mb-2
w-full
flex
>
<div style="flex: 1 0 110px">
<icon-mdi-arrow-right-bottom />
</div>
<input-copyable :value="k" readonly />
<input-copyable :value="v" readonly />
</div>
</c-card>
2022-04-19 00:12:44 +02:00
</template>
<script setup lang="ts">
import { isNotThrowing } from '@/utils/boolean';
import { withDefaultOnError } from '@/utils/defaults';
import { computed, ref } from 'vue';
2022-08-04 22:46:50 +02:00
import InputCopyable from '../../components/InputCopyable.vue';
2022-04-19 00:12:44 +02:00
2022-04-22 23:31:40 +02:00
const urlToParse = ref('https://me:pwd@it-tools.tech:3000/url-parser?key1=value&key2=value2#the-hash');
const urlParsed = computed(() => withDefaultOnError(() => new URL(urlToParse.value), undefined));
const urlValidationRules = [
{
validator: (value: string) => isNotThrowing(() => new URL(value)),
message: 'Invalid url',
},
];
2022-04-19 00:12:44 +02:00
2022-04-22 23:31:40 +02:00
const properties: { title: string; key: keyof URL }[] = [
{ title: 'Protocol', key: 'protocol' },
{ title: 'Username', key: 'username' },
{ title: 'Password', key: 'password' },
{ title: 'Hostname', key: 'hostname' },
{ title: 'Port', key: 'port' },
{ title: 'Path', key: 'pathname' },
{ title: 'Params', key: 'search' },
];
2022-04-19 00:12:44 +02:00
</script>
<style lang="less" scoped>
.n-input-group-label {
text-align: right;
}
.n-input-group {
margin: 2px 0;
2022-04-19 00:12:44 +02:00
}
2022-04-22 23:31:40 +02:00
</style>