Compare commits

..
Author SHA1 Message Date
sharevb 9d3337ff60 feat(new tool): UTM URL Generator
UTM Url Generator
Fix #935
2024-04-03 22:52:39 +02:00
11 changed files with 197 additions and 117 deletions

No files matched your search

+1 -1
View File
@@ -15,7 +15,7 @@ jobs:
- run: corepack enable
- uses: actions/setup-node@v3
with:
node-version: 20
node-version: 16
cache: 'pnpm'
- name: Install dependencies
+1 -1
View File
@@ -18,7 +18,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 20
node-version: 16
cache: 'pnpm'
- name: Get Playwright version
-5
View File
@@ -127,10 +127,8 @@ declare module '@vue/runtime-core' {
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
MimeTypes: typeof import('./src/tools/mime-types/mime-types.vue')['default']
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
NCheckbox: typeof import('naive-ui')['NCheckbox']
NCode: typeof import('naive-ui')['NCode']
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
NColorPicker: typeof import('naive-ui')['NColorPicker']
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NDivider: typeof import('naive-ui')['NDivider']
NEllipsis: typeof import('naive-ui')['NEllipsis']
@@ -146,8 +144,6 @@ declare module '@vue/runtime-core' {
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
NMenu: typeof import('naive-ui')['NMenu']
NScrollbar: typeof import('naive-ui')['NScrollbar']
NSlider: typeof import('naive-ui')['NSlider']
NSpace: typeof import('naive-ui')['NSpace']
NSpin: typeof import('naive-ui')['NSpin']
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']
@@ -163,7 +159,6 @@ declare module '@vue/runtime-core' {
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
RsaKeyPairGenerator: typeof import('./src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue')['default']
SafelinkDecoder: typeof import('./src/tools/safelink-decoder/safelink-decoder.vue')['default']
SlugifyString: typeof import('./src/tools/slugify-string/slugify-string.vue')['default']
SpanCopyable: typeof import('./src/components/SpanCopyable.vue')['default']
SqlPrettify: typeof import('./src/tools/sql-prettify/sql-prettify.vue')['default']
+2 -2
View File
@@ -9,7 +9,7 @@ const useWebServer = process.env.NO_WEB_SERVER !== 'true';
*/
export default defineConfig({
testDir: './src',
testMatch: /\.e2e\.(spec\.)?ts$/,
testMatch: /.*\.e2e\.(spec\.)?ts/,
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
@@ -57,7 +57,7 @@ export default defineConfig({
&& {
webServer: {
command: 'npm run preview',
url: 'http://localhost:5050',
url: 'http://127.0.0.1:5050',
reuseExistingServer: !isCI,
},
}
+1 -1
View File
@@ -28,7 +28,7 @@ const compareMatch = computed(() => compareSync(compareString.value, compareHash
mb-2
/>
<n-form-item label="Salt count: " label-placement="left" label-width="120">
<n-input-number v-model:value="saltCount" placeholder="Salt rounds..." :max="100" :min="0" w-full />
<n-input-number v-model:value="saltCount" placeholder="Salt rounds..." :max="10" :min="0" w-full />
</n-form-item>
<c-input-text :value="hashed" readonly text-center />
+26 -99
View File
@@ -6,11 +6,9 @@ import cmykPlugin from 'colord/plugins/cmyk';
import hwbPlugin from 'colord/plugins/hwb';
import namesPlugin from 'colord/plugins/names';
import lchPlugin from 'colord/plugins/lch';
import xyzPlugin from 'colord/plugins/xyz';
import labPlugin from 'colord/plugins/lab';
import { buildColorFormat } from './color-converter.models';
extend([cmykPlugin, hwbPlugin, namesPlugin, lchPlugin, xyzPlugin, labPlugin]);
extend([cmykPlugin, hwbPlugin, namesPlugin, lchPlugin]);
const formats = {
picker: buildColorFormat({
@@ -48,18 +46,6 @@ const formats = {
format: (v: Colord) => v.toCmykString(),
placeholder: 'e.g. cmyk(0, 100%, 100%, 0)',
}),
lab: buildColorFormat({
label: 'lab',
format: (v: Colord) => JSON.stringify(v.toLab()),
placeholder: 'e.g. { l: 14.89, a: 5.77, b: 14.41, alpha: 0.5 }',
parse: value => colord(JSON.parse(value)),
}),
xyz: buildColorFormat({
label: 'xyz',
format: (v: Colord) => JSON.stringify(v.toXyz()),
placeholder: 'e.g. { x: 95.047, y: 100, z: 108.883, a: 1 }',
parse: value => colord(JSON.parse(value)),
}),
name: buildColorFormat({
label: 'name',
format: (v: Colord) => v.toName({ closest: true }) ?? 'Unknown',
@@ -67,17 +53,7 @@ const formats = {
}),
};
const saturation = ref(0);
const brightness = ref(0);
const grayscale = ref(false);
const invert = ref(false);
let lastColor = colord('#1ea54c');
watch([saturation, brightness, grayscale, invert],
() => updateColorValue(lastColor),
);
updateColorValue(lastColor);
updateColorValue(colord('#1ea54c'));
function updateColorValue(value: Colord | undefined, omitLabel?: string) {
if (value === undefined) {
@@ -88,89 +64,40 @@ function updateColorValue(value: Colord | undefined, omitLabel?: string) {
return;
}
lastColor = value;
let correctedValue = value;
if (grayscale.value) {
correctedValue = correctedValue.grayscale();
}
if (invert.value) {
correctedValue = correctedValue.invert();
}
const saturationFloat = saturation.value / 100.0;
if (saturationFloat > 0) {
correctedValue = correctedValue.saturate(saturationFloat);
}
else if (saturationFloat < 0) {
correctedValue = correctedValue.desaturate(-saturationFloat);
}
const brightnessFloat = brightness.value / 100.0;
if (brightnessFloat > 0) {
correctedValue = correctedValue.lighten(brightnessFloat);
}
else if (brightnessFloat < 0) {
correctedValue = correctedValue.darken(-brightnessFloat);
}
_.forEach(formats, ({ value: valueRef, format }, key) => {
if (key !== omitLabel) {
valueRef.value = format(correctedValue);
valueRef.value = format(value);
}
});
}
</script>
<template>
<div>
<c-card title="Transformations">
<n-form-item label="Saturation" label-placement="left">
<n-slider v-model:value="saturation" :step="1" :min="-100" :max="100" mr-2 />
<n-input-number v-model:value="saturation" size="small" />
</n-form-item>
<c-card>
<template v-for="({ label, parse, placeholder, validation, type }, key) in formats" :key="key">
<input-copyable
v-if="type === 'text'"
v-model:value="formats[key].value.value"
:test-id="`input-${key}`"
:label="`${label}:`"
label-position="left"
label-width="100px"
label-align="right"
:placeholder="placeholder"
:validation="validation"
raw-text
clearable
mt-2
@update:value="(v:string) => updateColorValue(parse(v), key)"
/>
<n-form-item label="Brightness" label-placement="left">
<n-slider v-model:value="brightness" :step="1" :min="-100" :max="100" mr-2 />
<n-input-number v-model:value="brightness" size="small" />
</n-form-item>
<n-space>
<n-form-item label="Grayscale" label-placement="left">
<n-checkbox v-model:checked="grayscale" mr-2 />
</n-form-item>
<n-form-item label="Invert" label-placement="left">
<n-checkbox v-model:checked="invert" mr-2 />
</n-form-item>
</n-space>
</c-card>
<c-card>
<template v-for="({ label, parse, placeholder, validation, type }, key) in formats" :key="key">
<input-copyable
v-if="type === 'text'"
<n-form-item v-else-if="type === 'color-picker'" :label="`${label}:`" label-width="100" label-placement="left" :show-feedback="false">
<n-color-picker
v-model:value="formats[key].value.value"
:test-id="`input-${key}`"
:label="`${label}:`"
label-position="left"
label-width="100px"
label-align="right"
:placeholder="placeholder"
:validation="validation"
raw-text
clearable
mt-2
placement="bottom-end"
@update:value="(v:string) => updateColorValue(parse(v), key)"
/>
<n-form-item v-else-if="type === 'color-picker'" :label="`${label}:`" label-width="100" label-placement="left" :show-feedback="false">
<n-color-picker
v-model:value="formats[key].value.value"
placement="bottom-end"
@update:value="(v:string) => updateColorValue(parse(v), key)"
/>
</n-form-item>
</template>
</c-card>
</div>
</n-form-item>
</template>
</c-card>
</template>
+2
View File
@@ -6,6 +6,7 @@ import { tool as asciiTextDrawer } from './ascii-text-drawer';
import { tool as textToUnicode } from './text-to-unicode';
import { tool as safelinkDecoder } from './safelink-decoder';
import { tool as utmUrlGenerator } from './utm-url-generator';
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
import { tool as numeronymGenerator } from './numeronym-generator';
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -115,6 +116,7 @@ export const toolsByCategory: ToolCategory[] = [
urlEncoder,
htmlEntities,
urlParser,
utmUrlGenerator,
deviceInformation,
basicAuthGenerator,
metaTagGenerator,
@@ -11,9 +11,6 @@ describe('integer-base-converter', () => {
expect(convertBase({ value: '10100101', fromBase: 2, toBase: 16 })).toEqual('a5');
expect(convertBase({ value: '192654', fromBase: 10, toBase: 8 })).toEqual('570216');
expect(convertBase({ value: 'zz', fromBase: 64, toBase: 10 })).toEqual('2275');
expect(convertBase({ value: '42540766411283223938465490632011909384', fromBase: 10, toBase: 10 })).toEqual('42540766411283223938465490632011909384');
expect(convertBase({ value: '42540766411283223938465490632011909384', fromBase: 10, toBase: 16 })).toEqual('20010db8000085a300000000ac1f8908');
expect(convertBase({ value: '20010db8000085a300000000ac1f8908', fromBase: 16, toBase: 10 })).toEqual('42540766411283223938465490632011909384');
});
});
});
@@ -5,16 +5,16 @@ export function convertBase({ value, fromBase, toBase }: { value: string; fromBa
let decValue = value
.split('')
.reverse()
.reduce((carry: bigint, digit: string, index: number) => {
.reduce((carry: number, digit: string, index: number) => {
if (!fromRange.includes(digit)) {
throw new Error(`Invalid digit "${digit}" for base ${fromBase}.`);
}
return (carry += BigInt(fromRange.indexOf(digit)) * BigInt(fromBase) ** BigInt(index));
}, 0n);
return (carry += fromRange.indexOf(digit) * fromBase ** index);
}, 0);
let newValue = '';
while (decValue > 0) {
newValue = toRange[Number(decValue % BigInt(toBase))] + newValue;
decValue = (decValue - (decValue % BigInt(toBase))) / BigInt(toBase);
newValue = toRange[decValue % toBase] + newValue;
decValue = (decValue - (decValue % toBase)) / toBase;
}
return newValue || '0';
}
+12
View File
@@ -0,0 +1,12 @@
import { Ad } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'UTM Url Generator',
path: '/utm-url-generator',
description: 'Generate an URL with utm_ parameters',
keywords: ['utm', 'url', 'generator'],
component: () => import('./utm-url-generator.vue'),
icon: Ad,
createdAt: new Date('2024-03-15'),
});
@@ -0,0 +1,147 @@
<script setup lang="ts">
import { useCopy } from '@/composable/copy';
import { useValidation } from '@/composable/validation';
const url = useStorage('utm-generator:url', '');
const utmSource = useStorage('utm-generator:source', '');
const utmMedium = useStorage('utm-generator:medium', '');
const utmCampaign = useStorage('utm-generator:campaign', '');
const utmContent = useStorage('utm-generator:content', '');
const utmTerm = useStorage('utm-generator:term', '');
const utmifiedUrl = computed(() => {
try {
const utmUrl = new URL(url.value);
utmUrl.searchParams.set('utm_source', utmSource.value);
utmUrl.searchParams.set('utm_medium', utmMedium.value);
utmUrl.searchParams.set('utm_campaign', utmCampaign.value);
if (utmContent.value) {
utmUrl.searchParams.set('utm_content', utmContent.value);
}
if (utmContent.value) {
utmUrl.searchParams.set('utm_term', utmTerm.value);
}
return utmUrl.href;
}
catch {
return '# invalid inputs';
}
});
const urlValidation = useValidation({
source: url,
rules: [
{
message: 'Invalid url string',
validator: (value) => {
try {
const _ = (new URL(value));
return true;
}
catch {
return false;
}
},
},
],
});
const utmMediumValidation = useValidation({
source: utmMedium,
rules: [
{
message: 'UTM Medium is required',
validator: value => value !== '',
},
],
});
const utmSourceValidation = useValidation({
source: utmSource,
rules: [
{
message: 'UTM Source is required',
validator: value => value !== '',
},
],
});
const utmCampaignValidation = useValidation({
source: utmCampaign,
rules: [
{
message: 'UTM Campaign is required',
validator: value => value !== '',
},
],
});
const { copy } = useCopy({ source: utmifiedUrl, text: 'UTMified url copied.' });
</script>
<template>
<div>
<n-p>
For more info about UTM, see <n-a href="https://en.wikipedia.org/wiki/UTM_parameters" target="_blank" rel="noopener noreferrer">
UTM Parameters
</n-a>
</n-p>
<c-input-text
v-model:value="url"
label="Website url"
placeholder="Put your website url here..."
clearable
mb-2
:validation="urlValidation"
/>
<c-input-text
v-model:value="utmSource"
label="UTM Source (Identifies which site sent the traffic)"
placeholder="Put your UTM Source here..."
clearable
mb-2
:validation="utmSourceValidation"
/>
<c-input-text
v-model:value="utmMedium"
label="UTM Medium (Identifies what type of link was used)"
placeholder="Put your UTM Medium here..."
clearable
mb-2
:validation="utmMediumValidation"
/>
<c-input-text
v-model:value="utmCampaign"
label="UTM Campaign (Identifies a specific product promotion or strategic campaign)"
placeholder="Put your UTM Campaign here..."
clearable
mb-2
:validation="utmCampaignValidation"
/>
<c-input-text
v-model:value="utmContent"
label="UTM Content (Identifies search terms)"
placeholder="Put your UTM Content here..."
clearable
mb-2
/>
<c-input-text
v-model:value="utmTerm"
label="UTM Term (Identifies what specifically was clicked to bring the user to the site)"
placeholder="Put your UTM Term here..."
clearable
mb-2
/>
<div v-if="utmifiedUrl">
<div mb-2>
Your url with UTM parameters added
</div>
<c-card>
{{ utmifiedUrl }}
</c-card>
<div mt-3 flex justify-center>
<c-button autofocus @click="copy()">
Copy url
</c-button>
</div>
</div>
</div>
</template>