diff --git a/locales/en.yml b/locales/en.yml index 2a44cf9a..0baa1e58 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -357,6 +357,22 @@ tools: title: UUIDs generator description: A Universally Unique Identifier (UUID) is a 128-bit number used to identify information in computer systems. The number of possible UUIDs is 16^32, which is 2^128 or about 3.4x10^38 (which is a lot!). + nanoid-generator: + title: NanoIDs generator + description: Generate random, unique, and URL-friendly IDs for your applications. + uppercase: Uppercase + lowercase: Lowercase + numbers: Numbers + symbols: Symbols + excludeLookalikes: Exclude lookalikes + length: Length + quantity: Quantity + copied: NanoID copied to the clipboard + button: + copy: Copy + refresh: Refresh + + ipv4-address-converter: title: IPv4 address converter description: Convert an IP address into decimal, binary, hexadecimal, or even an IPv6 representation of it. diff --git a/package.json b/package.json index 5b54a0ff..c2231a5d 100644 --- a/package.json +++ b/package.json @@ -177,6 +177,8 @@ "monaco-editor": "^0.43.0", "morsee": "^1.0.9", "naive-ui": "^2.35.0", + "nanoid": "^5.0.7", + "nanoid-dictionary": "^4.3.0", "netmask": "^2.0.2", "netstack.js": "^2.0.0", "nginx-config-formatter": "^1.4.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c8455ebd..1d3d286f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -428,6 +428,12 @@ dependencies: naive-ui: specifier: ^2.35.0 version: 2.35.0(vue@3.3.4) + nanoid: + specifier: ^5.0.7 + version: 5.0.8 + nanoid-dictionary: + specifier: ^4.3.0 + version: 4.3.0 netmask: specifier: ^2.0.2 version: 2.0.2 @@ -1339,6 +1345,7 @@ packages: /@babel/helper-validator-identifier@7.22.20: resolution: {integrity: sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==} engines: {node: '>=6.9.0'} + dev: true /@babel/helper-validator-identifier@7.22.5: resolution: {integrity: sha512-aJXu+6lErq8ltp+JhkJUfk1MTGyuA4v7f3pA+BJ5HLfNC6nAQ0Cpi9uOquUj8Hehg0aUiHzWQbOVJGao6ztBAQ==} @@ -1439,6 +1446,7 @@ packages: hasBin: true dependencies: '@babel/types': 7.23.0 + dev: true /@babel/parser@7.26.2: resolution: {integrity: sha512-DWMCZH9WA4Maitz2q21SRKHo9QXZxkDsbNZoVD62gusNtNBBqDg9i7uOhASfTfIGNzW+O+r7+jAlM8dwphcJKQ==} @@ -2430,6 +2438,7 @@ packages: '@babel/helper-string-parser': 7.22.5 '@babel/helper-validator-identifier': 7.22.20 to-fast-properties: 2.0.0 + dev: true /@babel/types@7.26.0: resolution: {integrity: sha512-Z/yiTPj+lDVnF7lWeKCIJzaIkI0vYO87dMpZ4bg4TDrFe4XXLFWL1TbXU27gBP3QccxV9mZICCrnjnYlJjXHOA==} @@ -5467,7 +5476,7 @@ packages: /@types/lodash-es@4.17.10: resolution: {integrity: sha512-YJP+w/2khSBwbUSFdGsSqmDvmnN3cCKoPOL7Zjle6s30ZtemkkqhjVfFqGwPN7ASil5VyjE2GtyU/yqYY6mC0A==} dependencies: - '@types/lodash': 4.14.200 + '@types/lodash': 4.14.192 dev: false /@types/lodash.defaultsdeep@4.6.9: @@ -5490,7 +5499,6 @@ packages: /@types/lodash@4.14.192: resolution: {integrity: sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==} - dev: true /@types/lodash@4.14.200: resolution: {integrity: sha512-YI/M/4HRImtNf3pJgbF+W6FrXovqj+T+/HpENLTooK9PnkacBsDpeP3IpHab40CClUfhNmdM2WTNP2sa2dni5Q==} @@ -6461,11 +6469,11 @@ packages: /@vue/reactivity-transform@3.3.4: resolution: {integrity: sha512-MXgwjako4nu5WFLAjpBnCj/ieqcjE2aJBINUNQzkZQfzIZA4xn+0fV1tIYBJvvva3N3OvKGofRLvQIwEQPpaXw==} dependencies: - '@babel/parser': 7.23.0 + '@babel/parser': 7.22.10 '@vue/compiler-core': 3.3.4 '@vue/shared': 3.3.4 estree-walker: 2.0.2 - magic-string: 0.30.5 + magic-string: 0.30.2 /@vue/reactivity@3.3.4: resolution: {integrity: sha512-kLTDLwd0B1jG08NBF3R5rqULtv/f8x3rOFByTDz4J53ttIQEDmALqKqXY0J+XQeN0aV2FBxY8nJDf88yvOPAqQ==} @@ -12074,9 +12082,20 @@ packages: vueuc: 0.4.51(vue@3.3.4) dev: false + /nanoid-dictionary@4.3.0: + resolution: {integrity: sha512-Xw1+/QnRGWO1KJ0rLfU1xR85qXmAHyLbE3TUkklu9gOIDburP6CsUnLmTaNECGpBh5SHb2uPFmx0VT8UPyoeyw==} + dev: false + /nanoid@3.3.6: resolution: {integrity: sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==} engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} + hasBin: true + + /nanoid@5.0.8: + resolution: {integrity: sha512-TcJPw+9RV9dibz1hHUzlLVy8N4X9TnwirAjrU08Juo6BNKggzVfP2ZJ/3ZUSq15Xl5i85i+Z89XBO90pB2PghQ==} + engines: {node: ^18 || >=20} + hasBin: true + dev: false /napi-build-utils@1.0.2: resolution: {integrity: sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==} diff --git a/src/tools/index.ts b/src/tools/index.ts index 3099c7a0..f573d21a 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -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, diff --git a/src/tools/nanoid-generator/index.ts b/src/tools/nanoid-generator/index.ts new file mode 100644 index 00000000..a0a0a593 --- /dev/null +++ b/src/tools/nanoid-generator/index.ts @@ -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'), +}); diff --git a/src/tools/nanoid-generator/nanoid-generator.service.ts b/src/tools/nanoid-generator/nanoid-generator.service.ts new file mode 100644 index 00000000..4813830e --- /dev/null +++ b/src/tools/nanoid-generator/nanoid-generator.service.ts @@ -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); +} diff --git a/src/tools/nanoid-generator/nanoid-generator.vue b/src/tools/nanoid-generator/nanoid-generator.vue new file mode 100644 index 00000000..03b1cfb7 --- /dev/null +++ b/src/tools/nanoid-generator/nanoid-generator.vue @@ -0,0 +1,156 @@ + + + + +