Skip to content

Instantly share code, notes, and snippets.

@ArielLeslie
Created November 16, 2015 00:22
Show Gist options
  • Save ArielLeslie/8d40b5c614c6d97aec05 to your computer and use it in GitHub Desktop.
Save ArielLeslie/8d40b5c614c6d97aec05 to your computer and use it in GitHub Desktop.
Bonfire: Convert HTML Entities
function convert(str) {
var mapping = {
'&' : '&',
':' : ':',
'<' : '&lt;',
'>' : '&gt;',
'"' : '&quot;',
"'" : '&apos;'
};
var words =str.split('');
words = words.map(function(word){
return mapping.hasOwnProperty(word) ? mapping[word] : word;
});
return words.join('');
}
convert("Dolce & Gabbana");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment