UNPKG

alfred-uuid

Version:

Alfred Workflow - Generate UUIDs in v1 and v4

48 lines (41 loc) 973 B
import {env} from 'node:process'; import alfy from 'alfy'; import {v1 as uuidv1, v4 as uuidv4} from 'uuid'; const output = []; function addAutocompleteOutput(title, subtitle, autocomplete) { output.push({ title, subtitle, autocomplete, valid: false, }); } function addUuidOutput(uuid, version) { output.push({ title: uuid, subtitle: `UUID${version}, Actions: ⏎ to copy`, arg: uuid, text: { copy: uuid, largetype: uuid, }, variables: { action: 'copy', }, }); } function genUuids(generator, version, count = 4) { for (let i = 0; i < count; i += 1) { const uuid = generator(); addUuidOutput(uuid, version); } } if (alfy.input.toLowerCase() === 'v1') { genUuids(uuidv1, 'v1'); } else if (alfy.input.toLowerCase() === 'v4') { genUuids(uuidv4, 'v4'); } else { addAutocompleteOutput(`${env.keyword} v4`, 'Generate v4 UUIDs', 'v4'); addAutocompleteOutput(`${env.keyword} v1`, 'Generate v1 UUIDs', 'v1'); } alfy.output(output);