{"id":13447307,"url":"https://github.com/syntax-tree/hast-util-parse-selector","last_synced_at":"2025-06-29T22:03:43.563Z","repository":{"id":4174624,"uuid":"52222109","full_name":"syntax-tree/hast-util-parse-selector","owner":"syntax-tree","description":"utility to create an element from a simple CSS selector","archived":false,"fork":false,"pushed_at":"2023-08-01T11:57:09.000Z","size":119,"stargazers_count":13,"open_issues_count":0,"forks_count":2,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-06-01T12:53:02.935Z","etag":null,"topics":["css","hast","hast-util","html","parse","selector","syntax-tree","unist","util"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/syntax-tree.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"unifiedjs","open_collective":"unified"}},"created_at":"2016-02-21T18:52:12.000Z","updated_at":"2024-04-18T01:01:49.000Z","dependencies_parsed_at":"2024-01-18T15:59:00.901Z","dependency_job_id":"d7c2a8e9-b70c-4abb-8df8-ab8074075a4b","html_url":"https://github.com/syntax-tree/hast-util-parse-selector","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/syntax-tree/hast-util-parse-selector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-parse-selector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-parse-selector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-parse-selector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-parse-selector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntax-tree","download_url":"https://codeload.github.com/syntax-tree/hast-util-parse-selector/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntax-tree%2Fhast-util-parse-selector/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260087901,"owners_count":22956993,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","hast","hast-util","html","parse","selector","syntax-tree","unist","util"],"created_at":"2024-07-31T05:01:13.460Z","updated_at":"2025-06-29T22:03:43.495Z","avatar_url":"https://github.com/syntax-tree.png","language":"JavaScript","readme":"# hast-util-parse-selector\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 to create an element from a simple CSS selector.\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    *   [`parseSelector(selector?[, defaultTagName])`](#parseselectorselector-defaulttagname)\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 is a tiny utility that helps create elements.\n\n## When should I use this?\n\nThis utility is super niche.\nYou probably want the more powerful [`hastscript`][hastscript] or\n[`hast-util-from-selector`][hast-util-from-selector]\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-parse-selector\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport {parseSelector} from 'https://esm.sh/hast-util-parse-selector@4'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {parseSelector} from 'https://esm.sh/hast-util-parse-selector@4?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\n```js\nimport {parseSelector} from 'hast-util-parse-selector'\n\nconsole.log(parseSelector('.quux#bar.baz.qux'))\n```\n\nYields:\n\n```js\n{ type: 'element',\n  tagName: 'div',\n  properties: { id: 'bar', className: [ 'quux', 'baz', 'qux' ] },\n  children: [] }\n```\n\n## API\n\nThis package exports the identifier [`parseSelector`][api-parse-selector].\nThere is no default export.\n\n### `parseSelector(selector?[, defaultTagName])`\n\nCreate a hast element from a simple CSS selector.\n\n###### Parameters\n\n*   `selector` (`string`, optional)\n    —  simple CSS selector, can contain a tag name (`foo`), classes (`.bar`),\n    and an ID (`#baz`), multiple classes are allowed, uses the last ID if\n    multiple IDs are found\n*   `defaultTagName` (`string`, default: `'div'`)\n    — tag name to use if `selector` does not specify one\n\n###### Returns\n\nBuilt element ([`Element`][element]).\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports no additional types.\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,\n`hast-util-parse-selector@^4`, compatible with Node.js 16.\n\n## Security\n\nImproper use of the `selector` or `defaultTagName` can open you up to a\n[cross-site scripting (XSS)][xss] attack as the value of `tagName`, when\nresolving to `script`, injects a `script` element into the syntax tree.\n\nDo not use user input in `selector` or use\n[`hast-util-santize`][hast-util-sanitize].\n\n## Related\n\n*   [`hast-util-from-selector`](https://github.com/syntax-tree/hast-util-from-selector)\n    — parse complex CSS selectors to nodes\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for\nways to get started.\nSee [`support.md`][support] 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\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/syntax-tree/hast-util-parse-selector/workflows/main/badge.svg\n\n[build]: https://github.com/syntax-tree/hast-util-parse-selector/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-parse-selector.svg\n\n[coverage]: https://codecov.io/github/syntax-tree/hast-util-parse-selector\n\n[downloads-badge]: https://img.shields.io/npm/dm/hast-util-parse-selector.svg\n\n[downloads]: https://www.npmjs.com/package/hast-util-parse-selector\n\n[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size\u0026query=$.size.compressedSize\u0026url=https://deno.bundlejs.com/?q=hast-util-parse-selector\n\n[size]: https://bundlejs.com/?q=hast-util-parse-selector\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[support]: 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[hast]: https://github.com/syntax-tree/hast\n\n[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize\n\n[hastscript]: https://github.com/syntax-tree/hastscript\n\n[hast-util-from-selector]: https://github.com/syntax-tree/hast-util-from-selector\n\n[element]: https://github.com/syntax-tree/hast#element\n\n[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n\n[api-parse-selector]: #parseselectorselector-defaulttagname\n","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fhast-util-parse-selector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntax-tree%2Fhast-util-parse-selector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntax-tree%2Fhast-util-parse-selector/lists"}