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.

implementation.js 611B

12345678910111213141516171819202122
  1. 'use strict'
  2. const implementation = {
  3. isTag: node => node !== undefined && 'name' in node,
  4. getAttributeValue: ( elem, name ) => {
  5. if( implementation.isTag( elem ) && elem.attribs ) return elem.attribs[ name ]
  6. },
  7. getChildren: node => node.children,
  8. getName: elem => {
  9. if( implementation.isTag( elem ) ) return elem.name
  10. },
  11. getParent: node => node.parent,
  12. getText: node => node.children.map( child => {
  13. if( child.text ) return child.text
  14. if( implementation.isTag( child ) ) return implementation.getText( child )
  15. return ''
  16. }).join( '' )
  17. }
  18. module.exports = implementation