Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. const printer = require('node-thermal-printer')
  2. const {json} = require('micro')
  3.  
  4. printer.init({
  5. type: 'epson',
  6. interface: '/dev/usb/lp0',
  7. width: 40,
  8. })
  9.  
  10. printer.isPrinterConnected((isConnected) => {
  11. printer.execute((err) => {})
  12. })
  13.  
  14. printer.setTextNormal()
  15. printer.bold(true)
  16.  
  17. module.exports = async (req, res) => {
  18. const {tasks} = await json(req)
  19.  
  20. tasks.map(printTask)
  21. res.end('Printing tasks :D')
  22. }
  23.  
  24. function printTask(taskString) {
  25. let hasPrintedFirstLine = false
  26. const chars = taskString.split('')
  27.  
  28. const print = (str) => {
  29. if (hasPrintedFirstLine) {
  30. printer.println(` ${str}`)
  31. } else {
  32. printer.println(`( ): ${str}`)
  33. }
  34. }
  35.  
  36. chars.reduce((line, char, i) => {
  37. if (i === chars.length - 1) {
  38. print(line + char)
  39. hasPrintedFirstLine = true
  40. }
  41. if (line.length >= 26) {
  42. print(line)
  43. hasPrintedFirstLine = true
  44. return char
  45. }
  46. return line + char
  47. })
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement