mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-22 22:02:38 +03:00
Merge branch 'up/feat/uuid-converter' into chore/all-my-stuffs
This commit is contained in:
commit
bdc5966a4c
9 files changed
+15138
No files matched your search
Generated
+14956
File diff suppressed because it is too large.
Load diff
@@ -140,6 +140,7 @@ import { tool as cssPrettifier } from './css-prettifier';
|
|||||||
import { tool as htmlPrettifier } from './html-prettifier';
|
import { tool as htmlPrettifier } from './html-prettifier';
|
||||||
import { tool as x509CertificateGenerator } from './x509-certificate-generator';
|
import { tool as x509CertificateGenerator } from './x509-certificate-generator';
|
||||||
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
||||||
|
import { tool as uuidConverter } from './uuid-converter';
|
||||||
import { tool as numeronymGenerator } from './numeronym-generator';
|
import { tool as numeronymGenerator } from './numeronym-generator';
|
||||||
import { tool as macAddressGenerator } from './mac-address-generator';
|
import { tool as macAddressGenerator } from './mac-address-generator';
|
||||||
import { tool as textToBinary } from './text-to-binary';
|
import { tool as textToBinary } from './text-to-binary';
|
||||||
@@ -293,6 +294,7 @@ export const toolsByCategory: ToolCategory[] = [
|
|||||||
listComparer,
|
listComparer,
|
||||||
tomlToJson,
|
tomlToJson,
|
||||||
tomlToYaml,
|
tomlToYaml,
|
||||||
|
uuidConverter,
|
||||||
htmlToMarkdown,
|
htmlToMarkdown,
|
||||||
markdownToHtml,
|
markdownToHtml,
|
||||||
currencyConverter,
|
currencyConverter,
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { Replace } from '@vicons/tabler';
|
||||||
|
import { defineTool } from '../tool';
|
||||||
|
import { translate } from '@/plugins/i18n.plugin';
|
||||||
|
|
||||||
|
export const tool = defineTool({
|
||||||
|
name: translate('tools.uuid-converter.title'),
|
||||||
|
path: '/uuid-converter',
|
||||||
|
description: translate('tools.uuid-converter.description'),
|
||||||
|
keywords: ['uuid', 'converter', 'guid', 'sql'],
|
||||||
|
component: () => import('./uuid-converter.vue'),
|
||||||
|
icon: Replace,
|
||||||
|
createdAt: new Date('2023-11-08'),
|
||||||
|
});
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
tools:
|
||||||
|
uuid-converter:
|
||||||
|
title: UUID converter
|
||||||
|
description: Converts a UUID with and without a hyphen to other common SQL notations and back.
|
||||||
|
|
||||||
|
uuid: UUID
|
||||||
|
uuidhexupper: HEX notation (upper)
|
||||||
|
uuidhexlower: HEX notation (lower)
|
||||||
|
uuidversion: RFC Version
|
||||||
|
input:
|
||||||
|
label: Your Input
|
||||||
|
placeholder: Your UUID with/without hyphen
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
tools:
|
||||||
|
uuid-converter:
|
||||||
|
title: Convertisseur UUID
|
||||||
|
description: Convertit un UUID avec et sans trait d'union en d'autres notations SQL courantes et inversement.
|
||||||
|
|
||||||
|
uuid: UUID
|
||||||
|
uuidhexupper: Notation HEX (supérieure)
|
||||||
|
uuidhexlower: Notation HEX (inférieure)
|
||||||
|
uuidversion: Version RFC
|
||||||
|
input:
|
||||||
|
label: Votre contribution
|
||||||
|
placeholder: Votre UUID avec/sans trait d'union
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { expect, test } from '@playwright/test';
|
||||||
|
|
||||||
|
test.describe('Tool - UUID converter', () => {
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
await page.goto('/uuid-converter');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Has correct title', async ({ page }) => {
|
||||||
|
await expect(page).toHaveTitle('UUID converter - IT Tools');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('', async ({ page }) => {
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
import { UUID2HEX, getVersion, normalizeUUID } from './uuid-converter.service';
|
||||||
|
|
||||||
|
const validUuid = '005056a3-e753-1eee-97a1-e5eb141bb52c';
|
||||||
|
const validUuidHex = '005056A3E7531EEE97A1E5EB141BB52C';
|
||||||
|
const inValidUuid = '005056a3-e753-1eee-97a1-e5eb141bb52x';
|
||||||
|
|
||||||
|
describe('uuid-converter', () => {
|
||||||
|
describe('normalizeUUID', () => {
|
||||||
|
it('A valid UUID should be returned without changes', () => {
|
||||||
|
expect(normalizeUUID(validUuid)).toBe(validUuid);
|
||||||
|
});
|
||||||
|
it('An invalid UUID should return an empty string', () => {
|
||||||
|
expect(normalizeUUID(inValidUuid)).toBe('');
|
||||||
|
});
|
||||||
|
it('A packed UUID in hex format should return its valid UUID', () => {
|
||||||
|
expect(normalizeUUID(validUuidHex)).toBe(validUuid);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('UUID2HEX', () => {
|
||||||
|
it('A UUID is converted to upper case hex notation', () => {
|
||||||
|
expect(UUID2HEX(validUuid)).toBe(validUuidHex.toUpperCase());
|
||||||
|
});
|
||||||
|
it('A UUID is converted to lower case hex notation', () => {
|
||||||
|
expect(UUID2HEX(validUuid, false)).toBe(validUuidHex.toLowerCase());
|
||||||
|
});
|
||||||
|
it('An invalid UUID should return an empty string', () => {
|
||||||
|
expect(UUID2HEX(inValidUuid)).toBe('');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getVersion', () => {
|
||||||
|
it('Returns the RFC version of the UUID as string', () => {
|
||||||
|
expect(getVersion(validUuid)).toBe('1');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('An invalid UUID should return an empty string', () => {
|
||||||
|
expect(getVersion(inValidUuid)).toBe('');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { validate as uuidValidate, version as uuidVersion } from 'uuid';
|
||||||
|
|
||||||
|
export { normalizeUUID, UUID2HEX, getVersion };
|
||||||
|
|
||||||
|
function normalizeUUID(value: string) {
|
||||||
|
let uuid = ''; // Default return value
|
||||||
|
const probablyUuid = value.toLowerCase();
|
||||||
|
|
||||||
|
const uuidHexRegEx = /^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/;
|
||||||
|
const isCondensedUuid = uuidHexRegEx.test(probablyUuid);
|
||||||
|
|
||||||
|
if (isCondensedUuid) {
|
||||||
|
uuid = probablyUuid.replace(uuidHexRegEx, '$1-$2-$3-$4-$5');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
uuid = value;
|
||||||
|
};
|
||||||
|
|
||||||
|
return uuidValidate(uuid) ? uuid : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function UUID2HEX(value: string, upper = true) {
|
||||||
|
let result = ''; // Default return value
|
||||||
|
const uuid = normalizeUUID(value);
|
||||||
|
|
||||||
|
if (uuid) {
|
||||||
|
const hex = value.replace(/-/g, '');
|
||||||
|
result = upper ? hex.toUpperCase() : hex.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getVersion(value: string) {
|
||||||
|
const uuid = normalizeUUID(value);
|
||||||
|
|
||||||
|
return uuid ? uuidVersion(uuid).toString() : '';
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import InputCopyable from '../../components/InputCopyable.vue';
|
||||||
|
import { UUID2HEX, getVersion, normalizeUUID } from './uuid-converter.service';
|
||||||
|
|
||||||
|
const { t } = useI18n();
|
||||||
|
const input = ref('');
|
||||||
|
|
||||||
|
const formats = computed(() => [
|
||||||
|
{
|
||||||
|
label: t('tools.uuid-converter.uuid'),
|
||||||
|
value: normalizeUUID(input.value),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('tools.uuid-converter.uuidhexupper'),
|
||||||
|
value: UUID2HEX(input.value, true),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('tools.uuid-converter.uuidhexlower'),
|
||||||
|
value: UUID2HEX(input.value, false),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('tools.uuid-converter.uuidversion'),
|
||||||
|
value: getVersion(input.value).toString(),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const inputLabelAlignmentConfig = {
|
||||||
|
labelPosition: 'left',
|
||||||
|
labelWidth: '120px',
|
||||||
|
labelAlign: 'right',
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<c-card>
|
||||||
|
<c-input-text
|
||||||
|
v-model:value="input"
|
||||||
|
autofocus :label="t('tools.uuid-converter.input.label')" :placeholder="t('tools.uuid-converter.input.placeholder')" raw-text
|
||||||
|
v-bind="inputLabelAlignmentConfig"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div my-16px divider />
|
||||||
|
|
||||||
|
<InputCopyable
|
||||||
|
v-for="format in formats" :key="format.label" :value="format.value" :label="format.label"
|
||||||
|
:readonly="true" v-bind="inputLabelAlignmentConfig" mb-1
|
||||||
|
/>
|
||||||
|
</c-card>
|
||||||
|
</template>
|
||||||
Reference in new issue
Block a user