{"name":"dom-iterator","version":"1.0.1","keywords":["iterator","dom","mini-html-parser"],"author":{"name":"Matthew Mueller"},"license":"MIT","_id":"dom-iterator@1.0.1","maintainers":[{"name":"mattmueller","email":"mattmuelle@gmail.com"},{"name":"tootallnate","email":"nathan@tootallnate.net"}],"homepage":"https://github.com/MatthewMueller/dom-iterator","bugs":{"url":"https://github.com/MatthewMueller/dom-iterator/issues"},"dist":{"shasum":"a123781fac4f5fbc8f719e6618daf002a00d48f7","tarball":"http://registry-npm.ywwl.com/dom-iterator/download/dom-iterator-1.0.1.tgz","fileCount":9,"integrity":"sha512-0U9Z/Br5VLzBJae84ht7m7uuM+kffWbLMYdGIki+/ugehDDLxLM4xQWRj+6GxavidrMf53nrBmu3UgNBNgrgHQ==","signatures":[{"sig":"MEUCIQCJ5jvTKHoCCiFPhayLWByAJpOgc7MaWNj9Zmtl2azKyQIgd9+zNFFWyzZvWOF5A3oqhjOMIPopTCbKL2hPpEvdkN8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":27562,"size":6208,"noattachment":false,"key":"/dom-iterator/-/dom-iterator-1.0.1.tgz"},"main":"index.js","gitHead":"d690a6ea53b215fa2193584a2e06f74dd52c9ccf","scripts":{"test":"make test"},"_npmUser":{"name":"mattmueller","email":"mattmuelle@gmail.com"},"repository":{"url":"git+https://github.com/MatthewMueller/dom-iterator.git","type":"git"},"_npmVersion":"10.8.2","description":"iterator for mini-html-parser","directories":{"test":"test","example":"examples"},"_nodeVersion":"20.17.0","dependencies":{"component-xor":"0.0.4","cheerio-select":"0.0.3","component-props":"1.1.1"},"_hasShrinkwrap":false,"devDependencies":{"chalk":"2.1.0","mocha":"1.17.1","component":"0.x","component-test":"0.1.7","component-domify":"1.2.2","mini-html-parser":"0.0.3"},"_npmOperationalInternal":{"tmp":"tmp/dom-iterator_1.0.1_1736746390386_0.948627139482368","host":"s3://npm-registry-packages-npm-production"},"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":1736746390559,"_cnpm_publish_time":1736746390559,"dist-tags":{"latest":"1.0.2"}}