1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00

Maths operators: Remove concat (same as addsuffix) and add splitregexp

This commit is contained in:
Jeremy Ruston 2019-06-13 16:52:19 +01:00
parent fc09f8e331
commit 73eb7fbd4e

View File

@ -30,15 +30,11 @@ exports.trim = makeStringBinaryOperator(
function(a) {return [$tw.utils.trim(a)];} function(a) {return [$tw.utils.trim(a)];}
); );
exports.concat = makeStringBinaryOperator(
function(a,b) {return ["" + a + b];}
);
exports.split = makeStringBinaryOperator( exports.split = makeStringBinaryOperator(
function(a,b) {return ("" + a).split(b).filter(function(str) {return !!str;});} function(a,b) {return ("" + a).split(b).filter(function(str) {return !!str;});}
); );
exports.join = makeStringArrayOperator( exports.join = makeStringReducingOperator(
function(accumulator,value,operand) { function(accumulator,value,operand) {
return "" + (accumulator ? accumulator + (operand || "") + value : value); return "" + (accumulator ? accumulator + (operand || "") + value : value);
} }
@ -54,7 +50,7 @@ function makeStringBinaryOperator(fnCalc) {
}; };
} }
function makeStringArrayOperator(fnCalc,initialValue) { function makeStringReducingOperator(fnCalc,initialValue) {
initialValue = initialValue || ""; initialValue = initialValue || "";
return function(source,operator,options) { return function(source,operator,options) {
var result = []; var result = [];
@ -67,4 +63,15 @@ function makeStringArrayOperator(fnCalc,initialValue) {
}; };
} }
exports.splitregexp = function(source,operator,options) {
var result = [],
suffix = operator.suffix || "",
flags = (suffix.indexOf("m") !== -1 ? "m" : "") + (suffix.indexOf("i") !== -1 ? "i" : ""),
regExp = new RegExp(operator.operand || "",flags);
source(function(tiddler,title) {
Array.prototype.push.apply(result,title.split(regExp));
});
return result;
};
})(); })();