Created
May 29, 2013 16:47
-
-
Save tatat/5671799 to your computer and use it in GitHub Desktop.
全部16進数の数値文字参照にするやつ
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
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