mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-11 09:50:27 +00:00
Add encodebase64/decodebase64 operators
Proposed by @ericshulman
This commit is contained in:
parent
f249b79e81
commit
89fd8871b6
@ -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) {
|
||||
|
19
editions/test/tiddlers/tests/data/filters/Base64.tid
Normal file
19
editions/test/tiddlers/tests/data/filters/Base64.tid
Normal 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>
|
16
editions/tw5.com/tiddlers/filters/decodebase64 Operator.tid
Normal file
16
editions/tw5.com/tiddlers/filters/decodebase64 Operator.tid
Normal 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">>
|
16
editions/tw5.com/tiddlers/filters/encodebase64 Operator.tid
Normal file
16
editions/tw5.com/tiddlers/filters/encodebase64 Operator.tid
Normal 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">>
|
Loading…
Reference in New Issue
Block a user