-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·47 lines (41 loc) · 973 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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);