forms
Version:
An easy way to create, parse, and validate forms
31 lines (26 loc) • 781 B
JavaScript
;
/*
* from hogan https://github.com/twitter/hogan.js/blob/master/lib/template.js#L317-L327
*/
module.exports = (function () {
var rAmp = /&/g;
var rLt = /</g;
var rGt = />/g;
var rApos = /'/g;
var rQuot = /"/g;
var hChars = /[&<>"']/;
var coerceToString = function (value) {
return typeof value === 'undefined' || value === null ? '' : String(value);
};
var htmlEscape = function (value) {
var str = coerceToString(value);
return hChars.test(str)
? str.replace(rAmp, '&')
.replace(rLt, '<')
.replace(rGt, '>')
.replace(rApos, ''')
.replace(rQuot, '"')
: str;
};
return htmlEscape;
}());