blob: c88985b8cf55ea283ff13400b76dd19e104c4f0e [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict'
2
3const implementation = {
4 isTag: node => node !== undefined && 'name' in node,
5 getAttributeValue: ( elem, name ) => {
6 if( implementation.isTag( elem ) && elem.attribs ) return elem.attribs[ name ]
7 },
8 getChildren: node => node.children,
9 getName: elem => {
10 if( implementation.isTag( elem ) ) return elem.name
11 },
12 getParent: node => node.parent,
13 getText: node => node.children.map( child => {
14 if( child.text ) return child.text
15
16 if( implementation.isTag( child ) ) return implementation.getText( child )
17
18 return ''
19 }).join( '' )
20}
21
22module.exports = implementation