Note: An alternative skin, TW4MW (work in progress), is available from the user preferences.
Dev:String Methods
TiddlyWiki Community Wiki
Contents |
[edit] right(n)
Returns n right-most chars from a string.
Example:
"foo".right(1) // returns "0"
[edit] trim()
Trims whitespace from the front and end of a string
Example:
" foo ".trim() // returns "foo"
[edit] format(subStrings)
Very handy for macros and plugins. A little bit like sprintf in C. subStrings should be an array.
Examples:
alert("Today I feel %0 because %1".format(['happy','my cat likes me']));
var t = store.getTiddler("MyTiddler");
var template = "Tiddler '%0' is %1 chars long and was last modified by '%2'";
alert(template.format([t.title,t.text.length,t.modifier]);
[edit] escapeRegExp()
Escapes any special RegExp characters with that character preceded by a backslash
[edit] readBrackettedList()
TBC...
String.prototype.right = function(n) String.prototype.trim = function() String.prototype.unDash = function() String.prototype.format = function(substrings) String.prototype.escapeRegExp = function() String.prototype.escapeLineBreaks = function() String.prototype.unescapeLineBreaks = function() String.prototype.htmlEncode = function() String.prototype.htmlDecode = function() String.prototype.toJSONString = function() String.prototype.parseParams = function(defaultName,defaultValue,allowEval,noNames,cascadeDefaults) String.prototype.readMacroParams = function() String.prototype.readBracketedList = function(unique) String.prototype.getChunkRange = function(start,end) String.prototype.replaceChunk = function(start,end,sub) String.prototype.getChunk = function(start,end) String.prototype.decodeHashMap = function() String.prototype.startsWith = function(prefix)

