1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-16 02:19:55 +00:00

Split operator: Remove empty strings when splitting

See the discussion on 9b2d527; thanks @kookma
This commit is contained in:
Jermolene 2019-02-08 15:59:07 +00:00
parent 6ff7a7d261
commit 9d7d3fefa0
2 changed files with 3 additions and 2 deletions

View File

@ -35,7 +35,7 @@ exports.concat = makeStringBinaryOperator(
);
exports.split = makeStringBinaryOperator(
function(a,b) {return ("" + a).split(b);}
function(a,b) {return ("" + a).split(b).filter(function(str) {return !!str;});}
);
exports.join = makeStringArrayOperator(

View File

@ -368,7 +368,8 @@ describe("Filter tests", function() {
expect(wiki.filterTiddlers("John Paul George Ringo +[lowercase[]]").join(",")).toBe("john,paul,george,ringo");
expect(wiki.filterTiddlers("John Paul George Ringo +[concat[y]]").join(",")).toBe("Johny,Pauly,Georgey,Ringoy");
expect(wiki.filterTiddlers("John Paul George Ringo +[split[]]").join(",")).toBe("J,o,h,n,P,a,u,l,G,e,o,r,g,e,R,i,n,g,o");
expect(wiki.filterTiddlers("John Paul George Ringo +[split[e]]").join(",")).toBe("John,Paul,G,org,,Ringo");
expect(wiki.filterTiddlers("[[John. Paul. George. Ringo.]] +[split[.]trim[]]").join(",")).toBe("John,Paul,George,Ringo");
expect(wiki.filterTiddlers("John Paul George Ringo +[split[e]]").join(",")).toBe("John,Paul,G,org,Ringo");
expect(wiki.filterTiddlers("John Paul George Ringo +[join[ ]split[e]join[ee]split[ ]]").join(",")).toBe("John,Paul,Geeorgee,Ringo");
expect(wiki.filterTiddlers("[[ John ]] [[Paul ]] [[ George]] Ringo +[trim[]join[-]]").join(",")).toBe("John-Paul-George-Ringo");
});