mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Maths operators: Remove concat (same as addsuffix) and add splitregexp
This commit is contained in:
parent
fc09f8e331
commit
73eb7fbd4e
@ -30,15 +30,11 @@ exports.trim = makeStringBinaryOperator(
|
||||
function(a) {return [$tw.utils.trim(a)];}
|
||||
);
|
||||
|
||||
exports.concat = makeStringBinaryOperator(
|
||||
function(a,b) {return ["" + a + b];}
|
||||
);
|
||||
|
||||
exports.split = makeStringBinaryOperator(
|
||||
function(a,b) {return ("" + a).split(b).filter(function(str) {return !!str;});}
|
||||
);
|
||||
|
||||
exports.join = makeStringArrayOperator(
|
||||
exports.join = makeStringReducingOperator(
|
||||
function(accumulator,value,operand) {
|
||||
return "" + (accumulator ? accumulator + (operand || "") + value : value);
|
||||
}
|
||||
@ -54,7 +50,7 @@ function makeStringBinaryOperator(fnCalc) {
|
||||
};
|
||||
}
|
||||
|
||||
function makeStringArrayOperator(fnCalc,initialValue) {
|
||||
function makeStringReducingOperator(fnCalc,initialValue) {
|
||||
initialValue = initialValue || "";
|
||||
return function(source,operator,options) {
|
||||
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;
|
||||
};
|
||||
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user