Created
August 27, 2015 07:56
-
-
Save nordinrahman/0eccaec7b5b988e74c5d to your computer and use it in GitHub Desktop.
escapeHtml via JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://stackoverflow.com/a/13371349/29669 | |
var escapeHtml = (function () { | |
'use strict'; | |
var chr = { '"': '"', '&': '&', '<': '<', '>': '>' }; | |
return function (text) { | |
return text.replace(/[\"&<>]/g, function (a) { return chr[a]; }); | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment