generate-big5-table.js 787 B

12345678910111213141516171819202122232425
  1. var http = require('http');
  2. var fs = require('fs');
  3. // BIG5
  4. var cp950_b2u = {host:'moztw.org',path:'/docs/big5/table/cp950-b2u.txt'},
  5. cp950_u2b = {host:'moztw.org',path:'/docs/big5/table/cp950-u2b.txt'},
  6. cp950_moz18_b2u = {host:'moztw.org',path:'/docs/big5/table/moz18-b2u.txt'};
  7. http.get(cp950_moz18_b2u, function(res) {
  8. var data = '';
  9. res.on('data', function(chunk) {
  10. data += chunk;
  11. });
  12. res.on('end', function() {
  13. var table = {};
  14. data = data.split('\n').slice(1);
  15. data.forEach(function(line, idx) {
  16. var pair = line.split(' ');
  17. var key = parseInt(pair[0]);
  18. var val = parseInt(pair[1]);
  19. table[key] = val;
  20. });
  21. fs.createWriteSync('encodings/table/big5.js',
  22. 'module.exports = ' + JSON.stringify(table) + ';');
  23. });
  24. });