Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

printj.njs 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env node
  2. /* printj.js (C) 2016-present SheetJS -- http://sheetjs.com */
  3. /* eslint-env node */
  4. /* vim: set ts=2 ft=javascript: */
  5. /*jshint node:true, evil:true */
  6. var X = require("../"), argv = process.argv;
  7. function help() {
  8. [
  9. "usage: printj [options] <format> [args...]",
  10. "",
  11. "Options:",
  12. " -h, --help output usage information",
  13. " -d, --dump print debug information about format string",
  14. "",
  15. "Arguments are treated as strings unless prefaced by a type indicator:",
  16. " n:<integer> call parseInt (ex. n:3 -> 3)",
  17. " f:<float> call parseFloat (ex. f:3.1 -> 3.1)",
  18. ' b:<boolean> false when lowercase value is "FALSE" or "0", else true',
  19. " s:<string> interpret as string (ex. s:n:3 -> \"n:3\")",
  20. " j:<JSON> interpret as an object using JSON.parse",
  21. " e:<JS> evaluate argument (ex. e:1+1 -> 2, e:\"1\"+1 -> \"11\")",
  22. "",
  23. "samples:",
  24. " $ printj '|%02hhx%d|' n:50 e:0x7B # |32123|",
  25. " $ printj '|%2$d + %3$d is %1$d|' e:1+2 n:1 n:2 # |1 + 2 is 3| ",
  26. " $ printj '|%s is %s|' s:1+2 e:1+2 # |1+2 is 3|",
  27. " $ printj '|%c %c|' s:69 n:69 # |6 E|",
  28. "",
  29. "Support email: dev@sheetjs.com",
  30. "Web Demo: http://oss.sheetjs.com/printj/"
  31. ].forEach(function(l) { console.log(l); });
  32. return 0;
  33. }
  34. function parse_arg(arg/*:string*/)/*:any*/ {
  35. var m = arg.substr(2), p/*:number*/ = 0;
  36. if(arg.charCodeAt(1) === 58) switch((p = arg.charCodeAt(0))) {
  37. case /*n*/ 110: return parseInt(m, 10);
  38. case /*f*/ 102: return parseFloat(m);
  39. case /*b*/ 98: return !(m.toUpperCase() === "FALSE" || m === "0");
  40. case /*j*/ 106: return JSON.parse(m);
  41. case /*e*/ 101: return eval(m);
  42. case /*s*/ 115: return m;
  43. }
  44. void p;
  45. return arg;
  46. }
  47. var args/*:Array<any>*/ = [];
  48. var fmt = "", n = 0;
  49. for(var i = 2; i < argv.length; ++i) switch(argv[i]) {
  50. case "--help": case "-h": process.exit(help()); break;
  51. case "--dump": case "-d": if(fmt.length===0) fmt = argv[++i]; process.exit(dump(fmt)); break;
  52. default: if(n++ === 0) fmt = argv[i]; else args.push(parse_arg(argv[i]));
  53. }
  54. console.log(X.vsprintf(fmt, args));
  55. process.exit(0);
  56. function dump(fmt/*:string*/)/*:number*/ {
  57. if(!fmt) { console.error("printj: missing format argument"); return 1; }
  58. X._tokenize(fmt).forEach(function(x){console.log(x);});
  59. return 0;
  60. }