{"id":16350314,"url":"https://github.com/niksy/postcss-query-ast","last_synced_at":"2025-07-18T14:36:18.835Z","repository":{"id":57328416,"uuid":"163986779","full_name":"niksy/postcss-query-ast","owner":"niksy","description":"Query PostCSS AST with CSS selectors.","archived":false,"fork":false,"pushed_at":"2023-08-23T07:29:58.000Z","size":36,"stargazers_count":12,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-11T06:42:05.299Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/niksy.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-03T14:58:58.000Z","updated_at":"2024-09-13T16:18:41.000Z","dependencies_parsed_at":"2024-06-20T23:38:19.326Z","dependency_job_id":null,"html_url":"https://github.com/niksy/postcss-query-ast","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niksy%2Fpostcss-query-ast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niksy%2Fpostcss-query-ast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niksy%2Fpostcss-query-ast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niksy%2Fpostcss-query-ast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/niksy","download_url":"https://codeload.github.com/niksy/postcss-query-ast/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234444575,"owners_count":18833657,"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":[],"created_at":"2024-10-11T01:03:07.164Z","updated_at":"2025-01-17T23:49:02.302Z","avatar_url":"https://github.com/niksy.png","language":"JavaScript","readme":"# postcss-query-ast\n\n[![Build Status][ci-img]][ci]\n\nQuery PostCSS AST with CSS selectors.\n\nSupported selectors are:\n\n-   [Type selectors][mdn-type-selector]: `rule`, `atrule`, `decl`, `comment`\n-   [Universal selector](mdn-universal-selector): `*`\n-   [Attribute selectors][mdn-attribute-selector]: `[attr=value]`,\n    `[attr=value]`, `[attr~=value]`, `[attr|=value]`, `[attr^=value]`,\n    `[attr$=value]`, `[attr*=value]`\n-   [Descendant combinator][mdn-descendant-combinator]: `rule decl`\n-   [Child combinator][mdn-child-combinator]: `atrule \u003e rule`\n-   [Adjacent sibling combinator][mdn-adjacent-sibling-combinator]:\n    `rule + rule`\n-   [General sibling combinator][mdn-general-sibling-combinator]: `rule ~ rule`\n-   Child pseudo classes ([`:first-child`][mdn-first-child],\n    [`:last-child`][mdn-last-child], [`:nth-child`][mdn-nth-child],\n    [`:nth-last-child`][mdn-nth-last-child], [`:only-child`][mdn-only-child]):\n    `rule:first-child`\n-   Type pseudo classes ([`:first-of-type`][mdn-first-of-type],\n    [`:last-of-type`][mdn-last-of-type], [`:nth-of-type`][mdn-nth-of-type],\n    [`:nth-last-of-type`][mdn-nth-last-of-type],\n    [`:only-of-type`][mdn-only-of-type]): `rule:first-of-type`\n-   [Empty nodes][mdn-empty]: `rule:empty`\n-   [Matches][mdn-matches]: `:matches(rule, atrule)`\n-   [Negation][mdn-not]: `:not(atrule)`\n\nIn addition to standard selectors, there are also custom selectors:\n\n-   Attribute selector with regular expression: `[attr=\"/^value$/i\"]`\n\n## Install\n\n```sh\nnpm install postcss-query-ast --save\n```\n\n## Usage\n\nQuerying AST from following CSS will give us only `body` rule with `jackie` ID\nattribute.\n\n```css\nbody {\n\tbackground: red;\n}\n\nbody#jackie {\n\tbackground: hotpink;\n}\n\na {\n\tbackground: green;\n}\n```\n\n```js\nimport queryAst from 'postcss-query-ast';\n\n// Assume we have AST\nconst postcssAst = [];\n\n(async () =\u003e {\n\tconst ast = await queryAst('rule[selector=\"body#jackie\"]', postcssAst);\n\n\t/* [ Rule {\n\t    raws: { before: '\\n\\n', between: ' ', semicolon: true, after: '\\n' },\n\t    type: 'rule',\n\t    nodes: [ [Declaration] ],\n\t    parent: \n\t     Root {\n\t       raws: [Object],\n\t       type: 'root',\n\t       nodes: [Array],\n\t       source: [Object],\n\t       lastEach: 1,\n\t       indexes: {} },\n\t    source: { start: [Object], input: [Input], end: [Object] },\n\t    selector: 'body#jackie',\n\t    lastEach: 1,\n\t    indexes: {} } ] */\n})();\n```\n\n## API\n\n### queryAst(query, ast)\n\nReturns: `Promise\u003c(Root | Rule | AtRule | Declaration | Comment)[]\u003e`\n\nQueries PostCSS with CSS selector.\n\n#### query\n\nType: `string`\n\nCSS selector.\n\n#### ast\n\nType: `Root`\n\nPostCSS AST.\n\n## License\n\nMIT © [Ivan Nikolić](http://ivannikolic.com)\n\n\u003c!-- prettier-ignore-start --\u003e\n\n[ci]: https://github.com/niksy/postcss-query-ast/actions?query=workflow%3ACI\n[ci-img]: https://github.com/niksy/postcss-query-ast/workflows/CI/badge.svg?branch=master\n[mdn-type-selector]: https://developer.mozilla.org/en-US/docs/Web/CSS/Type_selectors\n[mdn-universal-selector]: https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors\n[mdn-attribute-selector]: https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors\n[mdn-descendant-combinator]: https://developer.mozilla.org/en-US/docs/Web/CSS/Descendant_selectors\n[mdn-child-combinator]: https://developer.mozilla.org/en-US/docs/Web/CSS/Child_selectors\n[mdn-adjacent-sibling-combinator]: https://developer.mozilla.org/en-US/docs/Web/CSS/Adjacent_sibling_selectors\n[mdn-general-sibling-combinator]: https://developer.mozilla.org/en-US/docs/Web/CSS/General_sibling_selectors\n[mdn-first-child]: https://developer.mozilla.org/en-US/docs/Web/CSS/:first-child\n[mdn-last-child]: https://developer.mozilla.org/en-US/docs/Web/CSS/:last-child\n[mdn-nth-child]: https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child\n[mdn-nth-last-child]: https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-last-child\n[mdn-only-child]: https://developer.mozilla.org/en-US/docs/Web/CSS/:only-child\n[mdn-first-of-type]: https://developer.mozilla.org/en-US/docs/Web/CSS/:first-of-type\n[mdn-last-of-type]: https://developer.mozilla.org/en-US/docs/Web/CSS/:last-of-type\n[mdn-nth-of-type]: https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-of-type\n[mdn-nth-last-of-type]: https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-last-of-type\n[mdn-only-of-type]: https://developer.mozilla.org/en-US/docs/Web/CSS/:only-of-type\n[mdn-empty]: https://developer.mozilla.org/en-US/docs/Web/CSS/:empty\n[mdn-matches]: https://developer.mozilla.org/en-US/docs/Web/CSS/:matches\n[mdn-not]: https://developer.mozilla.org/en-US/docs/Web/CSS/:not\n\n\u003c!-- prettier-ignore-end --\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniksy%2Fpostcss-query-ast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fniksy%2Fpostcss-query-ast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniksy%2Fpostcss-query-ast/lists"}