mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-03 04:39:10 +00:00
Added trim string utility function
This commit is contained in:
parent
4953fd6c80
commit
27c21a5edb
@ -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 "&", < to "<", > to ">" and " to """
|
||||
exports.htmlEncode = function(s)
|
||||
{
|
||||
exports.htmlEncode = function(s) {
|
||||
if(s) {
|
||||
return s.toString().replace(/&/mg,"&").replace(/</mg,"<").replace(/>/mg,">").replace(/\"/mg,""");
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user