"dedupe" and "raw" suffixes for enlist-input operator (#5152)

Includes unit tests.
optimising-macrocalls
Robin Munn 2020-12-01 00:52:46 +07:00 zatwierdzone przez GitHub
rodzic 8fc6910c03
commit fd3e77d38f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 10 dodań i 3 usunięć

Wyświetl plik

@ -61,7 +61,7 @@ exports.split = makeStringBinaryOperator(
);
exports["enlist-input"] = makeStringBinaryOperator(
function(a) {return $tw.utils.parseStringArray("" + a);}
function(a,o,s) {return $tw.utils.parseStringArray("" + a,(s === "raw"));}
);
exports.join = makeStringReducingOperator(
@ -78,7 +78,7 @@ function makeStringBinaryOperator(fnCalc) {
return function(source,operator,options) {
var result = [];
source(function(tiddler,title) {
Array.prototype.push.apply(result,fnCalc(title,operator.operand || ""));
Array.prototype.push.apply(result,fnCalc(title,operator.operand || "",operator.suffix || ""));
});
return result;
};

Wyświetl plik

@ -184,6 +184,9 @@ function runTests(wiki) {
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 two three]enlist-input[]]").join(",")).toBe("one,two,three");
expect(wiki.filterTiddlers("[[one two two three]enlist-input:dedupe[]]").join(",")).toBe("one,two,three");
expect(wiki.filterTiddlers("[[one two two three]enlist-input:raw[]]").join(",")).toBe("one,two,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("");

Wyświetl plik

@ -4,6 +4,8 @@ modified: 20201102221854719
op-input: a [[selection of titles|Title Selection]]
op-output: the titles stored as a [[title list|Title List]] in each input title
op-purpose: select titles by interpreting each input title as a [[title list|Title List]]
op-suffix: `dedupe` (the default) to remove duplicates, `raw` to leave duplicates untouched
op-suffix-name: D
tags: [[Filter Operators]] [[String Operators]] [[Selection Constructors]]
title: enlist-input Operator
type: text/vnd.tiddlywiki

Wyświetl plik

@ -7,4 +7,6 @@ type: text/vnd.tiddlywiki
<<.operator-example 1 "[[Days of the Week]get[list]enlist-input[]]">>
Contrast with: <<.operator-example 2 "[[Days of the Week]get[list]]">>
<<.operator-example 3 "'HelloThere GettingStarted [[Customise TiddlyWiki]]' +[enlist-input[]]">>
Contrast with: <<.operator-example 4 "'HelloThere GettingStarted [[Customise TiddlyWiki]]'">>
Contrast with: <<.operator-example 4 "'HelloThere GettingStarted [[Customise TiddlyWiki]]'">>
<<.operator-example 5 "'HelloThere HelloThere GettingStarted [[Customise TiddlyWiki]]' +[enlist-input:raw[]]">>
Contrast with: <<.operator-example 6 "'HelloThere HelloThere GettingStarted [[Customise TiddlyWiki]]' +[enlist-input[]]">>