generate.js 1018 B

123456789101112131415161718192021222324252627282930313233
  1. var util = require("util"),
  2. fs = require("fs"),
  3. _ = require("underscore");
  4. // Load emojis
  5. var emojis = require("../../../emoji_strategy.json");
  6. // Generate Objective-C mapping
  7. var mapping = _(emojis).map(function(data, shortname) {
  8. // Get chars
  9. var chars = _(data.unicode.split("-")).map(function (code) {
  10. // Handle invalid unicode char for C99
  11. // http://c0x.coding-guidelines.com/6.4.3.html
  12. if (code < 160) {
  13. return String.fromCharCode(parseInt(code, 16));
  14. }
  15. return "\\u{" + Array(8 - code.length + 1).join("0") + code + "}";
  16. });
  17. return '"' + shortname + '": "' + chars.join('') + '",';
  18. }).join("\n ");
  19. // Generate Objective-C class from template
  20. var input = fs.readFileSync("./Emojione.swift");
  21. var output = _(input.toString()).template()({ mapping: mapping });
  22. // Write Objective-C class to file
  23. var output_path = "../src/Emojione.swift";
  24. fs.writeFileSync(output_path, output);
  25. console.log("Generated " + output_path);