{"name":"dom-iterator","version":"1.0.2","description":"iterator for mini-html-parser","main":"index.js","directories":{"example":"examples","test":"test"},"dependencies":{"component-props":"1.1.1","component-xor":"0.0.4"},"devDependencies":{"chalk":"2.1.0","component":"0.x","component-domify":"1.2.2","component-test":"0.1.7","mini-html-parser":"0.0.3","mocha":"1.17.1"},"scripts":{"test":"make test"},"repository":{"type":"git","url":"git+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@1.0.2","gitHead":"95a87f136ab6816c71d33e2946fac40ff6ac1b04","_nodeVersion":"20.17.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-BMelEjhy08OpoWF3v/jrPtx7PZCyP1VM9yiB7rJk19UVmt7zTN5rqoC0Jea+EyT0M6v/VokL0LxIlGLUOBJZ2g==","shasum":"6b239349ccadbd595055da5e0a7386cce9f0aa7b","tarball":"http://registry-npm.ywwl.com/dom-iterator/download/dom-iterator-1.0.2.tgz","fileCount":9,"unpackedSize":27606,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFs5p6VDJZmmIVu1C+vGi/8nLW+gK9GR9w9BuWP15m4DAiAScgDSrgwtRGVGx/IeSOD2lFyXmAc4MelL7vFl72WCbw=="}],"size":6236,"noattachment":false,"key":"/dom-iterator/-/dom-iterator-1.0.2.tgz"},"_npmUser":{"name":"mattmueller","email":"mattmuelle@gmail.com"},"maintainers":[{"name":"mattmueller","email":"mattmuelle@gmail.com"},{"name":"tootallnate","email":"nathan@tootallnate.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/dom-iterator_1.0.2_1737183270705_0.11819829224787859"},"_hasShrinkwrap":false,"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":1737183270865,"_cnpm_publish_time":1737183270865,"dist-tags":{"latest":"1.0.2"}}