index.js 628 B

12345678910111213141516171819
  1. const beautify = require('pretty')
  2. const isHtmlString = received => received && typeof received === 'string' && received[0] === '<'
  3. const isVueWrapper = received => (
  4. received &&
  5. typeof received === 'object' &&
  6. typeof received.isVueInstance === 'function'
  7. )
  8. module.exports = {
  9. test (received) {
  10. return isHtmlString(received) || isVueWrapper(received)
  11. },
  12. print (received) {
  13. const html = (isVueWrapper(received) ? received.html() : received) || ''
  14. const removedServerRenderedText = html.replace(/ data-server-rendered="true"/, '')
  15. return beautify(removedServerRenderedText, { indent_size: 2 })
  16. }
  17. }