1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-27 14:48:19 +00:00

Added trim string utility function

This commit is contained in:
Jeremy Ruston 2012-12-26 19:35:12 +00:00
parent 4953fd6c80
commit 27c21a5edb

View File

@ -12,6 +12,18 @@ Various static utility functions.
/*global $tw: false */
"use strict";
/*
Trim whitespace from the start and end of a string
Thanks to Steven Levithan, http://blog.stevenlevithan.com/archives/faster-trim-javascript
*/
exports.trim = function(str) {
if(typeof str === "string") {
return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
} else {
return str;
}
};
/*
Return the number of keys in an object
*/
@ -222,8 +234,7 @@ exports.getRelativeDate = function(delta) {
};
// Convert & to "&amp;", < to "&lt;", > to "&gt;" and " to "&quot;"
exports.htmlEncode = function(s)
{
exports.htmlEncode = function(s) {
if(s) {
return s.toString().replace(/&/mg,"&amp;").replace(/</mg,"&lt;").replace(/>/mg,"&gt;").replace(/\"/mg,"&quot;");
} else {