diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c486e657..c76a1770 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10094,7 +10094,6 @@ packages: /glob@7.2.3: resolution: {integrity: sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==} - deprecated: Glob versions prior to v9 are no longer supported dependencies: fs.realpath: 1.0.0 inflight: 1.0.6 diff --git a/src/composable/computed/catchedComputed.ts b/src/composable/computed/catchedComputed.ts index fd00a128..259c481e 100644 --- a/src/composable/computed/catchedComputed.ts +++ b/src/composable/computed/catchedComputed.ts @@ -1,6 +1,6 @@ import { type Ref, ref, watchEffect } from 'vue'; -export { computedCatch }; +export { computedCatch, computedCatchAsync }; function computedCatch(getter: () => T, { defaultValue }: { defaultValue: D; defaultErrorMessage?: string }): [Ref, Ref]; function computedCatch(getter: () => T, { defaultValue, defaultErrorMessage = 'Unknown error' }: { defaultValue?: D; defaultErrorMessage?: string } = {}) { @@ -20,3 +20,22 @@ function computedCatch(getter: () => T, { defaultValue, defaultErrorMessag return [value, error] as const; } + +function computedCatchAsync(getterAsync: () => Promise, { defaultValue }: { defaultValue: D; defaultErrorMessage?: string }): [Ref, Ref]; +function computedCatchAsync(getterAsync: () => Promise, { defaultValue, defaultErrorMessage = 'Unknown error' }: { defaultValue?: D; defaultErrorMessage?: string } = {}) { + const error = ref(); + const value = ref(); + + watchEffect(async () => { + try { + error.value = undefined; + value.value = await getterAsync(); + } + catch (err) { + error.value = err instanceof Error ? err.message : err?.toString() ?? defaultErrorMessage; + value.value = defaultValue; + } + }); + + return [value, error] as const; +} diff --git a/src/tools/index.ts b/src/tools/index.ts index fc7e7e17..53306e9b 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -127,6 +127,7 @@ import { tool as markdownCheatsheet } from './markdown-cheatsheet'; import { tool as markdownEditor } from './markdown-editor'; import { tool as nanoMemo } from './nano-memo'; import { tool as option43Generator } from './option43-generator'; +import { tool as pgpEncryption } from './pgp-encryption'; import { tool as pdfSignatureChecker } from './pdf-signature-checker'; import { tool as numeronymGenerator } from './numeronym-generator'; import { tool as macAddressGenerator } from './mac-address-generator'; @@ -270,6 +271,9 @@ export const toolsByCategory: ToolCategory[] = [ ed25519KeyPairGenerator, passwordStrengthAnalyser, pdfSignatureChecker, + passwordStrengthAnalyser, + pdfSignatureChecker, + pgpEncryption, ], }, { diff --git a/src/tools/pgp-encryption/index.ts b/src/tools/pgp-encryption/index.ts new file mode 100644 index 00000000..1006484f --- /dev/null +++ b/src/tools/pgp-encryption/index.ts @@ -0,0 +1,12 @@ +import { Lock } from '@vicons/tabler'; +import { defineTool } from '../tool'; + +export const tool = defineTool({ + name: 'PGP encryption', + path: '/pgp-encryption', + description: 'Encrypt and decrypt text clear text using PGP Keys.', + keywords: ['pgp', 'openpgp', 'encryption', 'cypher', 'encipher', 'crypt', 'decrypt'], + component: () => import('./pgp-encryption.vue'), + icon: Lock, + createdAt: new Date('2024-04-20'), +}); diff --git a/src/tools/pgp-encryption/pgp-encryption.vue b/src/tools/pgp-encryption/pgp-encryption.vue new file mode 100644 index 00000000..3d85a8f4 --- /dev/null +++ b/src/tools/pgp-encryption/pgp-encryption.vue @@ -0,0 +1,194 @@ + + +