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.

data.js 559B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict'
  2. const walk = ( node, parent, cb ) => {
  3. cb( node, parent )
  4. if( Array.isArray( node.children ) )
  5. node.children.forEach( child => walk( child, node, cb ) )
  6. }
  7. const data = {
  8. name: 'div',
  9. attribs: {
  10. id: 'container',
  11. class: 'message'
  12. },
  13. children: [
  14. {
  15. name: 'strong',
  16. attribs: {
  17. class: 'message'
  18. },
  19. children: [
  20. { text: 'Hello' }
  21. ]
  22. },
  23. { text: ', World!' }
  24. ]
  25. }
  26. walk( data, null, ( node, parent ) => {
  27. if( parent ) node.parent = parent
  28. })
  29. module.exports = [ data ]