mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-09 07:35:01 -04:00
feat: ✨ Add tool uuid-converter
This commit is contained in:
parent
093ff311fd
commit
94eb67b4ab
12 changed files with 15155 additions and 17 deletions
|
@ -1,6 +1,7 @@
|
|||
import { tool as base64FileConverter } from './base64-file-converter';
|
||||
import { tool as base64StringConverter } from './base64-string-converter';
|
||||
import { tool as basicAuthGenerator } from './basic-auth-generator';
|
||||
import { tool as uuidConverter } from './uuid-converter';
|
||||
import { tool as numeronymGenerator } from './numeronym-generator';
|
||||
import { tool as macAddressGenerator } from './mac-address-generator';
|
||||
import { tool as textToBinary } from './text-to-binary';
|
||||
|
@ -99,6 +100,7 @@ export const toolsByCategory: ToolCategory[] = [
|
|||
listConverter,
|
||||
tomlToJson,
|
||||
tomlToYaml,
|
||||
uuidConverter,
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
13
src/tools/uuid-converter/index.ts
Normal file
13
src/tools/uuid-converter/index.ts
Normal file
|
@ -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'),
|
||||
});
|
12
src/tools/uuid-converter/locales/en.yml
Normal file
12
src/tools/uuid-converter/locales/en.yml
Normal file
|
@ -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
|
12
src/tools/uuid-converter/locales/fr.yml
Normal file
12
src/tools/uuid-converter/locales/fr.yml
Normal file
|
@ -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
|
15
src/tools/uuid-converter/uuid-converter.e2e.spec.ts
Normal file
15
src/tools/uuid-converter/uuid-converter.e2e.spec.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { test, expect } 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 }) => {
|
||||
|
||||
});
|
||||
});
|
41
src/tools/uuid-converter/uuid-converter.service.test.ts
Normal file
41
src/tools/uuid-converter/uuid-converter.service.test.ts
Normal file
|
@ -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('');
|
||||
});
|
||||
});
|
38
src/tools/uuid-converter/uuid-converter.service.ts
Normal file
38
src/tools/uuid-converter/uuid-converter.service.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
import { parse as uuidParse, 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() : '';
|
||||
}
|
49
src/tools/uuid-converter/uuid-converter.vue
Normal file
49
src/tools/uuid-converter/uuid-converter.vue
Normal file
|
@ -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>
|
Loading…
Add table
Add a link
Reference in a new issue