insomnia/app/templating/extensions/base-64-extension.js
Gregory Schier fd7a25e1ac New 'request' tag and a lot of improvements (#296)
* New 'request' tag and a lot of improvements

* Update request extension to render all values

* Custom value of tag editor now inherits current
2017-06-08 18:10:12 -07:00

32 lines
739 B
JavaScript

export default {
name: 'base64',
displayName: 'Base64',
description: 'encode or decode values',
args: [
{
displayName: 'Action',
type: 'enum',
options: [
{displayName: 'Encode', value: 'encode'},
{displayName: 'Decode', value: 'decode'}
]
},
{
displayName: 'Value',
type: 'string',
placeholder: 'My text'
}
],
run (context, op, text) {
text = text || '';
if (op === 'encode') {
return Buffer.from(text, 'utf8').toString('base64');
} else if (op === 'decode') {
return Buffer.from(text, 'base64').toString('utf8');
} else {
throw new Error('Unsupported operation "' + op + '". Must be encode or decode.');
}
}
};