mirror of
https://github.com/sharevb/it-tools.git
synced 2026-12-03 01:59:08 +03:00
Merge branch 'up/feat/nanoid-generator' into chore/all-my-stuffs
This commit is contained in:
commit
95708f1ca7
7 files changed
+251
-4
No files matched your search
@@ -107,6 +107,7 @@ import { tool as torrentToMagnet } from './torrent-to-magnet';
|
||||
import { tool as ttlCalculator } from './ttl-calculator';
|
||||
import { tool as unicodeFormatter } from './unicode-formatter';
|
||||
import { tool as raidCalculator } from './raid-calculator';
|
||||
import { tool as nanoidGenerator } from './nanoid-generator';
|
||||
|
||||
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
||||
|
||||
@@ -245,6 +246,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
bcrypt,
|
||||
uuidGenerator,
|
||||
ulidGenerator,
|
||||
nanoidGenerator,
|
||||
cypher,
|
||||
bip39,
|
||||
hmacGenerator,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Fingerprint } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.nanoid-generator.title'),
|
||||
path: '/nanoid-generator',
|
||||
description: translate('tools.nanoid-generator.description'),
|
||||
keywords: ['nanoid', 'generator'],
|
||||
component: () => import('./nanoid-generator.vue'),
|
||||
icon: Fingerprint,
|
||||
createdAt: new Date('2024-05-31'),
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
import { customAlphabet, nanoid } from 'nanoid';
|
||||
import { lowercase, nolookalikes, numbers, uppercase } from 'nanoid-dictionary';
|
||||
|
||||
const symbols = '-_';
|
||||
|
||||
export function createNanoid({
|
||||
length = 21,
|
||||
withLowercase = true,
|
||||
withUppercase = true,
|
||||
withNumbers = true,
|
||||
withSymbols = true,
|
||||
excludeLookalikes = false,
|
||||
}: {
|
||||
length?: number
|
||||
withLowercase?: boolean
|
||||
withUppercase?: boolean
|
||||
withNumbers?: boolean
|
||||
withSymbols?: boolean
|
||||
excludeLookalikes?: boolean
|
||||
}) {
|
||||
let alphabet = '';
|
||||
|
||||
if (!withLowercase && !withUppercase && !withNumbers && !excludeLookalikes && !withSymbols) {
|
||||
return nanoid(length);
|
||||
}
|
||||
|
||||
if (excludeLookalikes) {
|
||||
alphabet = [nolookalikes, withSymbols ? symbols : ''].join('');
|
||||
}
|
||||
|
||||
alphabet = [
|
||||
withLowercase ? lowercase : '',
|
||||
withUppercase ? uppercase : '',
|
||||
withNumbers ? numbers : '',
|
||||
withSymbols ? symbols : '',
|
||||
].join('');
|
||||
|
||||
return customAlphabet(alphabet, length);
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
<script setup lang="ts">
|
||||
import { InfoCircle } from '@vicons/tabler';
|
||||
import { createNanoid } from './nanoid-generator.service';
|
||||
import { computedRefreshable } from '@/composable/computedRefreshable';
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { useQueryParam } from '@/composable/queryParams';
|
||||
|
||||
const count = useQueryParam({ name: 'count', defaultValue: 1 });
|
||||
const length = useQueryParam({ name: 'length', defaultValue: 21 });
|
||||
const withUppercase = useQueryParam({ name: 'uppercase', defaultValue: true });
|
||||
const withLowercase = useQueryParam({ name: 'lowercase', defaultValue: true });
|
||||
const withNumbers = useQueryParam({ name: 'numbers', defaultValue: true });
|
||||
const withSymbols = useQueryParam({ name: 'symbols', defaultValue: true });
|
||||
const excludeLookalikes = useQueryParam({ name: 'no-lookalikes', defaultValue: false });
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const [nanoIds, refreshNanoIds] = computedRefreshable(() =>
|
||||
withDefaultOnError(
|
||||
() =>
|
||||
Array.from({ length: count.value }, (_ignored) => {
|
||||
const nanoId = createNanoid({
|
||||
length: length.value,
|
||||
withUppercase: withUppercase.value,
|
||||
withLowercase: withLowercase.value,
|
||||
withNumbers: withNumbers.value,
|
||||
withSymbols: withSymbols.value,
|
||||
excludeLookalikes: excludeLookalikes.value,
|
||||
});
|
||||
|
||||
return nanoId();
|
||||
}).join('\n'),
|
||||
'',
|
||||
),
|
||||
);
|
||||
|
||||
const { copy } = useCopy({ source: nanoIds, text: 'NanoIds copied to the clipboard' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<n-form label-placement="left" label-width="140">
|
||||
<div mb-8 flex justify-center gap-8>
|
||||
<div class="column">
|
||||
<div>
|
||||
<n-text>{{ t('tools.nanoid-generator.uppercase') }}</n-text>
|
||||
<c-tooltip
|
||||
tooltip="ABCDEFGHIJKLMNOPQRSTUVWXYZ" position="bottom"
|
||||
>
|
||||
<n-icon size="20" :component="InfoCircle" />
|
||||
</c-tooltip>
|
||||
<n-switch v-model:value="withUppercase" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<n-text>{{ t('tools.nanoid-generator.lowercase') }}</n-text>
|
||||
<c-tooltip
|
||||
tooltip="abcdefghijklmnopqrstuvwxyz" position="bottom"
|
||||
>
|
||||
<n-icon size="20" :component="InfoCircle" />
|
||||
</c-tooltip>
|
||||
<n-switch v-model:value="withLowercase" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="column">
|
||||
<div>
|
||||
<n-text>
|
||||
{{ t('tools.nanoid-generator.numbers') }}
|
||||
</n-text>
|
||||
<c-tooltip
|
||||
tooltip="0123456789" position="bottom"
|
||||
>
|
||||
<n-icon size="20" :component="InfoCircle" />
|
||||
</c-tooltip>
|
||||
<n-switch v-model:value="withNumbers" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<n-text>
|
||||
{{ t('tools.nanoid-generator.symbols') }}
|
||||
</n-text>
|
||||
<c-tooltip
|
||||
tooltip="-_" position="bottom"
|
||||
>
|
||||
<n-icon size="20" :component="InfoCircle" />
|
||||
</c-tooltip>
|
||||
<n-switch v-model:value="withSymbols" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div>
|
||||
<n-text>
|
||||
{{ t('tools.nanoid-generator.excludeLookalikes') }}
|
||||
</n-text>
|
||||
<c-tooltip
|
||||
tooltip="1lI0Oouv5Ss2Z" position="bottom"
|
||||
>
|
||||
<n-icon size="20" :component="InfoCircle" />
|
||||
</c-tooltip>
|
||||
<n-switch v-model:value="excludeLookalikes" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</n-form>
|
||||
|
||||
<div mb-2 flex items-center>
|
||||
<span w-100px>{{ t('tools.nanoid-generator.length') }}</span>
|
||||
<n-input-number v-model:value="length" flex-1 :min="1" :max="100" placeholder="NanoId Length" />
|
||||
</div>
|
||||
<div mb-2 flex items-center>
|
||||
<span w-100px>{{ t('tools.nanoid-generator.quantity') }}</span>
|
||||
<n-input-number v-model:value="count" flex-1 :min="1" :max="50" placeholder="NanoIds quantity" />
|
||||
</div>
|
||||
|
||||
<c-input-text
|
||||
style="text-align: center; font-family: monospace"
|
||||
:value="nanoIds"
|
||||
placeholder="Your uuids"
|
||||
rows="1"
|
||||
autosize
|
||||
readonly
|
||||
raw-text
|
||||
multiline
|
||||
monospace
|
||||
my-3
|
||||
class="uuid-display"
|
||||
/>
|
||||
|
||||
<div flex justify-center gap-3>
|
||||
<c-button autofocus @click="copy()">
|
||||
{{ t('tools.nanoid-generator.button.copy') }}
|
||||
</c-button>
|
||||
<c-button @click="refreshNanoIds">
|
||||
{{ t('tools.nanoid-generator.button.refresh') }}
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
.n-icon {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.n-text {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user