mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-27 07:58:54 +03:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd44c72fc5 |
No files matched your search
+5
-5
@@ -42,9 +42,9 @@
|
||||
"@regexper/render": "^1.0.0",
|
||||
"@sindresorhus/slugify": "^2.2.1",
|
||||
"@tabler/icons-vue": "^3.20.0",
|
||||
"@tiptap/pm": "2.1.6",
|
||||
"@tiptap/starter-kit": "2.1.6",
|
||||
"@tiptap/vue-3": "2.0.3",
|
||||
"@tiptap/pm": "2.11.0",
|
||||
"@tiptap/starter-kit": "2.11.0",
|
||||
"@tiptap/vue-3": "2.11.0",
|
||||
"@types/figlet": "^1.5.8",
|
||||
"@types/markdown-it": "^13.0.7",
|
||||
"@vicons/material": "^0.12.0",
|
||||
@@ -94,7 +94,7 @@
|
||||
"ulid": "^2.3.0",
|
||||
"unicode-emoji-json": "^0.4.0",
|
||||
"unplugin-auto-import": "^0.16.4",
|
||||
"uuid": "^9.0.0",
|
||||
"uuid": "^11.0.3",
|
||||
"vue": "^3.3.4",
|
||||
"vue-i18n": "^9.9.1",
|
||||
"vue-router": "^4.1.6",
|
||||
@@ -123,7 +123,7 @@
|
||||
"@types/node-forge": "^1.3.2",
|
||||
"@types/qrcode": "^1.5.0",
|
||||
"@types/ua-parser-js": "^0.7.36",
|
||||
"@types/uuid": "^9.0.0",
|
||||
"@types/uuid": "^10.0.0",
|
||||
"@unocss/eslint-config": "^0.57.0",
|
||||
"@vitejs/plugin-vue": "^4.3.2",
|
||||
"@vitejs/plugin-vue-jsx": "^3.0.2",
|
||||
|
||||
Generated
+2108
-1909
File diff suppressed because it is too large.
Load diff
@@ -1,10 +1,11 @@
|
||||
import { Link } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Encode/decode url formatted strings',
|
||||
name: translate('tools.url-encoder.title'),
|
||||
path: '/url-encoder',
|
||||
description: 'Encode to url-encoded format (also known as "percent-encoded") or decode from it.',
|
||||
description: translate('tools.url-encoder.description'),
|
||||
keywords: ['url', 'encode', 'decode', 'percent', '%20', 'format'],
|
||||
component: () => import('./url-encoder.vue'),
|
||||
icon: Link,
|
||||
|
||||
@@ -1,82 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { useQueryParamOrStorage } from '@/composable/queryParams';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
import { isNotThrowing } from '@/utils/boolean';
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
|
||||
const encodings = [
|
||||
{ value: 'URIComponent', label: 'URIComponent' },
|
||||
{ value: 'RFC3986URIComponent', label: 'RFC3986 - URIComponent' },
|
||||
{ value: 'RFC5987', label: 'RFC5987 (Link - Content-Disposition)' },
|
||||
{ value: 'URI', label: 'URI' },
|
||||
{ value: 'RFC3986URI', label: 'RFC3986 - URI' },
|
||||
];
|
||||
const encoding = useQueryParamOrStorage({ name: 'enc', storageName: 'url-encode:enc', defaultValue: 'URIComponent' });
|
||||
|
||||
function encodeRFC3986URIComponent(str: string) {
|
||||
return encodeURIComponent(str).replace(
|
||||
/[!'()*]/g,
|
||||
(c: string) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`,
|
||||
);
|
||||
}
|
||||
|
||||
function encodeRFC5987ValueChars(str: string) {
|
||||
return (
|
||||
encodeURIComponent(str)
|
||||
// The following creates the sequences %27 %28 %29 %2A (Note that
|
||||
// the valid encoding of "*" is %2A, which necessitates calling
|
||||
// toUpperCase() to properly encode). Although RFC3986 reserves "!",
|
||||
// RFC5987 does not, so we do not need to escape it.
|
||||
.replace(
|
||||
/['()*]/g,
|
||||
c => `%${c.charCodeAt(0).toString(16).toUpperCase()}`,
|
||||
)
|
||||
// The following are not required for percent-encoding per RFC5987,
|
||||
// so we can allow for a little better readability over the wire: |`^
|
||||
.replace(/%(7C|60|5E)/g, (str, hex) =>
|
||||
String.fromCharCode(Number.parseInt(hex, 16)),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function encodeRFC3986URI(str: string) {
|
||||
return encodeURI(str)
|
||||
.replace(/%5B/g, '[')
|
||||
.replace(/%5D/g, ']')
|
||||
.replace(
|
||||
/[!'()*]/g,
|
||||
c => `%${c.charCodeAt(0).toString(16).toUpperCase()}`,
|
||||
);
|
||||
}
|
||||
|
||||
function encode(str: string) {
|
||||
if (encoding.value === 'URIComponent') {
|
||||
return encodeURIComponent(str);
|
||||
}
|
||||
if (encoding.value === 'RFC3986URIComponent') {
|
||||
return encodeRFC3986URIComponent(str);
|
||||
}
|
||||
if (encoding.value === 'RFC5987') {
|
||||
return encodeRFC5987ValueChars(str);
|
||||
}
|
||||
if (encoding.value === 'URI') {
|
||||
return encodeURI(str);
|
||||
}
|
||||
if (encoding.value === 'RFC3986URI') {
|
||||
return encodeRFC3986URI(str);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
const encodeInput = ref('Hello world :)');
|
||||
const encodeOutput = computed(() => withDefaultOnError(() => encode(encodeInput.value), ''));
|
||||
const encodeOutput = computed(() => withDefaultOnError(() => encodeURIComponent(encodeInput.value), ''));
|
||||
|
||||
const encodedValidation = useValidation({
|
||||
source: encodeInput,
|
||||
rules: [
|
||||
{
|
||||
validator: value => isNotThrowing(() => encode(value)),
|
||||
validator: value => isNotThrowing(() => encodeURIComponent(value)),
|
||||
message: 'Impossible to parse this string',
|
||||
},
|
||||
],
|
||||
@@ -88,7 +23,7 @@ const decodeInput = ref('Hello%20world%20%3A)');
|
||||
const decodeOutput = computed(() => withDefaultOnError(() => decodeURIComponent(decodeInput.value), ''));
|
||||
|
||||
const decodeValidation = useValidation({
|
||||
source: encodeInput,
|
||||
source: decodeInput,
|
||||
rules: [
|
||||
{
|
||||
validator: value => isNotThrowing(() => decodeURIComponent(value)),
|
||||
@@ -102,15 +37,6 @@ const { copy: copyDecoded } = useCopy({ source: decodeOutput, text: 'Decoded str
|
||||
|
||||
<template>
|
||||
<c-card title="Encode">
|
||||
<c-select
|
||||
v-model:value="encoding"
|
||||
label="Encoding Kind:"
|
||||
label-position="left"
|
||||
:options="encodings"
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<c-input-text
|
||||
v-model:value="encodeInput"
|
||||
label="Your string :"
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { v1 as generateUuidV1, v3 as generateUuidV3, v4 as generateUuidV4, v5 as generateUuidV5, NIL as nilUuid } from 'uuid';
|
||||
import { v1 as generateUuidV1, v3 as generateUuidV3, v4 as generateUuidV4, v5 as generateUuidV5, v6 as generateUuidV6, v7 as generateUuidV7, NIL as nilUuid } from 'uuid';
|
||||
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { computedRefreshable } from '@/composable/computedRefreshable';
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
|
||||
const versions = ['NIL', 'v1', 'v3', 'v4', 'v5'] as const;
|
||||
const versions = ['NIL', 'v1', 'v3', 'v4', 'v5', 'v6', 'v7'] as const;
|
||||
|
||||
const version = useStorage<typeof versions[number]>('uuid-generator:version', 'v4');
|
||||
const count = useStorage('uuid-generator:quantity', 1);
|
||||
@@ -29,11 +30,13 @@ const generators = {
|
||||
clockseq: index,
|
||||
msecs: Date.now(),
|
||||
nsecs: Math.floor(Math.random() * 10000),
|
||||
node: Array.from({ length: 6 }, () => Math.floor(Math.random() * 256)),
|
||||
node: Uint8Array.from(Array.from({ length: 6 }, () => Math.floor(Math.random() * 256))), // NOSONAR
|
||||
}),
|
||||
v3: () => generateUuidV3(v35Args.value.name, v35Args.value.namespace),
|
||||
v4: () => generateUuidV4(),
|
||||
v5: () => generateUuidV5(v35Args.value.name, v35Args.value.namespace),
|
||||
v6: () => generateUuidV6(),
|
||||
v7: () => generateUuidV7(),
|
||||
};
|
||||
|
||||
const [uuids, refreshUUIDs] = computedRefreshable(() => withDefaultOnError(() =>
|
||||
|
||||
Reference in new issue
Block a user