Add encodebase64/decodebase64 operators

Proposed by @ericshulman
This commit is contained in:
jeremy@jermolene.com 2023-02-02 09:55:54 +00:00
parent f249b79e81
commit 89fd8871b6
4 changed files with 67 additions and 0 deletions

View File

@ -16,6 +16,22 @@ Filter operator for applying decodeURIComponent() to each item.
Export our filter functions
*/
exports.decodebase64 = function(source,operator,options) {
var results = [];
source(function(tiddler,title) {
results.push($tw.utils.base64Decode(title));
});
return results;
};
exports.encodebase64 = function(source,operator,options) {
var results = [];
source(function(tiddler,title) {
results.push($tw.utils.base64Encode(title));
});
return results;
};
exports.decodeuricomponent = function(source,operator,options) {
var results = [];
source(function(tiddler,title) {

View File

@ -0,0 +1,19 @@
title: Filters/Base64
description: Test {encode|decode}base64 operators
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
(<$text text={{{ [[Jeremy1234]encodebase64[]] }}}/>)
(<$text text={{{ [[]encodebase64[]] }}}/>)
(<$text text={{{ [[SmVyZW15MTIzNA==]decodebase64[]] }}}/>)
(<$text text={{{ [[]decodebase64[]] }}}/>)
+
title: ExpectedResult
<p>(SmVyZW15MTIzNA==)
()
(Jeremy1234)
()</p>

View File

@ -0,0 +1,16 @@
caption: decodebase64
op-input: a [[selection of titles|Title Selection]]
op-output: the input with base 64 decoding applied
op-parameter:
op-parameter-name:
op-purpose: apply base 64 decoding to a string
tags: [[Filter Operators]] [[String Operators]]
title: decodebase64 Operator
type: text/vnd.tiddlywiki
from-version: 5.2.6
See Mozilla Developer Network for details of [[base 64 encoding|https://developer.mozilla.org/en-US/docs/Glossary/Base64]]. TiddlyWiki uses [[library code from @nijikokun|https://gist.github.com/Nijikokun/5192472]] to handle the conversion.
The input strings must be base64 encoded. The output strings are binary data.
<<.operator-examples "decodebase64">>

View File

@ -0,0 +1,16 @@
caption: encodebase64
op-input: a [[selection of titles|Title Selection]]
op-output: the input with base 64 encoding applied
op-parameter:
op-parameter-name:
op-purpose: apply base 64 encoding to a string
tags: [[Filter Operators]] [[String Operators]]
title: encodebase64 Operator
type: text/vnd.tiddlywiki
from-version: 5.2.6
See Mozilla Developer Network for details of [[base 64 encoding|https://developer.mozilla.org/en-US/docs/Glossary/Base64]]. TiddlyWiki uses [[library code from @nijikokun|https://gist.github.com/Nijikokun/5192472]] to handle the conversion.
The input strings are interpreted as binary data. The output strings are base64 encoded.
<<.operator-examples "encodebase64">>