From e7245a709c703d5ea9931ff3911747bab1486734 Mon Sep 17 00:00:00 2001 From: saqimtiaz Date: Sun, 1 Nov 2020 18:11:46 +0100 Subject: [PATCH] Add string operator enlist-input[] (#4948) * Add string operator titlelist[] * Update strings.js * Update strings.js * Add tests --- core/modules/filters/strings.js | 8 ++++---- editions/test/tiddlers/tests/test-filters.js | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/core/modules/filters/strings.js b/core/modules/filters/strings.js index 625acd9a7..38620454c 100644 --- a/core/modules/filters/strings.js +++ b/core/modules/filters/strings.js @@ -56,14 +56,14 @@ exports.trim = function(source,operator,options) { return result; }; -// makeStringBinaryOperator( -// function(a) {return [$tw.utils.trim(a)];} -// ); - exports.split = makeStringBinaryOperator( function(a,b) {return ("" + a).split(b);} ); +exports["enlist-input"] = makeStringBinaryOperator( + function(a) {return $tw.utils.parseStringArray("" + a);} +); + exports.join = makeStringReducingOperator( function(accumulator,value,operand) { if(accumulator === null) { diff --git a/editions/test/tiddlers/tests/test-filters.js b/editions/test/tiddlers/tests/test-filters.js index 2d486a181..aa25a1121 100644 --- a/editions/test/tiddlers/tests/test-filters.js +++ b/editions/test/tiddlers/tests/test-filters.js @@ -160,6 +160,13 @@ function runTests(wiki) { expect(wiki.filterTiddlers("[enlist[one two three]addsuffix[!]]").join(",")).toBe("one!,two!,three!"); }); + it("should handle the enlist-input operator", function() { + expect(wiki.filterTiddlers("[[one two three]enlist-input[]]").join(",")).toBe("one,two,three"); + expect(wiki.filterTiddlers("[[one two three]] [[four five six]] +[enlist-input[]]").join(",")).toBe("one,two,three,four,five,six"); + expect(wiki.filterTiddlers("[[one two three]] [[four five six]] [[seven eight]] +[enlist-input[]]").join(",")).toBe("one,two,three,four,five,six,seven,eight"); + expect(wiki.filterTiddlers("[[]] +[enlist-input[]]").join(",")).toBe(""); + }); + it("should handle the then and else operators", function() { expect(wiki.filterTiddlers("[modifier[JoeBloggs]then[Susi]]").join(",")).toBe("Susi"); expect(wiki.filterTiddlers("[!modifier[JoeBloggs]then[Susi]]").join(",")).toBe("Susi,Susi,Susi,Susi,Susi,Susi,Susi,Susi");