Skip to content

Instantly share code, notes, and snippets.

@zbigniewTomczak
Created February 19, 2013 14:19
Show Gist options
  • Save zbigniewTomczak/4986306 to your computer and use it in GitHub Desktop.
Save zbigniewTomczak/4986306 to your computer and use it in GitHub Desktop.
Function.prototype.method = function (name, func) {
if (!this.prototype[name]) {
this.prototype[name] = func;
return this;
}
};
String.method('deentityify', function ( ) {
var entity = {
quot: '"',
lt: '<',
gt: '>'
};
return function ( ) {
return this.replace(/&([^&;]+);/g,
function (a, b) {
var r = entity[b];
return typeof r === 'string' ? r : a;
}
);
};
}() );
console.log( '&lt;&quot;&gt;'.deentityify() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment