From 97e995e0c730603e62daa7be319a00814f6357f9 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Thu, 9 Feb 2017 15:43:28 +0000 Subject: [PATCH] Add wiki.checkTiddlerText() convenience method --- core/modules/wiki.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 9eed1b5f1..a402cac6c 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -1106,6 +1106,22 @@ exports.getTiddlerText = function(title,defaultText) { } }; +/* +Check whether the text of a tiddler matches a given value. By default, the comparison is case insensitive, and any spaces at either end of the tiddler text is trimmed +*/ +exports.checkTiddlerText = function(title,targetText,options) { + options = options || {}; + var text = this.getTiddlerText(title,""); + if(!options.noTrim) { + text = text.trim(); + } + if(!options.caseSensitive) { + text = text.toLowerCase(); + targetText = targetText.toLowerCase(); + } + return text === targetText; +} + /* Read an array of browser File objects, invoking callback(tiddlerFieldsArray) once they're all read */