Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created March 29, 2012 16:42
Show Gist options
  • Save isaacs/2239665 to your computer and use it in GitHub Desktop.
Save isaacs/2239665 to your computer and use it in GitHub Desktop.
This is working in node 0.7.7
$ node unicode.js
buf= <Buffer 5b 22 f0 9f 92 a9 22 0a 2c 22 f0 9f 98 81 22 0a 2c 22 5c 75 64 38 33 64 5c 75 64 63 61 39 22 0a 2c 22 5c 75 64 38 33 64 5c 75 64 65 30 31 22 0a 5d 0a>
str= ["πŸ’©"
,"😁"
,"\ud83d\udca9"
,"\ud83d\ude01"
]
obj= [ 'πŸ’©', '😁', 'πŸ’©', '😁' ]
obj[0]= πŸ’©
obj[0].length= 2
obj[0].charAt(0)= ?
obj[0].charCodeAt(0)= d83d
obj[0].charAt(1)= ?
obj[0].charCodeAt(1)= dca9
obj[1]= 😁
obj[1].length= 2
obj[1].charAt(0)= ?
obj[1].charCodeAt(0)= d83d
obj[1].charAt(1)= ?
obj[1].charCodeAt(1)= de01
obj[2]= πŸ’©
obj[2].length= 2
obj[2].charAt(0)= ?
obj[2].charCodeAt(0)= d83d
obj[2].charAt(1)= ?
obj[2].charCodeAt(1)= dca9
obj[3]= 😁
obj[3].length= 2
obj[3].charAt(0)= ?
obj[3].charCodeAt(0)= d83d
obj[3].charAt(1)= ?
obj[3].charCodeAt(1)= de01
var fs = require("fs")
var buf = fs.readFileSync("unicode.json")
console.error("buf=", buf)
var str = buf.toString("utf8")
console.error("str=", str)
var obj = JSON.parse(str)
console.error("obj=", obj)
obj.forEach(function (char, pos) {
console.error("obj[%d]=", pos, obj[pos])
console.error("obj[%d].length=", pos, obj[pos].length)
for (var i = 0; i < obj[pos].length; i ++) {
console.error("obj[%d].charAt(%d)=", pos, i, obj[pos].charAt(i))
console.error("obj[%d].charCodeAt(%d)=", pos, i, obj[pos].charCodeAt(i).toString(16))
}
})
["πŸ’©"
,"😁"
,"\ud83d\udca9"
,"\ud83d\ude01"
]
@isaacs
Copy link
Author

isaacs commented Mar 29, 2012

The font that github uses for code apparently doesn't have glyphs for poo face and smiling eyes.

@mathiasbynens
Copy link

@isaacs The rendering depends on the browser. It works in Opera and Safari. Chrome does not support Emoji. Firefox displays the Emoji, but uses the non-colored OS X-style glyphs.

@isaacs
Copy link
Author

isaacs commented Mar 29, 2012

Ahh, I see. Thanks, for the clarification, @mathiasbynens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment