Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
feat(node.js): expose node types
Browse files Browse the repository at this point in the history
  • Loading branch information
stfsy committed Sep 18, 2016
1 parent 5b10532 commit c908de6
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ const fs = require('fs-promise')
*/
class Node {

/** */
static get TYPE_COMMENT() {
return 'comment'
}
/** */
static get TYPE_TAG() {
return 'tag'
}
/** */
static get TYPE_TEXT() {
return 'text'
}

/**
* Creates a new document of a files contents
* @param {string} path path to a file
Expand Down Expand Up @@ -155,30 +168,30 @@ class Node {
*/
find(element, attrs, limit) {

if (typeof tag === 'string') {
const name = tag
if (typeof element === 'string') {
const name = element

tag = {
element = {
type: 'tag',
name: name
}
}

const elements = domUtils.filter((element) => {
const elements = domUtils.filter((el) => {
let found = true

found = Object.keys(tag).every((key) => element[key] === tag[key])
found = Object.keys(element).every((key) => el[key] === element[key])

if (found && attrs) {
found = attrs.find((attr) => {
return element.attribs[attr.key] === attr.value
return el.attribs[attr.key] === attr.value
})
}

return found
}, this._element, true, limit)

return elements.map((element) => new Node(element))
return elements.map((el) => new Node(el))
}

/**
Expand Down

0 comments on commit c908de6

Please sign in to comment.