+
Skip to content

feat(new tool): ULID generator #623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ declare module '@vue/runtime-core' {
CaseConverter: typeof import('./src/tools/case-converter/case-converter.vue')['default']
CButton: typeof import('./src/ui/c-button/c-button.vue')['default']
'CButton.demo': typeof import('./src/ui/c-button/c-button.demo.vue')['default']
CButtonsSelect: typeof import('./src/ui/c-buttons-select/c-buttons-select.vue')['default']
'CButtonsSelect.demo': typeof import('./src/ui/c-buttons-select/c-buttons-select.demo.vue')['default']
CCard: typeof import('./src/ui/c-card/c-card.vue')['default']
'CCard.demo': typeof import('./src/ui/c-card/c-card.demo.vue')['default']
CDiffEditor: typeof import('./src/ui/c-diff-editor/c-diff-editor.vue')['default']
Expand Down Expand Up @@ -183,6 +185,7 @@ declare module '@vue/runtime-core' {
TomlToYaml: typeof import('./src/tools/toml-to-yaml/toml-to-yaml.vue')['default']
'Tool.layout': typeof import('./src/layouts/tool.layout.vue')['default']
ToolCard: typeof import('./src/components/ToolCard.vue')['default']
UlidGenerator: typeof import('./src/tools/ulid-generator/ulid-generator.vue')['default']
UrlEncoder: typeof import('./src/tools/url-encoder/url-encoder.vue')['default']
UrlParser: typeof import('./src/tools/url-parser/url-parser.vue')['default']
UserAgentParser: typeof import('./src/tools/user-agent-parser/user-agent-parser.vue')['default']
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"randombytes": "^2.1.0",
"sql-formatter": "^13.0.0",
"ua-parser-js": "^1.0.35",
"ulid": "^2.3.0",
"unicode-emoji-json": "^0.4.0",
"unplugin-auto-import": "^0.16.4",
"uuid": "^9.0.0",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/tools/index.ts
Original file line number Diff line number Diff line change
@@ -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 ulidGenerator } from './ulid-generator';
import { tool as ibanValidatorAndParser } from './iban-validator-and-parser';
import { tool as stringObfuscator } from './string-obfuscator';
import { tool as textDiff } from './text-diff';
Expand Down Expand Up @@ -74,7 +75,7 @@ import { tool as xmlFormatter } from './xml-formatter';
export const toolsByCategory: ToolCategory[] = [
{
name: 'Crypto',
components: [tokenGenerator, hashText, bcrypt, uuidGenerator, cypher, bip39, hmacGenerator, rsaKeyPairGenerator, passwordStrengthAnalyser],
components: [tokenGenerator, hashText, bcrypt, uuidGenerator, ulidGenerator, cypher, bip39, hmacGenerator, rsaKeyPairGenerator, passwordStrengthAnalyser],
},
{
name: 'Converter',
Expand Down
12 changes: 12 additions & 0 deletions src/tools/ulid-generator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { SortDescendingNumbers } from '@vicons/tabler';
import { defineTool } from '../tool';

export const tool = defineTool({
name: 'ULID generator',
path: '/ulid-generator',
description: 'Generate random Universally Unique Lexicographically Sortable Identifier (ULID).',
keywords: ['ulid', 'generator', 'random', 'id', 'alphanumeric', 'identity', 'token', 'string', 'identifier', 'unique'],
component: () => import('./ulid-generator.vue'),
icon: SortDescendingNumbers,
createdAt: new Date('2023-09-11'),
});
23 changes: 23 additions & 0 deletions src/tools/ulid-generator/ulid-generator.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { expect, test } from '@playwright/test';

const ULID_REGEX = /[0-9A-Z]{26}/;

test.describe('Tool - ULID generator', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/ulid-generator');
});

test('Has correct title', async ({ page }) => {
await expect(page).toHaveTitle('ULID generator - IT Tools');
});

test('the refresh button generates a new ulid', async ({ page }) => {
const ulid = await page.getByTestId('ulids').textContent();
expect(ulid?.trim()).toMatch(ULID_REGEX);

await page.getByTestId('refresh').click();
const newUlid = await page.getByTestId('ulids').textContent();
expect(ulid?.trim()).not.toBe(newUlid?.trim());
expect(newUlid?.trim()).toMatch(ULID_REGEX);
});
});
46 changes: 46 additions & 0 deletions src/tools/ulid-generator/ulid-generator.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<script setup lang="ts">
import { ulid } from 'ulid';
import _ from 'lodash';
import { computedRefreshable } from '@/composable/computedRefreshable';
import { useCopy } from '@/composable/copy';

const amount = useStorage('ulid-generator-amount', 1);
const formats = [{ label: 'Raw', value: 'raw' }, { label: 'JSON', value: 'json' }] as const;
const format = useStorage<typeof formats[number]['value']>('ulid-generator-format', formats[0].value);

const [ulids, refreshUlids] = computedRefreshable(() => {
const ids = _.times(amount.value, () => ulid());

if (format.value === 'json') {
return JSON.stringify(ids, null, 2);
}

return ids.join('\n');
});

const { copy } = useCopy({ source: ulids, text: 'ULIDs copied to the clipboard' });
</script>

<template>
<div flex flex-col justify-center gap-2>
<div flex items-center>
<label w-75px> Quantity:</label>
<n-input-number v-model:value="amount" min="1" max="100" flex-1 />
</div>

<c-buttons-select v-model:value="format" :options="formats" label="Format: " label-width="75px" />

<c-card mt-5 flex data-test-id="ulids">
<pre m-0 m-x-auto>{{ ulids }}</pre>
</c-card>

<div flex justify-center gap-2>
<c-button data-test-id="refresh" @click="refreshUlids()">
Refresh
</c-button>
<c-button @click="copy()">
Copy
</c-button>
</div>
</div>
</template>
14 changes: 14 additions & 0 deletions src/ui/c-buttons-select/c-buttons-select.demo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<script setup lang="ts">
const optionsA = [
{ label: 'Option A', value: 'a' },
{ label: 'Option B', value: 'b', tooltip: 'This is a tooltip' },
{ label: 'Option C', value: 'c' },
];
const valueA = ref('a');
</script>

<template>
<c-buttons-select v-model:value="valueA" :options="optionsA" label="Label: " />
<c-buttons-select v-model:value="valueA" :options="optionsA" label="Label: " label-position="left" mt-2 />
<c-buttons-select v-model:value="valueA" :options="optionsA" label="Label: " label-position="left" mt-2 />
</template>
5 changes: 5 additions & 0 deletions src/ui/c-buttons-select/c-buttons-select.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { CSelectOption } from '../c-select/c-select.types';

export type CButtonSelectOption<T> = CSelectOption<T> & {
tooltip?: string
};
59 changes: 59 additions & 0 deletions src/ui/c-buttons-select/c-buttons-select.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<script setup lang="ts" generic="T extends unknown">
import type { CLabelProps } from '../c-label/c-label.types';
import type { CButtonSelectOption } from './c-buttons-select.types';

const props = withDefaults(
defineProps<{
options?: CButtonSelectOption<T>[] | string[]
value?: T
size?: 'small' | 'medium' | 'large'
} & CLabelProps >(),
{
options: () => [],
value: undefined,
labelPosition: 'left',
size: 'medium',
},
);

const emits = defineEmits(['update:value']);

const { options: rawOptions, size } = toRefs(props);

const options = computed(() => {
return rawOptions.value.map((option: string | CButtonSelectOption<T>) => {
if (typeof option === 'string') {
return { label: option, value: option };
}

return option;
});
});

const value = useVModel(props, 'value', emits);

function selectOption(option: CButtonSelectOption<T>) {
// @ts-expect-error vue template generic is a bit flacky thanks to withDefaults
value.value = option.value;
}
</script>

<template>
<c-label v-bind="props">
<div class="flex gap-2">
<c-tooltip
v-for="option in options" :key="option.value"
:tooltip="option.tooltip"
>
<c-button
:test-id="option.value"
:size="size"
:type="option.value === value ? 'primary' : 'default'"
@click="selectOption(option)"
>
{{ option.label }}
</c-button>
</c-tooltip>
</div>
</c-label>
</template>
1 change: 1 addition & 0 deletions src/ui/c-tooltip/c-tooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const isTargetHovered = useElementHover(targetRef);
</div>

<div
v-if="tooltip || $slots.tooltip"
class="absolute bottom-100% left-50% z-10 mb-5px whitespace-nowrap rounded bg-black px-12px py-6px text-sm text-white shadow-lg transition transition transition-duration-0.2s -translate-x-1/2"
:class="{
'op-0 scale-0': isTargetHovered === false,
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载