{"name":"dom-iterator","version":"0.2.0","description":"iterator for mini-html-parser","main":"index.js","directories":{"example":"examples","test":"test"},"dependencies":{"xor":"component/xor#0.0.2","props":"component/props#1.0.3"},"devDependencies":{"mini-html-parser":"0.0.3","mocha":"~1.17.1","component-test":"~0.1.3"},"scripts":{"postinstall":"make npm","test":"make test"},"repository":{"type":"git","url":"https://github.com/MatthewMueller/dom-iterator.git"},"keywords":["iterator","dom","mini-html-parser"],"author":{"name":"Matthew Mueller"},"license":"MIT","bugs":{"url":"https://github.com/MatthewMueller/dom-iterator/issues"},"homepage":"https://github.com/MatthewMueller/dom-iterator","_id":"dom-iterator@0.2.0","dist":{"shasum":"90650f196da52c466ef88f3e883a3d2ca40f3dcc","tarball":"http://registry-npm.ywwl.com/dom-iterator/download/dom-iterator-0.2.0.tgz","integrity":"sha512-MS0tGbjQ7PIPazWua9caOlx8yPRnTJLALzlxIxP16vMl7jvZKmiuKR4nMIRP+NQY1Y75TYSs/lW2o6Z/RBkNCg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCdhGVhF3TR0iPrVq8d9Q8Y9EPkRb0TusebjHIc1uMZ5AIgO9/YSBZDIN1OB2E2fbHSJWC1P4HkjSgJo8rYVFHQPSA="}],"size":6067,"noattachment":false,"key":"/dom-iterator/-/dom-iterator-0.2.0.tgz"},"_from":".","_npmVersion":"1.3.25","_npmUser":{"name":"mattmueller","email":"mattmuelle@gmail.com"},"maintainers":[{"name":"mattmueller","email":"mattmuelle@gmail.com"}],"readme":"\n# dom-iterator\n\n  Feature-rich, well-tested Iterator for traversing DOM nodes. A better version of [NodeIterator](https://developer.mozilla.org/en-US/docs/Web/API/NodeIterator). Travels in both directions.\n\n  Can be used in node.js with [mini-html-parser](http://github.com/matthewmueller/mini-html-parser).\n\n## Installation\n\n  Install with [component(1)](http://component.io):\n\n    $ component install matthewmueller/dom-iterator\n\n  With node.js:\n\n    $ npm install dom-iterator\n\n## Example\n\n```js\nvar it = iterator(node);\nvar next;\n\nwhile (next = it.next(Node.TEXT_NODE)) {\n  console.log(next.nodeValue) // next textnodes after node\n}\n```\n\n## API\n\n### `iterator(node, root)`\n\nInitialize an iterator starting on the `node`. Optionally you can\nspecify a `root` to limit your traversal to a particular subtree.\n`root` must be either a parent or an ancestor of `node`.\n\n```js\nvar it = iterator(el.firstChild, el)\n```\n\n### `iterator#next([expr], [n])`\n\nGets the next DOM `node`. If no `node` exists, return `null`.\nYou may pass an expression `expr`, to grab the first node that\nmatches `expr`.\n\nAdditionally, you can pass a number to select the `nth` node.\nDefaults to `1` or the `1st` node.\n\n```js\nvar node = it.next()\n// select the 2nd element node we come across\nvar next = it.next(Node.ELEMENT_NODE, 2)\n```\n\nHere's a look at how the DOM is traversed:\n\n![next](https://i.cloudup.com/kl80e5axNP.png)\n\n### `iterator#prev()`, `iterator#previous()`\n\nGets the previous DOM `node`. If no `node` exists, return `null`.\nYou may pass an expression `expr`, to grab the first node that\nmatches `expr`.\n\nAdditionally, you can pass a number to select the `nth` node.\nDefaults to `1` or the `1st` node.\n\n```js\nvar node = it.prev()\n// select the 2nd element node we come across\nvar prev = it.prev(Node.ELEMENT_NODE, 2)\n```\n\nHere's a look at how the DOM is traversed:\n\n![prev](https://i.cloudup.com/EkaCyvdwvF.png)\n\n### `iterator.select(expr)`\n\niterate over nodes that pass the expression `expr`. The `expr` can be an\nenum, number, string or function. If it's a number, the `nodeType` is compared.\n\nThis function can be chained where all expressions are OR-ed.\n\n```js\nit.select(Node.ELEMENT_NODE)\n  .select(8)\n  .select('nodeValue == \"sloth\"')\n  .select(fn)\n```\n\nThis is saying:\n\n> select all element nodes or comment nodes\n> or nodes with the nodeValue \"sloth\" or\n> nodes that pass the function `fn`.\n\n### `iterator.reject(expr)`\n\niterate over nodes that do not pass the expression `expr`. The `expr` can be an\nenum, number, string or function. If it's a number, the `nodeType` is compared.\n\nThis function can be chained where all expressions are AND-ed.\n\n```js\nit.reject(Node.ELEMENT_NODE)\n  .reject(8)\n  .reject('nodeValue == \"sloth\"')\n  .reject(fn)\n```\n\nThis is saying:\n\n> reject all element nodes and comment nodes\n> and nodes with the nodeValue sloth and\n> nodes that pass the function `fn`\".\n\n### `iterator.revisit(revisit)`\n\nYou can also skip over elements you already visited, by setting `revisit` to false. By default, `revisit` is set to `true`.\n\n```js\nit.revisit(false);\n```\n\nHere's how that would change the iterator:\n\n**it.next():**\n\n![next](https://i.cloudup.com/VX6BbZEuzf.png)\n\n**it.prev()**\n\n![prev](https://i.cloudup.com/NEKe6F4EUX.png)\n\n### `iterator.opening()`\n\nJump to the opening tag of an element. This is the default.\n\n```js\nvar dom = domify('<em>hi</em>');\nvar it = it(dom).opening()\nit.next() // 'hi'\n```\n\n### `iterator.closing()`\n\nJump to the closing tag of an element\n\n```js\nvar dom = domify('<em>hi</em>');\nvar it = it(dom).closing()\nit.prev() // 'hi'\n```\n\n### `iterator.peek([expr], [n])`\n\nSometimes you want to peek on the following or previous node without actually visiting it. With `peek` you can peek forward or backwards `n` steps. If no `n` is given, peek forward 1 step.\n\nPeaking forward:\n\n```js\nit.peek(); // peek forward 1\nit.peek(3); // peek forward 3 steps\n```\n\nPeaking backwards:\n\n```js\nit.peek(Node.ELEMENT_NODE, -3) // peek backwards 3 steps, only selecting element nodes\n```\n\n### `iterator.reset([newNode])`\n\nReset the iterator to the original `node`. Optionally pass a `newNode` to start at.\n\n```js\nit.reset();\n```\n\n### `iterator.use(fn)`\n\nAdd a plugin to the iterator.\n\n## Run Tests\n\nOn the server:\n\n```js\nnpm install\nmake test\n```\n\nOr in the browser:\n\n```js\nnpm install\nmake test-browser\n```\n\n## License\n\n  MIT\n","publish_time":1392041876977,"_cnpm_publish_time":1392041876977,"dist-tags":{"latest":"1.0.2"}}