Compare commits

..
Author SHA1 Message Date
ShareVB 55b4a8ce57 feat(Url Encoder): enhance encoding options
Handles RFC3986 - URIComponent ; RFC5987 (Link - Content-Disposition) and others
Fix #1445
2025-01-26 19:43:18 +01:00
9 changed files with 645 additions and 430 deletions

No files matched your search

+2 -4
View File
@@ -11,7 +11,6 @@ declare module '@vue/runtime-core' {
export interface GlobalComponents {
'404.page': typeof import('./src/pages/404.page.vue')['default']
About: typeof import('./src/pages/About.vue')['default']
AiPromptSplitter: typeof import('./src/tools/ai-prompt-splitter/ai-prompt-splitter.vue')['default']
App: typeof import('./src/App.vue')['default']
AsciiTextDrawer: typeof import('./src/tools/ascii-text-drawer/ascii-text-drawer.vue')['default']
'Base.layout': typeof import('./src/layouts/base.layout.vue')['default']
@@ -136,15 +135,14 @@ declare module '@vue/runtime-core' {
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NDivider: typeof import('naive-ui')['NDivider']
NEllipsis: typeof import('naive-ui')['NEllipsis']
NFormItem: typeof import('naive-ui')['NFormItem']
NH1: typeof import('naive-ui')['NH1']
NH3: typeof import('naive-ui')['NH3']
NIcon: typeof import('naive-ui')['NIcon']
NLayout: typeof import('naive-ui')['NLayout']
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NMenu: typeof import('naive-ui')['NMenu']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NTag: typeof import('naive-ui')['NTag']
NSpace: typeof import('naive-ui')['NSpace']
NTable: typeof import('naive-ui')['NTable']
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
-1
View File
@@ -54,7 +54,6 @@
"@vueuse/router": "^10.0.0",
"bcryptjs": "^2.4.3",
"change-case": "^4.1.2",
"chatgpt-prompt-splitter": "^1.0.5",
"colord": "^2.9.3",
"composerize-ts": "^0.6.2",
"country-code-lookup": "^0.1.0",
+564 -343
View File
File diff suppressed because it is too large. Load diff
@@ -1,55 +0,0 @@
<script setup lang="ts">
import promptSplitter from 'chatgpt-prompt-splitter';
import { useValidation } from '@/composable/validation';
const prompt = ref('');
const splitLength = ref(1024);
const splittedPrompts = computed(() => {
try {
return promptSplitter({
prompt: prompt.value,
splitLength: splitLength.value,
newLine: true,
});
}
catch (e: any) {
return [e.toString()];
}
});
const promptValidation = useValidation({
source: prompt,
rules: [
{
validator: v => v !== '',
message: 'Prompt must not be empty',
},
],
});
</script>
<template>
<div style="max-width: 600px;">
<c-card title="Prompt and options" mb-2>
<c-input-text
v-model:value="prompt"
label="Full Prompt"
multiline
placeholder="Put your full prompt here..."
rows="10"
:validation="promptValidation"
mb-2
/>
<n-form-item label="Character length for each chunk">
<n-input-number v-model:value="splitLength" :min="1" />
</n-form-item>
</c-card>
<c-card title="Divided prompts">
<div v-for="(splittedPrompt, index) in splittedPrompts" :key="index">
<TextareaCopyable :value="splittedPrompt" />
</div>
</c-card>
</div>
</template>
@@ -1,7 +0,0 @@
declare module "chatgpt-prompt-splitter" {
export default function promptSplitter(options: {
prompt: string
splitLength: number
newLine: boolean
}): Array<string>;
}
-12
View File
@@ -1,12 +0,0 @@
import { Prompt } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'AI Prompt Splitter',
path: '/ai-prompt-splitter',
description: 'Split a long document to multiple chat (ie ChatGPT) prompts',
keywords: ['ai', 'chatgpt', 'gpt', 'prompt', 'splitter'],
component: () => import('./ai-prompt-splitter.vue'),
icon: Prompt,
createdAt: new Date('2024-07-14'),
});
-2
View File
@@ -9,7 +9,6 @@ import { tool as textToUnicode } from './text-to-unicode';
import { tool as safelinkDecoder } from './safelink-decoder';
import { tool as xmlToJson } from './xml-to-json';
import { tool as jsonToXml } from './json-to-xml';
import { tool as aiPromptSplitter } from './ai-prompt-splitter';
import { tool as regexTester } from './regex-tester';
import { tool as regexMemo } from './regex-memo';
import { tool as markdownToHtml } from './markdown-to-html';
@@ -184,7 +183,6 @@ export const toolsByCategory: ToolCategory[] = [
stringObfuscator,
textDiff,
numeronymGenerator,
aiPromptSplitter,
asciiTextDrawer,
],
},
+2 -3
View File
@@ -1,11 +1,10 @@
import { Link } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate } from '@/plugins/i18n.plugin';
export const tool = defineTool({
name: translate('tools.url-encoder.title'),
name: 'Encode/decode url formatted strings',
path: '/url-encoder',
description: translate('tools.url-encoder.description'),
description: 'Encode to url-encoded format (also known as "percent-encoded") or decode from it.',
keywords: ['url', 'encode', 'decode', 'percent', '%20', 'format'],
component: () => import('./url-encoder.vue'),
icon: Link,
+77 -3
View File
@@ -1,17 +1,82 @@
<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(() => encodeURIComponent(encodeInput.value), ''));
const encodeOutput = computed(() => withDefaultOnError(() => encode(encodeInput.value), ''));
const encodedValidation = useValidation({
source: encodeInput,
rules: [
{
validator: value => isNotThrowing(() => encodeURIComponent(value)),
validator: value => isNotThrowing(() => encode(value)),
message: 'Impossible to parse this string',
},
],
@@ -23,7 +88,7 @@ const decodeInput = ref('Hello%20world%20%3A)');
const decodeOutput = computed(() => withDefaultOnError(() => decodeURIComponent(decodeInput.value), ''));
const decodeValidation = useValidation({
source: decodeInput,
source: encodeInput,
rules: [
{
validator: value => isNotThrowing(() => decodeURIComponent(value)),
@@ -37,6 +102,15 @@ 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 :"