Skip to content

Commit bdc5966

Browse files
committed
Merge branch 'up/feat/uuid-converter' into chore/all-my-stuffs
2 parents 95708f1 + 6f64dc4 commit bdc5966

File tree

9 files changed

+15138
-0
lines changed

9 files changed

+15138
-0
lines changed

package-lock.json

Lines changed: 14956 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ import { tool as cssPrettifier } from './css-prettifier';
140140
import { tool as htmlPrettifier } from './html-prettifier';
141141
import { tool as x509CertificateGenerator } from './x509-certificate-generator';
142142
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
143+
import { tool as uuidConverter } from './uuid-converter';
143144
import { tool as numeronymGenerator } from './numeronym-generator';
144145
import { tool as macAddressGenerator } from './mac-address-generator';
145146
import { tool as textToBinary } from './text-to-binary';
@@ -293,6 +294,7 @@ export const toolsByCategory: ToolCategory[] = [
293294
listComparer,
294295
tomlToJson,
295296
tomlToYaml,
297+
uuidConverter,
296298
htmlToMarkdown,
297299
markdownToHtml,
298300
currencyConverter,

src/tools/uuid-converter/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Replace } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
import { translate } from '@/plugins/i18n.plugin';
4+
5+
export const tool = defineTool({
6+
name: translate('tools.uuid-converter.title'),
7+
path: '/uuid-converter',
8+
description: translate('tools.uuid-converter.description'),
9+
keywords: ['uuid', 'converter', 'guid', 'sql'],
10+
component: () => import('./uuid-converter.vue'),
11+
icon: Replace,
12+
createdAt: new Date('2023-11-08'),
13+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
tools:
2+
uuid-converter:
3+
title: UUID converter
4+
description: Converts a UUID with and without a hyphen to other common SQL notations and back.
5+
6+
uuid: UUID
7+
uuidhexupper: HEX notation (upper)
8+
uuidhexlower: HEX notation (lower)
9+
uuidversion: RFC Version
10+
input:
11+
label: Your Input
12+
placeholder: Your UUID with/without hyphen
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
tools:
2+
uuid-converter:
3+
title: Convertisseur UUID
4+
description: Convertit un UUID avec et sans trait d'union en d'autres notations SQL courantes et inversement.
5+
6+
uuid: UUID
7+
uuidhexupper: Notation HEX (supérieure)
8+
uuidhexlower: Notation HEX (inférieure)
9+
uuidversion: Version RFC
10+
input:
11+
label: Votre contribution
12+
placeholder: Votre UUID avec/sans trait d'union
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { expect, test } from '@playwright/test';
2+
3+
test.describe('Tool - UUID converter', () => {
4+
test.beforeEach(async ({ page }) => {
5+
await page.goto('/uuid-converter');
6+
});
7+
8+
test('Has correct title', async ({ page }) => {
9+
await expect(page).toHaveTitle('UUID converter - IT Tools');
10+
});
11+
12+
test('', async ({ page }) => {
13+
14+
});
15+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { UUID2HEX, getVersion, normalizeUUID } from './uuid-converter.service';
3+
4+
const validUuid = '005056a3-e753-1eee-97a1-e5eb141bb52c';
5+
const validUuidHex = '005056A3E7531EEE97A1E5EB141BB52C';
6+
const inValidUuid = '005056a3-e753-1eee-97a1-e5eb141bb52x';
7+
8+
describe('uuid-converter', () => {
9+
describe('normalizeUUID', () => {
10+
it('A valid UUID should be returned without changes', () => {
11+
expect(normalizeUUID(validUuid)).toBe(validUuid);
12+
});
13+
it('An invalid UUID should return an empty string', () => {
14+
expect(normalizeUUID(inValidUuid)).toBe('');
15+
});
16+
it('A packed UUID in hex format should return its valid UUID', () => {
17+
expect(normalizeUUID(validUuidHex)).toBe(validUuid);
18+
});
19+
});
20+
21+
describe('UUID2HEX', () => {
22+
it('A UUID is converted to upper case hex notation', () => {
23+
expect(UUID2HEX(validUuid)).toBe(validUuidHex.toUpperCase());
24+
});
25+
it('A UUID is converted to lower case hex notation', () => {
26+
expect(UUID2HEX(validUuid, false)).toBe(validUuidHex.toLowerCase());
27+
});
28+
it('An invalid UUID should return an empty string', () => {
29+
expect(UUID2HEX(inValidUuid)).toBe('');
30+
});
31+
});
32+
33+
describe('getVersion', () => {
34+
it('Returns the RFC version of the UUID as string', () => {
35+
expect(getVersion(validUuid)).toBe('1');
36+
});
37+
});
38+
it('An invalid UUID should return an empty string', () => {
39+
expect(getVersion(inValidUuid)).toBe('');
40+
});
41+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { validate as uuidValidate, version as uuidVersion } from 'uuid';
2+
3+
export { normalizeUUID, UUID2HEX, getVersion };
4+
5+
function normalizeUUID(value: string) {
6+
let uuid = ''; // Default return value
7+
const probablyUuid = value.toLowerCase();
8+
9+
const uuidHexRegEx = /^([0-9a-f]{8})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{12})$/;
10+
const isCondensedUuid = uuidHexRegEx.test(probablyUuid);
11+
12+
if (isCondensedUuid) {
13+
uuid = probablyUuid.replace(uuidHexRegEx, '$1-$2-$3-$4-$5');
14+
}
15+
else {
16+
uuid = value;
17+
};
18+
19+
return uuidValidate(uuid) ? uuid : '';
20+
}
21+
22+
function UUID2HEX(value: string, upper = true) {
23+
let result = ''; // Default return value
24+
const uuid = normalizeUUID(value);
25+
26+
if (uuid) {
27+
const hex = value.replace(/-/g, '');
28+
result = upper ? hex.toUpperCase() : hex.toLowerCase();
29+
}
30+
31+
return result;
32+
}
33+
34+
function getVersion(value: string) {
35+
const uuid = normalizeUUID(value);
36+
37+
return uuid ? uuidVersion(uuid).toString() : '';
38+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<script setup lang="ts">
2+
import InputCopyable from '../../components/InputCopyable.vue';
3+
import { UUID2HEX, getVersion, normalizeUUID } from './uuid-converter.service';
4+
5+
const { t } = useI18n();
6+
const input = ref('');
7+
8+
const formats = computed(() => [
9+
{
10+
label: t('tools.uuid-converter.uuid'),
11+
value: normalizeUUID(input.value),
12+
},
13+
{
14+
label: t('tools.uuid-converter.uuidhexupper'),
15+
value: UUID2HEX(input.value, true),
16+
},
17+
{
18+
label: t('tools.uuid-converter.uuidhexlower'),
19+
value: UUID2HEX(input.value, false),
20+
},
21+
{
22+
label: t('tools.uuid-converter.uuidversion'),
23+
value: getVersion(input.value).toString(),
24+
},
25+
]);
26+
27+
const inputLabelAlignmentConfig = {
28+
labelPosition: 'left',
29+
labelWidth: '120px',
30+
labelAlign: 'right',
31+
};
32+
</script>
33+
34+
<template>
35+
<c-card>
36+
<c-input-text
37+
v-model:value="input"
38+
autofocus :label="t('tools.uuid-converter.input.label')" :placeholder="t('tools.uuid-converter.input.placeholder')" raw-text
39+
v-bind="inputLabelAlignmentConfig"
40+
/>
41+
42+
<div my-16px divider />
43+
44+
<InputCopyable
45+
v-for="format in formats" :key="format.label" :value="format.value" :label="format.label"
46+
:readonly="true" v-bind="inputLabelAlignmentConfig" mb-1
47+
/>
48+
</c-card>
49+
</template>

0 commit comments

Comments
 (0)