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

133 lines
2.9 KiB
Vue
Raw Normal View History

2022-04-13 13:29:44 +02:00
<template>
2022-04-16 16:16:00 +02:00
<div>
2022-04-15 23:10:47 +02:00
<n-card title="Encode">
<n-form-item
label="Your string :"
:feedback="encodedValidation.message"
:validation-status="encodedValidation.status"
>
<n-input
v-model:value="encodeInput"
type="textarea"
placeholder="The string to encode"
2022-04-16 16:16:00 +02:00
:autosize="{ minRows: 2 }"
2022-04-15 23:10:47 +02:00
/>
</n-form-item>
2022-04-13 13:29:44 +02:00
2022-04-15 23:10:47 +02:00
<n-form-item label="Your string encoded :">
<n-input
:value="encodeOutput"
type="textarea"
readonly
placeholder="Your string encoded"
2022-04-16 16:16:00 +02:00
:autosize="{ minRows: 2 }"
2022-04-15 23:10:47 +02:00
/>
</n-form-item>
2022-04-13 13:29:44 +02:00
2022-04-15 23:10:47 +02:00
<n-space justify="center">
<n-button
secondary
@click="copyEncoded"
>
Copy
</n-button>
</n-space>
</n-card>
2022-04-16 16:16:00 +02:00
<br>
<n-card title="Decode">
2022-04-15 23:10:47 +02:00
<n-form-item
2022-04-16 16:16:00 +02:00
label="Your encoded string :"
2022-04-15 23:10:47 +02:00
:feedback="decodeValidation.message"
:validation-status="decodeValidation.status"
>
<n-input
v-model:value="decodeInput"
type="textarea"
placeholder="The string to decode"
2022-04-16 16:16:00 +02:00
:autosize="{ minRows: 2 }"
2022-04-15 23:10:47 +02:00
/>
</n-form-item>
2022-04-13 13:29:44 +02:00
2022-04-16 16:16:00 +02:00
<n-form-item label="Your string decoded :">
2022-04-15 23:10:47 +02:00
<n-input
:value="decodeOutput"
type="textarea"
readonly
placeholder="Your string decoded"
2022-04-16 16:16:00 +02:00
:autosize="{ minRows: 2 }"
2022-04-15 23:10:47 +02:00
/>
</n-form-item>
2022-04-13 13:29:44 +02:00
2022-04-15 23:10:47 +02:00
<n-space justify="center">
<n-button
secondary
@click="copyDecoded"
>
Copy
</n-button>
</n-space>
</n-card>
2022-04-16 16:16:00 +02:00
</div>
2022-04-13 13:29:44 +02:00
</template>
<script setup lang="ts">
import { useCopy } from '@/composable/copy';
import { useValidation } from '@/composable/validation';
import { computed, ref } from 'vue'
const encodeInput = ref('Hello world :)')
const encodeOutput = computed(() => {
2022-04-16 16:16:00 +02:00
try {
return encodeURIComponent(encodeInput.value)
} catch (_) {
return ''
}
2022-04-13 13:29:44 +02:00
})
const encodedValidation = useValidation({
2022-04-16 16:16:00 +02:00
source: encodeInput, rules: [{
validator: (value) => {
try {
encodeURIComponent(value)
return true
} catch (_) {
return false
}
},
message: 'Impossible to parse this string'
}]
2022-04-13 13:29:44 +02:00
})
const { copy: copyEncoded } = useCopy({ source: encodeOutput, text: 'Encoded string copied to the clipboard' })
const decodeInput = ref('Hello%20world%20%3A)')
const decodeOutput = computed(() => {
2022-04-16 16:16:00 +02:00
try {
return decodeURIComponent(decodeInput.value)
} catch (_) {
return ''
}
2022-04-13 13:29:44 +02:00
})
const decodeValidation = useValidation({
2022-04-16 16:16:00 +02:00
source: encodeInput, rules: [{
validator: (value) => {
try {
decodeURIComponent(value)
return true
} catch (_) {
return false
}
},
message: 'Impossible to parse this string'
}]
2022-04-13 13:29:44 +02:00
})
const { copy: copyDecoded } = useCopy({ source: decodeOutput, text: 'Decoded string copied to the clipboard' })
</script>