{"name":"@asamuzakjp/dom-selector","version":"2.1.0-b.1","author":{"name":"asamuzaK"},"license":"MIT","_id":"@asamuzakjp/dom-selector@2.1.0-b.1","maintainers":[{"name":"asamuzakjp","email":"info@asamuzak.jp"}],"homepage":"https://github.com/asamuzaK/domSelector#readme","bugs":{"url":"https://github.com/asamuzaK/domSelector/issues"},"dist":{"shasum":"97b3c20a5d9ea97bd73bb648c06b79666a688107","tarball":"http://registry-npm.ywwl.com/@asamuzakjp/dom-selector/download/@asamuzakjp/dom-selector-2.1.0-b.1.tgz","fileCount":28,"integrity":"sha512-o32BsuH5UgIM+ShPnYh2awZRvs8qepRt6foK0Ru764eKyRwvJA/4VE1xtoPMZk2AsJywmIDEx2x26ulWw7jAfw==","signatures":[{"sig":"MEUCIQD+r5g5sqqw+SQ5u65QshJm1b2WIfoB4dMIM+nQbUjuggIgJ2cCFyeq/z6LqacQs/7Vumc47lnQhlFRnn9bfqPnH4I=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":368913,"size":75349,"noattachment":false,"key":"/@asamuzakjp/dom-selector/-/@asamuzakjp/dom-selector-2.1.0-b.1.tgz"},"type":"module","types":"types/index.d.ts","readme":"# DOM Selector\n\n[![build](https://github.com/asamuzaK/domSelector/actions/workflows/node.js.yml/badge.svg)](https://github.com/asamuzaK/domSelector/actions/workflows/node.js.yml)\n[![CodeQL](https://github.com/asamuzaK/domSelector/actions/workflows/codeql.yml/badge.svg)](https://github.com/asamuzaK/domSelector/actions/workflows/codeql.yml)\n[![npm (scoped)](https://img.shields.io/npm/v/@asamuzakjp/dom-selector)](https://www.npmjs.com/package/@asamuzakjp/dom-selector)\n\nA CSS selector engine.\n\n## Install\n\n```console\nnpm i @asamuzakjp/dom-selector\n```\n\n## Usage\n\n```javascript\nimport {\n  matches, closest, querySelector, querySelectorAll\n} from '@asamuzakjp/dom-selector';\n```\n\n<!-- Generated by documentation.js. Update this documentation by updating the source code. -->\n\n### matches(selector, node, opt)\n\nmatches - same functionality as [Element.matches()][64]\n\n#### Parameters\n\n- `selector` **[string][59]** CSS selector\n- `node` **[object][60]** Element node\n- `opt` **[object][60]?** options\n  - `opt.noexcept` **[boolean][61]?** no exception\n  - `opt.warn` **[boolean][61]?** console warn e.g. unsupported pseudo-class\n\nReturns **[boolean][61]** `true` if matched, `false` otherwise\n\n\n### closest(selector, node, opt)\n\nclosest - same functionality as [Element.closest()][65]\n\n#### Parameters\n\n- `selector` **[string][59]** CSS selector\n- `node` **[object][60]** Element node\n- `opt` **[object][60]?** options\n  - `opt.noexcept` **[boolean][61]?** no exception\n  - `opt.warn` **[boolean][61]?** console warn e.g. unsupported pseudo-class\n\nReturns **[object][60]?** matched node\n\n\n### querySelector(selector, node, opt)\n\nquerySelector - same functionality as [Document.querySelector()][66], [DocumentFragment.querySelector()][67], [Element.querySelector()][68]\n\n#### Parameters\n\n- `selector` **[string][59]** CSS selector\n- `node` **[object][60]** Document, DocumentFragment or Element node\n- `opt` **[object][60]?** options\n  - `opt.noexcept` **[boolean][61]?** no exception\n  - `opt.warn` **[boolean][61]?** console warn e.g. unsupported pseudo-class\n\nReturns **[object][60]?** matched node\n\n\n### querySelectorAll(selector, node, opt)\n\nquerySelectorAll - same functionality as [Document.querySelectorAll()][69], [DocumentFragment.querySelectorAll()][70], [Element.querySelectorAll()][71]  \n**NOTE**: returns Array, not NodeList\n\n#### Parameters\n\n- `selector` **[string][59]** CSS selector\n- `node` **[object][60]** Document, DocumentFragment or Element node\n- `opt` **[object][60]?** options\n  - `opt.noexcept` **[boolean][61]?** no exception\n  - `opt.warn` **[boolean][61]?** console warn e.g. unsupported pseudo-class\n\nReturns **[Array][62]&lt;([object][60] \\| [undefined][63])>** array of matched nodes\n\n\n## Supported CSS selectors\n\n|Pattern|Supported|Note|\n|:--------|:-------:|:--------|\n|\\*|✓| |\n|ns\\|E|✓| |\n|\\*\\|E|✓| |\n|\\|E|✓| |\n|E|✓| |\n|E:not(s1, s2, …)|✓| |\n|E:is(s1, s2, …)|✓| |\n|E:where(s1, s2, …)|✓| |\n|E:has(rs1, rs2, …)|✓| |\n|E.warning|✓| |\n|E#myid|✓| |\n|E\\[foo\\]|✓| |\n|E\\[foo=\"bar\"\\]|✓| |\n|E\\[foo=\"bar\"&nbsp;i\\]|✓| |\n|E\\[foo=\"bar\"&nbsp;s\\]|✓| |\n|E\\[foo~=\"bar\"\\]|✓| |\n|E\\[foo^=\"bar\"\\]|✓| |\n|E\\[foo$=\"bar\"\\]|✓| |\n|E\\[foo*=\"bar\"\\]|✓| |\n|E\\[foo\\|=\"en\"\\]|✓| |\n|E:defined|Unsupported| |\n|E:dir(ltr)|✓| |\n|E:lang(en)|Partially supported|Comma-separated list of language codes, e.g. `:lang(en, fr)`, is not yet supported.|\n|E:any&#8209;link|✓| |\n|E:link|✓| |\n|E:visited|✓|Returns `false` or `null` to prevent fingerprinting.|\n|E:local&#8209;link|✓| |\n|E:target|✓| |\n|E:target&#8209;within|✓| |\n|E:scope|✓| |\n|E:current|Unsupported| |\n|E:current(s)|Unsupported| |\n|E:past|Unsupported| |\n|E:future|Unsupported| |\n|E:active|Unsupported| |\n|E:hover|Unsupported| |\n|E:focus|✓| |\n|E:focus&#8209;within|✓| |\n|E:focus&#8209;visible|Unsupported| |\n|E:enabled<br>E:disabled|✓| |\n|E:read&#8209;write<br>E:read&#8209;only|✓| |\n|E:placeholder&#8209;shown|✓| |\n|E:default|✓| |\n|E:checked|✓| |\n|E:indeterminate|✓| |\n|E:valid<br>E:invalid|✓| |\n|E:required<br>E:optional|✓| |\n|E:blank|Unsupported| |\n|E:user&#8209;invalid|Unsupported| |\n|E:root|✓| |\n|E:empty|✓| |\n|E:nth&#8209;child(n&nbsp;[of&nbsp;S]?)|✓| |\n|E:nth&#8209;last&#8209;child(n&nbsp;[of&nbsp;S]?)|✓| |\n|E:first&#8209;child|✓| |\n|E:last&#8209;child|✓| |\n|E:only&#8209;child|✓| |\n|E:nth&#8209;of&#8209;type(n)|✓| |\n|E:nth&#8209;last&#8209;of&#8209;type(n)|✓| |\n|E:first&#8209;of&#8209;type|✓| |\n|E:last&#8209;of&#8209;type|✓| |\n|E:only&#8209;of&#8209;type|✓| |\n|E&nbsp;F|✓| |\n|E > F|✓| |\n|E + F|✓| |\n|E ~ F|✓| |\n|F \\|\\| E|Unsupported| |\n|E:nth&#8209;col(n)|Unsupported| |\n|E:nth&#8209;last&#8209;col(n)|Unsupported| |\n|:host|✓| |\n|:host(s)|✓| |\n|:host&#8209;context(s)|✓| |\n\n\n## Monkey patch jsdom\n\n``` javascript\nimport { JSDOM } from 'jsdom';\nimport {\n  closest, matches, querySelector, querySelectorAll\n} from '@asamuzakjp/dom-selector';\n\nconst dom = new JSDOM('', {\n  runScripts: 'dangerously',\n  url: 'http://localhost/',\n  beforeParse: window => {\n    window.Element.prototype.matches = function (...args) {\n      if (!args.length) {\n        throw new window.TypeError('1 argument required, but only 0 present.');\n      }\n      const [selector] = args;\n      return matches(selector, this);\n    };\n    window.Element.prototype.closest = function (...args) {\n      if (!args.length) {\n        throw new window.TypeError('1 argument required, but only 0 present.');\n      }\n      const [selector] = args;\n      return closest(selector, this);\n    };\n    window.Document.prototype.querySelector = function (...args) {\n      if (!args.length) {\n        throw new window.TypeError('1 argument required, but only 0 present.');\n      }\n      const [selector] = args;\n      return querySelector(selector, this);\n    };\n    window.DocumentFragment.prototype.querySelector = function (...args) {\n      if (!args.length) {\n        throw new window.TypeError('1 argument required, but only 0 present.');\n      }\n      const [selector] = args;\n      return querySelector(selector, this);\n    };\n    window.Element.prototype.querySelector = function (...args) {\n      if (!args.length) {\n        throw new window.TypeError('1 argument required, but only 0 present.');\n      }\n      const [selector] = args;\n      return querySelector(selector, this);\n    };\n    window.Document.prototype.querySelectorAll = function (...args) {\n      if (!args.length) {\n        throw new window.TypeError('1 argument required, but only 0 present.');\n      }\n      const [selector] = args;\n      return querySelectorAll(selector, this);\n    };\n    window.DocumentFragment.prototype.querySelectorAll = function (...args) {\n      if (!args.length) {\n        throw new window.TypeError('1 argument required, but only 0 present.');\n      }\n      const [selector] = args;\n      return querySelectorAll(selector, this);\n    };\n    window.Element.prototype.querySelectorAll = function (...args) {\n      if (!args.length) {\n        throw new window.TypeError('1 argument required, but only 0 present.');\n      }\n      const [selector] = args;\n      return querySelectorAll(selector, this);\n    };\n  }\n});\n```\n\n## Performance\n\n### matches()\n\n|Selector|jsdom v24.0.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result|\n|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------|\n|simple selector:<br>`matches('.content')`|2,730,719 ops/sec ±0.80%|1,669,966 ops/sec ±0.28%|657,226 ops/sec ±1.30%|191,661 ops/sec ±0.17%|jsdom is the fastest and 14.2 times faster than patched-jsdom.|\n|compound selector:<br>`matches('p.content[id]:only-child')`|1,153,187 ops/sec ±0.26%|470,767 ops/sec ±0.85%|309,344 ops/sec ±0.18%|89,231 ops/sec ±0.70%|jsdom is the fastest and 12.9 times faster than patched-jsdom.|\n|complex selector:<br>`matches('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|165,982 ops/sec ±0.46%|N/A|72,727 ops/sec ±0.25%|21,674 ops/sec ±1.35%|jsdom is the fastest and 7.7 times faster than patched-jsdom.|\n\n### closest()\n\n|Selector|jsdom v24.0.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result|\n|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------|\n|simple selector:<br>`closest('.container')`|578,462 ops/sec ±1.64%|361,946 ops/sec ±2.15%|397,660 ops/sec ±1.70%|66,355 ops/sec ±1.68%|jsdom is the fastest and 8.7 times faster than patched-jsdom.|\n|compound selector:<br>`closest('div.container[id]:not(.box)')`|216,725 ops/sec ±1.66%|79,273 ops/sec ±1.88%|169,185 ops/sec ±1.81%|33,135 ops/sec ±0.98%|jsdom is the fastest and 6.5 times faster than patched-jsdom.|\n|complex selector:<br>`closest('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|159,848 ops/sec ±0.29%|N/A|72,070 ops/sec ±1.68%|17,559 ops/sec ±2.09%|jsdom is the fastest and 9.1 times faster than patched-jsdom.|\n\n### querySelector()\n\n|Selector|jsdom v24.0.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result|\n|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------|\n|simple selector:<br>`querySelector('.content')`|3,326 ops/sec ±1.31%|342,846 ops/sec ±1.70%|322,199 ops/sec ±2.38%|70,933 ops/sec ±1.88%|happydom is the fastest and 4.8 times faster than patched-jsdom.|\n|compound selector:<br>`querySelector('p.content[id]:only-child')`|1,309 ops/sec ±1.19%|382,636 ops/sec ±1.56%|252,823 ops/sec ±2.03%|47,759 ops/sec ±1.44%|happydom is the fastest and 8.0 times faster than patched-jsdom.|\n|complex selector:<br>`querySelector('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|242 ops/sec ±0.16%|N/A|1,342 ops/sec ±0.37%|911 ops/sec ±1.80%|linkedom is the fastest and 1.5 times faster than patched-jsdom.|\n\n### querySelectorAll()\n\n|Selector|jsdom v24.0.0 (nwsapi)|happy-dom|linkeDom|patched-jsdom (dom-selector)|Result|\n|:-----------|:-----------|:-----------|:-----------|:-----------|:-----------|\n|simple selector:<br>`querySelectorAll('.content')`|3,090 ops/sec ±1.08%|778 ops/sec ±1.56%|1,203 ops/sec ±1.37%|2,483 ops/sec ±0.90%|jsdom is the fastest and 1.2 times faster than patched-jsdom.|\n|compound selector:<br>`querySelectorAll('p.content[id]:only-child')`|1,280 ops/sec ±0.96%|915 ops/sec ±1.57%|1,029 ops/sec ±0.89%|151 ops/sec ±0.91%|jsdom is the fastest and 8.5 times faster than patched-jsdom.|\n|complex selector:<br>`querySelectorAll('.box:first-child ~ .box:nth-of-type(4n+1) + .box[id] .block.inner > .content')`|245 ops/sec ±0.26%|N/A|438 ops/sec ±1.42%|904 ops/sec ±1.49%|patched-jsdom is the fastest.|\n\n\n## Acknowledgments\n\nThe following resources have been of great help in the development of the DOM Selector.\n\n- [CSSTree](https://github.com/csstree/csstree)\n- [selery](https://github.com/danburzo/selery)\n- [jsdom](https://github.com/jsdom/jsdom)\n\n\n---\nCopyright (c) 2023 [asamuzaK (Kazz)](https://github.com/asamuzaK/)\n\n\n[1]: #matches\n[2]: #parameters\n[3]: #closest\n[4]: #parameters-1\n[5]: #queryselector\n[6]: #parameters-2\n[7]: #queryselectorall\n[8]: #parameters-3\n[59]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String\n[60]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object\n[61]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean\n[62]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array\n[63]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined\n[64]: https://developer.mozilla.org/docs/Web/API/Element/matches\n[65]: https://developer.mozilla.org/docs/Web/API/Element/closest\n[66]: https://developer.mozilla.org/docs/Web/API/Document/querySelector\n[67]: https://developer.mozilla.org/docs/Web/API/DocumentFragment/querySelector\n[68]: https://developer.mozilla.org/docs/Web/API/Element/querySelector\n[69]: https://developer.mozilla.org/docs/Web/API/Document/querySelectorAll\n[70]: https://developer.mozilla.org/docs/Web/API/DocumentFragment/querySelectorAll\n[71]: https://developer.mozilla.org/docs/Web/API/Element/querySelectorAll\n","exports":{"import":"./src/index.js","require":"./dist/cjs/index.js"},"gitHead":"a95f4bf8464e0ef389a2f8b85d58c3850177c382","scripts":{"tsc":"npx tsc","lint":"eslint --fix .","test":"c8 --reporter=text mocha --exit test/**/*.test.js","bench":"node benchmark/bench.js","build":"npm run tsc && npm run lint && npm test && npm run compat","compat":"esbuild --format=cjs --platform=node --outdir=dist/cjs/ --minify --sourcemap src/**/*.js","test-wpt":"node test/wpt/wpt-runner.js","update-wpt":"git submodule update --init --recursive --remote","bench-sizzle":"node benchmark/bench-sizzle.js"},"_npmUser":{"name":"asamuzakjp","email":"info@asamuzak.jp"},"repository":{"url":"git+https://github.com/asamuzaK/domSelector.git","type":"git"},"_npmVersion":"10.2.1","description":"A CSS selector engine.","directories":{},"_nodeVersion":"20.10.0","dependencies":{"bidi-js":"^1.0.3","css-tree":"^2.3.1","is-potential-custom-element-name":"^1.0.1"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"c8":"^9.1.0","chai":"^5.0.0","jsdom":"24.0.0","mocha":"^10.2.0","sinon":"^17.0.1","eslint":"^8.56.0","esbuild":"^0.19.11","linkedom":"^0.16.8","benchmark":"^2.1.4","commander":"^11.1.0","happy-dom":"^13.2.1","typescript":"^5.3.3","wpt-runner":"^5.0.0","@types/css-tree":"^2.3.5","eslint-plugin-jsdoc":"^48.0.2","eslint-plugin-import":"^2.29.1","eslint-plugin-regexp":"^2.2.0","eslint-plugin-unicorn":"^50.0.1","eslint-config-standard":"^17.1.0"},"_npmOperationalInternal":{"tmp":"tmp/dom-selector_2.1.0-b.1_1706015457311_0.5632356783375272","host":"s3://npm-registry-packages"},"publish_time":1706015457501,"_cnpm_publish_time":1706015457501,"dist-tags":{"beta":"0.2.2","dev":"6.5.0-a.16","latest":"10.0.5","next":"8.0.0-a.2"}}