2023-05-28 23:13:24 +02:00
|
|
|
<script setup lang="ts">
|
2023-11-13 22:38:01 +01:00
|
|
|
import { v1 as generateUuidV1, v3 as generateUuidV3, v4 as generateUuidV4, v5 as generateUuidV5, NIL as nilUuid } from 'uuid';
|
2023-05-28 23:13:24 +02:00
|
|
|
import { useCopy } from '@/composable/copy';
|
|
|
|
import { computedRefreshable } from '@/composable/computedRefreshable';
|
2023-11-13 22:38:01 +01:00
|
|
|
import { withDefaultOnError } from '@/utils/defaults';
|
2023-05-28 23:13:24 +02:00
|
|
|
|
2023-11-13 22:38:01 +01:00
|
|
|
const versions = ['NIL', 'v1', 'v3', 'v4', 'v5'] as const;
|
|
|
|
|
|
|
|
const version = useStorage<typeof versions[number]>('uuid-generator:version', 'v4');
|
2023-05-28 23:13:24 +02:00
|
|
|
const count = useStorage('uuid-generator:quantity', 1);
|
2023-11-13 22:38:01 +01:00
|
|
|
const v35Args = ref({ namespace: '6ba7b811-9dad-11d1-80b4-00c04fd430c8', name: '' });
|
|
|
|
|
|
|
|
const validUuidRules = [
|
|
|
|
{
|
|
|
|
message: 'Invalid UUID',
|
|
|
|
validator: (value: string) => {
|
|
|
|
if (value === nilUuid) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Boolean(value.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const generators = {
|
|
|
|
NIL: () => nilUuid,
|
|
|
|
v1: (index: number) => generateUuidV1({
|
|
|
|
clockseq: index,
|
|
|
|
msecs: Date.now(),
|
|
|
|
nsecs: Math.floor(Math.random() * 10000),
|
|
|
|
node: Array.from({ length: 6 }, () => Math.floor(Math.random() * 256)),
|
|
|
|
}),
|
|
|
|
v3: () => generateUuidV3(v35Args.value.name, v35Args.value.namespace),
|
|
|
|
v4: () => generateUuidV4(),
|
|
|
|
v5: () => generateUuidV5(v35Args.value.name, v35Args.value.namespace),
|
|
|
|
};
|
2023-05-28 23:13:24 +02:00
|
|
|
|
2023-11-13 22:38:01 +01:00
|
|
|
const [uuids, refreshUUIDs] = computedRefreshable(() => withDefaultOnError(() =>
|
|
|
|
Array.from({ length: count.value }, (_ignored, index) => {
|
|
|
|
const generator = generators[version.value] ?? generators.NIL;
|
|
|
|
return generator(index);
|
|
|
|
}).join('\n'), ''));
|
2023-05-28 23:13:24 +02:00
|
|
|
|
|
|
|
const { copy } = useCopy({ source: uuids, text: 'UUIDs copied to the clipboard' });
|
|
|
|
</script>
|
|
|
|
|
2022-04-04 21:46:35 +02:00
|
|
|
<template>
|
2023-05-27 17:36:15 +02:00
|
|
|
<div>
|
2023-11-13 22:38:01 +01:00
|
|
|
<c-buttons-select v-model:value="version" :options="versions" label="UUID version" label-width="100px" mb-2 />
|
|
|
|
|
|
|
|
<div mb-2 flex items-center>
|
|
|
|
<span w-100px>Quantity </span>
|
|
|
|
<n-input-number v-model:value="count" flex-1 :min="1" :max="50" placeholder="UUID quantity" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-if="version === 'v3' || version === 'v5'">
|
|
|
|
<div>
|
|
|
|
<c-buttons-select
|
|
|
|
v-model:value="v35Args.namespace"
|
|
|
|
:options="{
|
|
|
|
DNS: '6ba7b810-9dad-11d1-80b4-00c04fd430c8',
|
|
|
|
URL: '6ba7b811-9dad-11d1-80b4-00c04fd430c8',
|
|
|
|
OID: '6ba7b812-9dad-11d1-80b4-00c04fd430c8',
|
|
|
|
X500: '6ba7b814-9dad-11d1-80b4-00c04fd430c8',
|
|
|
|
}"
|
|
|
|
label="Namespace"
|
|
|
|
label-width="100px"
|
|
|
|
mb-2
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div flex-1>
|
|
|
|
<c-input-text
|
|
|
|
v-model:value="v35Args.namespace"
|
|
|
|
placeholder="Namespace"
|
|
|
|
label-width="100px"
|
|
|
|
label-position="left"
|
|
|
|
label=" "
|
|
|
|
:validation-rules="validUuidRules"
|
|
|
|
mb-2
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<c-input-text
|
|
|
|
v-model:value="v35Args.name"
|
|
|
|
placeholder="Name"
|
|
|
|
label="Name"
|
|
|
|
label-width="100px"
|
|
|
|
label-position="left"
|
|
|
|
mb-2
|
|
|
|
/>
|
2023-05-27 17:36:15 +02:00
|
|
|
</div>
|
2023-04-13 23:30:33 +02:00
|
|
|
|
2023-06-25 15:00:50 +02:00
|
|
|
<c-input-text
|
2023-04-13 23:30:33 +02:00
|
|
|
style="text-align: center; font-family: monospace"
|
|
|
|
:value="uuids"
|
2023-06-25 15:00:50 +02:00
|
|
|
multiline
|
2023-04-13 23:30:33 +02:00
|
|
|
placeholder="Your uuids"
|
2024-05-11 01:14:04 -04:00
|
|
|
:rows="count"
|
2023-04-13 23:30:33 +02:00
|
|
|
readonly
|
2023-06-25 15:00:50 +02:00
|
|
|
raw-text
|
|
|
|
monospace
|
2023-05-27 17:36:15 +02:00
|
|
|
my-3
|
2023-06-25 15:00:50 +02:00
|
|
|
class="uuid-display"
|
2023-04-13 23:30:33 +02:00
|
|
|
/>
|
|
|
|
|
2023-05-27 17:36:15 +02:00
|
|
|
<div flex justify-center gap-3>
|
2023-08-22 01:00:20 +02:00
|
|
|
<c-button autofocus @click="copy()">
|
2023-05-28 23:13:24 +02:00
|
|
|
Copy
|
|
|
|
</c-button>
|
|
|
|
<c-button @click="refreshUUIDs">
|
|
|
|
Refresh
|
|
|
|
</c-button>
|
2023-05-27 17:36:15 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-04 21:46:35 +02:00
|
|
|
</template>
|
2023-06-25 15:00:50 +02:00
|
|
|
|
|
|
|
<style scoped lang="less">
|
|
|
|
::v-deep(.uuid-display) {
|
|
|
|
textarea {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|