-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.js
28 lines (26 loc) · 793 Bytes
/
plugin.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
module.exports.templateTags = [{
name: 'randomPick',
displayName: 'Random Pick',
description: 'Random pick value from array',
args: [
{
type: 'string',
displayName: 'Items',
description: 'Array of items',
placeholder: 'zero;one;two',
}
],
run (context, itemsString) {
try {
const items = itemsString.split(';').filter((item) => item.length);
let randomItem = items[Math.floor(Math.random() * items.length)];
try {
randomItem = eval(randomItem);
} catch (error) { }
return randomItem;
} catch (error) {
console.error(error);
throw new Error(`Error: ${error.message}`);
}
}
}]