2018-06-25 17:42:50 +00:00
|
|
|
module.exports.templateTags = [
|
|
|
|
{
|
|
|
|
name: 'base64',
|
|
|
|
displayName: 'Base64',
|
|
|
|
description: 'encode or decode values',
|
|
|
|
args: [
|
|
|
|
{
|
|
|
|
displayName: 'Action',
|
|
|
|
type: 'enum',
|
|
|
|
options: [
|
|
|
|
{ displayName: 'Encode', value: 'encode' },
|
2018-12-12 17:36:11 +00:00
|
|
|
{ displayName: 'Decode', value: 'decode' },
|
|
|
|
],
|
2018-06-25 17:42:50 +00:00
|
|
|
},
|
2019-03-13 17:07:52 +00:00
|
|
|
{
|
|
|
|
displayName: 'Kind',
|
|
|
|
type: 'enum',
|
2020-05-14 22:54:07 +00:00
|
|
|
options: [
|
|
|
|
{ displayName: 'Normal', value: 'normal' },
|
|
|
|
{ displayName: 'URL', value: 'url' },
|
|
|
|
],
|
2019-03-13 17:07:52 +00:00
|
|
|
},
|
2018-06-25 17:42:50 +00:00
|
|
|
{
|
|
|
|
displayName: 'Value',
|
|
|
|
type: 'string',
|
2018-12-12 17:36:11 +00:00
|
|
|
placeholder: 'My text',
|
|
|
|
},
|
2018-06-25 17:42:50 +00:00
|
|
|
],
|
2019-03-13 17:07:52 +00:00
|
|
|
run(context, action, kind, text) {
|
2018-06-25 17:42:50 +00:00
|
|
|
text = text || '';
|
2017-04-07 18:10:15 +00:00
|
|
|
|
2019-03-13 17:07:52 +00:00
|
|
|
if (action === 'encode') {
|
|
|
|
if (kind === 'normal') {
|
|
|
|
return Buffer.from(text, 'utf8').toString('base64');
|
|
|
|
} else if (kind === 'url') {
|
|
|
|
return Buffer.from(text, 'utf8')
|
|
|
|
.toString('base64')
|
|
|
|
.replace(/\+/g, '-')
|
|
|
|
.replace(/\//g, '_')
|
|
|
|
.replace(/=/g, '');
|
|
|
|
}
|
|
|
|
} else if (action === 'decode') {
|
2018-06-25 17:42:50 +00:00
|
|
|
return Buffer.from(text, 'base64').toString('utf8');
|
|
|
|
} else {
|
2019-03-13 17:07:52 +00:00
|
|
|
throw new Error('Unsupported operation "' + action + '". Must be encode or decode.');
|
2018-06-25 17:42:50 +00:00
|
|
|
}
|
2018-12-12 17:36:11 +00:00
|
|
|
},
|
|
|
|
},
|
2018-06-25 17:42:50 +00:00
|
|
|
];
|