{"name":"hast-util-select","version":"5.0.5","description":"hast utility for `querySelector`, `querySelectorAll`, and `matches`","license":"MIT","keywords":["unist","hast","hast-util","util","utility","html","css","select","selectall","selector","query","match","matches"],"repository":{"type":"git","url":"git+https://github.com/syntax-tree/hast-util-select.git"},"bugs":{"url":"https://github.com/syntax-tree/hast-util-select/issues"},"funding":{"type":"opencollective","url":"https://opencollective.com/unified"},"author":{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"},"contributors":[{"name":"Titus Wormer","email":"tituswormer@gmail.com","url":"https://wooorm.com"}],"sideEffects":false,"type":"module","main":"index.js","types":"index.d.ts","dependencies":{"@types/hast":"^2.0.0","@types/unist":"^2.0.0","bcp-47-match":"^2.0.0","comma-separated-tokens":"^2.0.0","css-selector-parser":"^1.0.0","direction":"^2.0.0","hast-util-has-property":"^2.0.0","hast-util-to-string":"^2.0.0","hast-util-whitespace":"^2.0.0","not":"^0.1.0","nth-check":"^2.0.0","property-information":"^6.0.0","space-separated-tokens":"^2.0.0","unist-util-visit":"^4.0.0","zwitch":"^2.0.0"},"devDependencies":{"@types/node":"^18.0.0","c8":"^7.0.0","hastscript":"^7.0.0","prettier":"^2.0.0","remark-cli":"^11.0.0","remark-preset-wooorm":"^9.0.0","type-coverage":"^2.0.0","typescript":"^4.0.0","unist-builder":"^3.0.0","xo":"^0.53.0"},"scripts":{"prepack":"npm run build && npm run format","build":"tsc --build --clean && tsc --build && type-coverage","format":"remark . -qfo && prettier . -w --loglevel warn && xo --fix","test-api":"node --conditions development test/index.js","test-coverage":"c8 --check-coverage --100 --reporter lcov npm run test-api","test":"npm run build && npm run format && npm run test-coverage"},"prettier":{"tabWidth":2,"useTabs":false,"singleQuote":true,"bracketSpacing":false,"semi":false,"trailingComma":"none"},"xo":{"prettier":true,"rules":{"max-params":"off"},"overrides":[{"files":["test/**/*.js"],"rules":{"no-await-in-loop":0}}]},"remarkConfig":{"plugins":["preset-wooorm"]},"typeCoverage":{"atLeast":100,"detail":true,"strict":true},"gitHead":"c523d66affafceff4c2b6099b81fe1b2abb56fc0","homepage":"https://github.com/syntax-tree/hast-util-select#readme","_id":"hast-util-select@5.0.5","_nodeVersion":"19.3.0","_npmVersion":"9.2.0","dist":{"integrity":"sha512-QQhWMhgTFRhCaQdgTKzZ5g31GLQ9qRb1hZtDPMqQaOhpLBziWcshUS0uCR5IJ0U1jrK/mxg35fmcq+Dp/Cy2Aw==","shasum":"be9ccb71d2278681ca024727f12abd4f93b3e9bc","tarball":"http://registry-npm.ywwl.com/hast-util-select/download/hast-util-select-5.0.5.tgz","fileCount":27,"unpackedSize":70581,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDpB1XUWhzdy+QT5Ydw3WigNbGD34InjxPCuVzoovaO9gIgZl+RCZf2GFqFK9twE7EW3YDM6i9oBooqtiCasHRYmME="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjzSO2ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqIbA//f9f6E6oymXe0d+bfe4q1wN7iOwB4mI1xrHo2GuRTVpDYnxvX\r\nQ44aGS8B6WMYxQxfXxqkHOA5MlzVIgEvgxzF0g+MbIyvQRgNeFPhmzZfIyZs\r\nVwrKItJhon7GCLtc1Wql2mR2+gZsiiBjjnS4M1lRMiGeci88rvQgc6AntZ2a\r\nPpMtAXGI0ZPf+LLP/4l5nlgdqBhKFOD3HTXKdsPcxv0ZU6YRZ9cK5C6UeVzi\r\n37NBjty69llR/OrSAGzR6BqYiRkmJMq8FcYFykG3rL7O0Va4fQW1aCsABuod\r\n5iVO/Sxu8x64t5LnitmylN6wv9mXLUyLZRr8aFytbhk87EdK8vS3uUG5lcvw\r\n5a98jg+ZebT2drKHcYwLzIJG4aLtMao/pa9kHFhjT8qld6JTHCqAjX7PsN3v\r\n26I4hT1ATrpQZbtXWs6Iny9+ZOXsgxpzvwAGtQ0QotgQLhURhzSuMUNE/EhH\r\nQyd24odnmZN0ZUpLdsTSn2SJzHj75OUoOCQXP/lbFyad7CZnmtHBfKsVnpH0\r\nmWG5UfhlhzQRQWXP8q3KdaWObTE9unXTOiLuPBAmc4Z7NjJToX5jnxb15l5X\r\npwmaSPmjOtoP3CKMyl55PrLc14qQhqlAOPeXUqxe/bjdMkZVzcg8TV2bOUsb\r\nwsUJyh8U0l2PrdoaomBsCKVEIv2n/b4DU5k=\r\n=iqYG\r\n-----END PGP SIGNATURE-----\r\n","size":16358,"noattachment":false,"key":"/hast-util-select/-/hast-util-select-5.0.5.tgz"},"_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"},{"name":"kmck","email":"keith@mcknig.ht"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hast-util-select_5.0.5_1674388406584_0.050506893486334414"},"_hasShrinkwrap":false,"readme":"# hast-util-select\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n[hast][] utility with equivalents for `matches`, `querySelector`,\nand `querySelectorAll`.\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`matches(selector, node[, space])`](#matchesselector-node-space)\n    *   [`select(selector, tree[, space])`](#selectselector-tree-space)\n    *   [`selectAll(selector, tree[, space])`](#selectallselector-tree-space)\n    *   [`Space`](#space)\n*   [Support](#support)\n*   [Unsupported](#unsupported)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package lets you find nodes in a tree, similar to how `matches`,\n`querySelector`, and `querySelectorAll` work with the DOM.\n\nOne notable difference between DOM and hast is that DOM nodes have references\nto their parents, meaning that `document.body.matches(':last-child')` can\nbe evaluated to check whether the body is the last child of its parent.\nThis information is not stored in hast, so selectors like that don’t work.\n\n## When should I use this?\n\nThis is a small utility that is quite useful, but is rather slow if you use it a\nlot.\nFor each call, it has to walk the entire tree.\nIn some cases, walking the tree once with [`unist-util-visit`][unist-util-visit]\nis smarter, such as when you want to change certain nodes.\nOn the other hand, this is quite powerful and fast enough for many other cases.\n\nThis utility is similar to [`unist-util-select`][unist-util-select], which can\nfind and match any unist node.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install hast-util-select\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {matches, select, selectAll} from \"https://esm.sh/hast-util-select@6\"\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {matches, select, selectAll} from \"https://esm.sh/hast-util-select@6?bundle\"\n</script>\n```\n\n## Use\n\n```js\nimport {h} from 'hastscript'\nimport {matches, select, selectAll} from 'hast-util-select'\n\nconst tree = h('section', [\n  h('p', 'Alpha'),\n  h('p', 'Bravo'),\n  h('h1', 'Charlie'),\n  h('p', 'Delta'),\n  h('p', 'Echo'),\n  h('p', 'Foxtrot'),\n  h('p', 'Golf')\n])\n\nconsole.log(matches('section', tree)) // `true`\n\nconsole.log(select('h1 ~ :nth-child(even)', tree))\n// The paragraph with `Delta`\n\nconsole.log(selectAll('h1 ~ :nth-child(even)', tree))\n// The paragraphs with `Delta` and `Foxtrot`\n```\n\n## API\n\nThis package exports the identifiers [`matches`][api-matches],\n[`select`][api-select], and [`selectAll`][api-select-all].\nThere is no default export.\n\n### `matches(selector, node[, space])`\n\nCheck that the given `node` matches `selector`.\n\nThis only checks the element itself, not the surrounding tree.\nThus, nesting in selectors is not supported (`p b`, `p > b`), neither are\nselectors like `:first-child`, etc.\nThis only checks that the given element matches the selector.\n\n###### Parameters\n\n*   `selector` (`string`)\n    — CSS selector, such as (`h1`, `a, b`)\n*   `node` ([`Node`][node], optional)\n    — node that might match `selector`, should be an element\n*   `space` ([`Space`][api-space], default: `'html'`)\n    — name of namespace\n\n###### Returns\n\nWhether `node` matches `selector` (`boolean`).\n\n###### Example\n\n```js\nimport {h} from 'hastscript'\nimport {matches} from 'hast-util-select'\n\nmatches('b, i', h('b')) // => true\nmatches(':any-link', h('a')) // => false\nmatches(':any-link', h('a', {href: '#'})) // => true\nmatches('.classy', h('a', {className: ['classy']})) // => true\nmatches('#id', h('a', {id: 'id'})) // => true\nmatches('[lang|=en]', h('a', {lang: 'en'})) // => true\nmatches('[lang|=en]', h('a', {lang: 'en-GB'})) // => true\n```\n\n### `select(selector, tree[, space])`\n\nSelect the first element that matches `selector` in the given `tree`.\nSearches the tree in *[preorder][]*.\n\n###### Parameters\n\n*   `selector` (`string`)\n    — CSS selector, such as (`h1`, `a, b`)\n*   `tree` ([`Node`][node], optional)\n    — tree to search\n*   `space` ([`Space`][api-space], default: `'html'`)\n    — name of namespace\n\n###### Returns\n\nFirst element in `tree` that matches `selector` or `undefined` if nothing is\nfound.\nThis could be `tree` itself.\n\n###### Example\n\n```js\nimport {h} from 'hastscript'\nimport {select} from 'hast-util-select'\n\nconsole.log(\n  select(\n    'h1 ~ :nth-child(even)',\n    h('section', [\n      h('p', 'Alpha'),\n      h('p', 'Bravo'),\n      h('h1', 'Charlie'),\n      h('p', 'Delta'),\n      h('p', 'Echo')\n    ])\n  )\n)\n```\n\nYields:\n\n```js\n{ type: 'element',\n  tagName: 'p',\n  properties: {},\n  children: [ { type: 'text', value: 'Delta' } ] }\n```\n\n### `selectAll(selector, tree[, space])`\n\nSelect all elements that match `selector` in the given `tree`.\nSearches the tree in *[preorder][]*.\n\n###### Parameters\n\n*   `selector` (`string`)\n    — CSS selector, such as (`h1`, `a, b`)\n*   `tree` ([`Node`][node], optional)\n    — tree to search\n*   `space` ([`Space`][api-space], default: `'html'`)\n    — name of namespace\n\n###### Returns\n\nElements in `tree` that match `selector`.\nThis could include `tree` itself.\n\n###### Example\n\n```js\nimport {h} from 'hastscript'\nimport {selectAll} from 'hast-util-select'\n\nconsole.log(\n  selectAll(\n    'h1 ~ :nth-child(even)',\n    h('section', [\n      h('p', 'Alpha'),\n      h('p', 'Bravo'),\n      h('h1', 'Charlie'),\n      h('p', 'Delta'),\n      h('p', 'Echo'),\n      h('p', 'Foxtrot'),\n      h('p', 'Golf')\n    ])\n  )\n)\n```\n\nYields:\n\n```js\n[ { type: 'element',\n    tagName: 'p',\n    properties: {},\n    children: [ { type: 'text', value: 'Delta' } ] },\n  { type: 'element',\n    tagName: 'p',\n    properties: {},\n    children: [ { type: 'text', value: 'Foxtrot' } ] } ]\n```\n\n### `Space`\n\nNamespace (TypeScript type).\n\n###### Type\n\n```ts\ntype Space = 'html' | 'svg'\n```\n\n## Support\n\n*   [x] `*` (universal selector)\n*   [x] `,` (multiple selector)\n*   [x] `p` (type selector)\n*   [x] `.class` (class selector)\n*   [x] `#id` (id selector)\n*   [x] `article p` (combinator: descendant selector)\n*   [x] `article > p` (combinator: child selector)\n*   [x] `h1 + p` (combinator: next-sibling selector)\n*   [x] `h1 ~ p` (combinator: subsequent sibling selector)\n*   [x] `[attr]` (attribute existence)\n*   [x] `[attr… i]` (attribute case-insensitive)\n*   [x] `[attr… s]` (attribute case-sensitive) (useless, default)\n*   [x] `[attr=value]` (attribute equality)\n*   [x] `[attr~=value]` (attribute contains in space-separated list)\n*   [x] `[attr|=value]` (attribute equality or prefix)\n*   [x] `[attr^=value]` (attribute begins with)\n*   [x] `[attr$=value]` (attribute ends with)\n*   [x] `[attr*=value]` (attribute contains)\n*   [x] `:dir()` (functional pseudo-class)\n*   [x] `:has()` (functional pseudo-class; also supports `a:has(> b)`)\n*   [x] `:is()` (functional pseudo-class)\n*   [x] `:lang()` (functional pseudo-class)\n*   [x] `:not()` (functional pseudo-class)\n*   [x] `:any-link` (pseudo-class)\n*   [x] `:blank` (pseudo-class)\n*   [x] `:checked` (pseudo-class)\n*   [x] `:disabled` (pseudo-class)\n*   [x] `:empty` (pseudo-class)\n*   [x] `:enabled` (pseudo-class)\n*   [x] `:optional` (pseudo-class)\n*   [x] `:read-only` (pseudo-class)\n*   [x] `:read-write` (pseudo-class)\n*   [x] `:required` (pseudo-class)\n*   [x] `:root` (pseudo-class)\n*   [x] `:scope` (pseudo-class):\n*   [x] \\* `:first-child` (pseudo-class)\n*   [x] \\* `:first-of-type` (pseudo-class)\n*   [x] \\* `:last-child` (pseudo-class)\n*   [x] \\* `:last-of-type` (pseudo-class)\n*   [x] \\* `:only-child` (pseudo-class)\n*   [x] \\* `:only-of-type` (pseudo-class)\n*   [x] \\* `:nth-child()` (functional pseudo-class)\n*   [x] \\* `:nth-last-child()` (functional pseudo-class)\n*   [x] \\* `:nth-last-of-type()` (functional pseudo-class)\n*   [x] \\* `:nth-of-type()` (functional pseudo-class)\n\n## Unsupported\n\n*   [ ] † `||` (column combinator)\n*   [ ] † `ns|E` (namespace type selector)\n*   [ ] † `*|E` (any namespace type selector)\n*   [ ] † `|E` (no namespace type selector)\n*   [ ] † `[ns|attr]` (namespace attribute)\n*   [ ] † `[*|attr]` (any namespace attribute)\n*   [ ] † `[|attr]` (no namespace attribute)\n*   [ ] ‖ `:nth-child(n of S)` (functional pseudo-class, note: scoping to\n    parents is not supported)\n*   [ ] ‖ `:nth-last-child(n of S)` (functional pseudo-class, note: scoping to\n    parents is not supported)\n*   [ ] † `:active` (pseudo-class)\n*   [ ] † `:autofill` (pseudo-class)\n*   [ ] † `:buffering` (pseudo-class)\n*   [ ] § `:closed` (pseudo-class)\n*   [ ] † `:current` (pseudo-class)\n*   [ ] † `:current()` (functional pseudo-class)\n*   [ ] † `:default` (pseudo-class)\n*   [ ] † `:defined` (pseudo-class)\n*   [ ] † `:focus` (pseudo-class)\n*   [ ] † `:focus-visible` (pseudo-class)\n*   [ ] † `:focus-within` (pseudo-class)\n*   [ ] † `:fullscreen` (pseudo-class)\n*   [ ] † `:future` (pseudo-class)\n*   [ ] § `:host()` (functional pseudo-class)\n*   [ ] § `:host-context()` (functional pseudo-class)\n*   [ ] † `:hover` (pseudo-class)\n*   [ ] ‡ `:in-range` (pseudo-class)\n*   [ ] † `:indeterminate` (pseudo-class)\n*   [ ] ‡ `:invalid` (pseudo-class)\n*   [ ] † `:link` (pseudo-class)\n*   [ ] † `:local-link` (pseudo-class)\n*   [ ] † `:modal` (pseudo-class)\n*   [ ] † `:muted` (pseudo-class)\n*   [ ] † `:nth-col()` (functional pseudo-class)\n*   [ ] † `:nth-last-col()` (functional pseudo-class)\n*   [ ] § `:open` (pseudo-class)\n*   [ ] ‡ `:out-of-range` (pseudo-class)\n*   [ ] † `:past` (pseudo-class)\n*   [ ] † `:paused` (pseudo-class)\n*   [ ] † `:placeholder-shown` (pseudo-class)\n*   [ ] † `:playing` (pseudo-class)\n*   [ ] † `:seeking` (pseudo-class)\n*   [ ] † `:stalled` (pseudo-class)\n*   [ ] † `:target` (pseudo-class)\n*   [ ] † `:target-within` (pseudo-class)\n*   [ ] † `:user-invalid` (pseudo-class)\n*   [ ] ‡ `:valid` (pseudo-class)\n*   [ ] † `:visited` (pseudo-class)\n*   [ ] † `:volume-locked` (pseudo-class)\n*   [ ] § `:where()` (functional pseudo-class)\n*   [ ] † `::before` (pseudo-elements: none are supported)\n\n###### Notes\n\n*   \\* — not supported in `matches`\n*   † — needs a user, browser, interactivity, scripting, or whole CSS to make\n    sense\n*   ‡ — not very interested in writing / including the code for this\n*   § — too new, the spec is still changing\n*   ‖ — pr wanted!\n*   `:any()` and `:matches()` are renamed to `:is()` in CSS.\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional type [`Space`][api-space].\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line, `hast-util-select@^6`,\ncompatible with Node.js 16.\n\n## Security\n\nThis package does not change the syntax tree so there are no openings for\n[cross-site scripting (XSS)][xss] attacks.\n\n## Related\n\n*   [`unist-util-select`](https://github.com/syntax-tree/unist-util-select)\n    — select unist nodes with CSS-like selectors\n*   [`hast-util-find-and-replace`](https://github.com/syntax-tree/hast-util-find-and-replace)\n    — find and replace text in a hast tree\n*   [`hast-util-parse-selector`](https://github.com/syntax-tree/hast-util-parse-selector)\n    — create an element from a simple CSS selector\n*   [`hast-util-from-selector`](https://github.com/syntax-tree/hast-util-from-selector)\n    — create an element from a complex CSS selector\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to get started.\nSee [`support.md`][help] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n<!-- Definitions -->\n\n[build-badge]: https://github.com/syntax-tree/hast-util-select/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/hast-util-select/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-select.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/hast-util-select\n\n[downloads-badge]: https://img.shields.io/npm/dm/hast-util-select.svg\n\n[downloads]: https://www.npmjs.com/package/hast-util-select\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=hast-util-select\n\n[size]: https://bundlejs.com/?q=hast-util-select\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/syntax-tree/unist/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[typescript]: https://www.typescriptlang.org\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[health]: https://github.com/syntax-tree/.github\n\n[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[help]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[preorder]: https://github.com/syntax-tree/unist#preorder\n\n[hast]: https://github.com/syntax-tree/hast\n\n[node]: https://github.com/syntax-tree/hast#nodes\n\n[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n\n[unist-util-visit]: https://github.com/syntax-tree/unist-util-visit\n\n[unist-util-select]: https://github.com/syntax-tree/unist-util-select\n\n[api-matches]: #matchesselector-node-space\n\n[api-select]: #selectselector-tree-space\n\n[api-select-all]: #selectallselector-tree-space\n\n[api-space]: #space\n","publish_time":1674388406735,"_cnpm_publish_time":1674388406735,"dist-tags":{"latest":"6.0.4"}}