ext-utils/string.js

23 lines
399 B
JavaScript
Raw Normal View History

2016-05-31 09:56:05 +00:00
module.exports = {
encodeHtml: function ( str, br )
{
str = ( str + "" ).replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&apos;")
;
if( br ) str = str.replace( /\n/g, "<br/>" );
return str;
}
, http_str: function( str )
{
if( str.match( "^https?://" ) )
{
return str;
}
return "http://" + str;
}
}