Skip to content

Instantly share code, notes, and snippets.

@tatat
Created May 29, 2013 16:47
Show Gist options
  • Save tatat/5671799 to your computer and use it in GitHub Desktop.
Save tatat/5671799 to your computer and use it in GitHub Desktop.
全部16進数の数値文字参照にするやつ
var entity = function(string) {
return ('' + string).replace(/(?:[\uD800-\uDBFF][\uDC00-\uDFFF]|[\S\s])/g, function(m0) {
var c = m0.length === 2 ?
(((m0.charCodeAt(0) & 0x3ff) << 10) | (m0.charCodeAt(1) & 0x3ff)) + 0x10000 :
m0.charCodeAt(0);
return '&#x' + c.toString(16) + ';';
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment