bodyLog.mjs

  1. import map from 'lodash-es/map.js'
  2. import o2j from './o2j.mjs'
  3. import htmlEncode from './htmlEncode.mjs'
  4. /**
  5. * 前端顯示log訊息,預設插入至body
  6. *
  7. * Unit Test: {@link https://github.com/yuda-lyu/wsemi/blob/master/test/bodyLog.test.mjs Github}
  8. * @memberOf wsemi
  9. * @param {String} c 輸入字串
  10. * @example
  11. *
  12. * bodyLog('show訊息')
  13. * // => 由html顯示'show訊息'
  14. *
  15. */
  16. function bodyLog() {
  17. //join arguments
  18. let as = map(arguments, function(v) {
  19. return o2j(v)
  20. }).join(', ')
  21. //msg
  22. let s = `
  23. <div style="padding:5px; font-size:10pt; font-family:Microsoft JhengHei, Helvetica;">
  24. <span style="color:#f26;">log: </span>
  25. <code>${htmlEncode(as)}</code>
  26. </div>
  27. `
  28. //append
  29. document.querySelector('body').insertAdjacentHTML('beforeend', s)
  30. }
  31. export default bodyLog