echo.js 862 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict'
  2. /**
  3. * Executes functions sequentially.
  4. *
  5. * @param {function[]} arguments - Functions to execute.
  6. * @returns {void}
  7. */
  8. function flow () {
  9. if (arguments.length === 0) {
  10. return
  11. }
  12. const head = arguments[0]
  13. const rest = [].slice.call(arguments, 1)
  14. head()
  15. setTimeout(() => {
  16. flow.apply(null, rest)
  17. }, 33)
  18. }
  19. const text = String(process.argv[2])
  20. flow(
  21. () => {
  22. process.stdout.write(text)
  23. },
  24. () => {
  25. process.stdout.write(`${text}\n`)
  26. },
  27. () => {
  28. process.stdout.write(`${text}\n${text}`)
  29. },
  30. () => {
  31. process.stdout.write(`${text}\n${text}\n`)
  32. },
  33. () => {
  34. process.stdout.write(`${text}\n${text}\n${text}\n${text}\n`)
  35. },
  36. () => {
  37. process.stdout.write(`\n${text}\n${text}`)
  38. },
  39. () => {
  40. process.stdout.write(`${text}\n\n\n`)
  41. },
  42. () => {
  43. process.stdout.write(`\n${text}`)
  44. }
  45. )