Skip to content

Instantly share code, notes, and snippets.

@AoJ
Forked from isaacs/output
Created March 30, 2012 14:12
Show Gist options
  • Save AoJ/2251787 to your computer and use it in GitHub Desktop.
Save AoJ/2251787 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"
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment