Skip to content

Commit 3669288

Browse files
committed
Document node types.
1 parent d68bbc9 commit 3669288

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

API.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# API Documentation
22

3+
*Please use only this documented API when working with the parser. Methods
4+
not documented here are subject to change at any point.*
5+
36
## `parser` function
47

58
This is the module's main entry point.
@@ -154,3 +157,56 @@ parser.universal();
154157
Arguments:
155158

156159
* `props (object)`: The new node's properties.
160+
161+
## Node types
162+
163+
### `node.type`
164+
165+
A string representation of the selector type. It can be one of the following;
166+
`attribute`, `class`, `combinator`, `comment`, `id`, `pseudo`, `root`,
167+
`selector`, `tag`, or `universal`.
168+
169+
```js
170+
parser.attribute({attribute: 'href'}).type;
171+
// => 'attribute'
172+
173+
### `node.parent`
174+
175+
Returns the parent node.
176+
177+
```js
178+
root.nodes[0].parent === root;
179+
```
180+
181+
### `node.toString()`, `String(node)`, or `'' + node`
182+
183+
Returns a string representation of the node.
184+
185+
```js
186+
var id = parser.id({value: 'search'});
187+
console.log(String(id));
188+
// => #search
189+
```
190+
191+
### `node.next()` & `node.prev()`
192+
193+
Returns the next/previous child of the parent node.
194+
195+
```js
196+
var next = id.next();
197+
if (next && next.type !== 'combinator') {
198+
throw new Error('Qualified IDs are not allowed!');
199+
}
200+
```
201+
202+
### `node.removeSelf()`
203+
204+
Removes the node from its parent node.
205+
206+
```js
207+
if (node.type === 'id') {
208+
node.removeSelf();
209+
}
210+
```
211+
212+

0 commit comments

Comments
 (0)