util.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use strict";
  2. const assert = require("assert");
  3. const fs = require("fs");
  4. const path = require("path");
  5. const process = require("process");
  6. const child_process = require("child_process");
  7. const CYAN_FMT = "\x1b[36m%s\x1b[0m";
  8. function hex(n, pad)
  9. {
  10. pad = pad || 0;
  11. let s = n.toString(16).toUpperCase();
  12. while(s.length < pad) s = "0" + s;
  13. return s;
  14. }
  15. function mkdirpSync(dir)
  16. {
  17. fs.mkdirSync(dir, { recursive: true });
  18. }
  19. function get_switch_value(arg_switch)
  20. {
  21. const argv = process.argv;
  22. const switch_i = argv.indexOf(arg_switch);
  23. const val_i = switch_i + 1;
  24. if(switch_i > -1 && val_i < argv.length)
  25. {
  26. return argv[switch_i + 1];
  27. }
  28. return null;
  29. }
  30. function get_switch_exist(arg_switch)
  31. {
  32. return process.argv.includes(arg_switch);
  33. }
  34. function finalize_table_rust(out_dir, name, contents)
  35. {
  36. const file_path = path.join(out_dir, name);
  37. fs.writeFileSync(file_path, contents);
  38. console.log(CYAN_FMT, `[+] Wrote table ${name}.`);
  39. }
  40. module.exports = {
  41. hex,
  42. mkdirpSync,
  43. get_switch_value,
  44. get_switch_exist,
  45. finalize_table_rust,
  46. };