Permalink
Browse files

scraper and basic index file

  • Loading branch information...
0 parents commit f0c062cfb5ba7cc4cd72745f6b84f38425b06c48 @substack committed Nov 19, 2010
Showing with 46 additions and 0 deletions.
  1. +17 −0 index.js
  2. +29 −0 scrape.js
@@ -0,0 +1,17 @@
+var fs = require('fs');
+var file = __dirname + '/data/keysyms.json';
+var data = JSON.parse(fs.readFileSync(file).toString());
+
+exports.records = data.records;
+
+exports.fromKeysym = function (keysym) {
+ return data.records[data.keysyms[keysym]]
+};
+
+exports.fromUnicode = function (code) {
+ return data.records[data.unicodes[code]]
+};
+
+exports.fromName = function (name) {
+ return data.records[data.names[name]]
+};
@@ -0,0 +1,29 @@
+// Scraper for http://www.cl.cam.ac.uk/~mgk25/ucs/keysyms.txt
+var Lazy = require('lazy');
+var Hash = require('traverse/hash');
+var fs = require('fs');
+
+var s = fs.createReadStream(__dirname + '/data/keysyms.txt');
+var re = /^0x([\da-f]+)\s+U([\da-f]+)\s+(\S+)\s+# (.+)/;
+Lazy(s).lines.map(String)
+ .filter(function (line) { return line.match(re) })
+ .map(function (line) {
+ var xs = line.match(re).slice(1);
+ xs[0] = parseInt(xs[0], 16);
+ xs[1] = parseInt(xs[1], 16);
+ return Hash.zip('keysym unicode status name'.split(' '), xs);
+ })
+ .join(function (records) {
+ var data = { records : [], keysyms : {}, unicodes : {}, names : {} };
+ records.forEach(function (rec) {
+ var i = data.records.length;
+ data.records.push(rec);
+
+ data.keysyms[rec.keysym] = i;
+ data.unicodes[rec.unicode] = i;
+ data.names[rec.name] = i;
+ });
+ fs.createWriteStream(__dirname + '/data/keysyms.json')
+ .write(JSON.stringify(data));
+ })
+;

0 comments on commit f0c062c

Please sign in to comment.