Skip to content

Instantly share code, notes, and snippets.

@tehsis
Last active August 29, 2015 14:16
Show Gist options
  • Save tehsis/96e03c1c688239f0ca50 to your computer and use it in GitHub Desktop.
Save tehsis/96e03c1c688239f0ca50 to your computer and use it in GitHub Desktop.
// Gets charachter map from http://unicode.org/charts/charindex.html
var fs = require('fs');
var request = require('superagent');
var cheerio = require('cheerio');
var map = {};
request.get('http://unicode.org/charts/charindex.html')
.end(function(res) {
var $ = cheerio.load(res.text);
$('a[href*=pdf]').each(function() {
var code = String.fromCharCode(parseInt($(this).text(), 16));
var character_title = $(this).parent().prev().text();
var character = character_title.charAt(0);
if(character_title.charAt(1) === ' ' || character_title.charAt(1) === ',') {
map[code] = character;
}
});
fs.writeFile('../charMap.json', JSON.stringify(map), function (err) {
if (err) return console.log(err);
console.log('charMap.json created!');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment