{"id":24983685,"url":"https://github.com/posthtml/posthtml-match-helper","last_synced_at":"2025-04-11T20:51:40.729Z","repository":{"id":41813036,"uuid":"44060257","full_name":"posthtml/posthtml-match-helper","owner":"posthtml","description":"A helper to expand CSS selectors into PostHTML matcher objects","archived":false,"fork":false,"pushed_at":"2025-04-04T16:16:58.000Z","size":918,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-10T21:22:54.348Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/posthtml.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-11T16:38:26.000Z","updated_at":"2025-04-04T16:16:54.000Z","dependencies_parsed_at":"2024-01-13T07:21:03.324Z","dependency_job_id":"5bbd4666-03d3-4e99-b849-6d208afdc301","html_url":"https://github.com/posthtml/posthtml-match-helper","commit_stats":{"total_commits":76,"total_committers":8,"mean_commits":9.5,"dds":0.5263157894736843,"last_synced_commit":"d5ea441f93f52a59dd18c852fc034623c94a72f7"},"previous_names":["rasmusfl0e/posthtml-match-helper"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-match-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-match-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-match-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-match-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/posthtml","download_url":"https://codeload.github.com/posthtml/posthtml-match-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248480512,"owners_count":21110936,"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":"2025-02-04T09:20:16.648Z","updated_at":"2025-04-11T20:51:40.692Z","avatar_url":"https://github.com/posthtml.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"150\" height=\"150\" title=\"PostHTML\" src=\"https://posthtml.github.io/posthtml/logo.svg\"\u003e\n  \u003ch1\u003eposthtml-match-helper\u003c/h1\u003e\n  \n  Expand CSS selectors into PostHTML matcher objects\n\n  [![Version][npm-version-shield]][npm]\n  [![Build][github-ci-shield]][github-ci]\n  [![License][license-shield]][license]\n  [![Downloads][npm-stats-shield]][npm-stats]\n\u003c/div\u003e\n\n## Introduction\n\nThis PostHTML plugin can turn simple CSS selectors into [matcher objects](https://github.com/posthtml/posthtml/blob/master/README.md#match).\n\nSupported features:\n\n* Tags: `\"div\"` returns `{tag: \"div\"}`.\n* Ids: `\"#bar\"` returns `{attrs: {id: \"bar\"}}`.\n* Classes: `.foo` returns `{attrs: { class: /(?:^|\\s)foo(?:\\\\s|$)/ }}`. Any number of classnames supported.\n* Attribute selectors: any number of standard [attribute selectors](https://developer.mozilla.org/en/docs/Web/CSS/Attribute_selectors) can be used\u003csup\u003e\u003ca href=\"#attribute_selectors_footnote\"\u003e1\u003c/a\u003e\u003c/sup\u003e including the following non-standard:\n   * `[attr!=value]`: matches attributes with values that do not contain `value`.\n* Multiple node selectors: `\"div, span\"` returns `[{tag: \"div\"}, {tag: \"span\"}]`.\n\n**\u003csup\u003e\u003ca name=\"attribute_selectors_footnote\"\u003e1\u003c/a\u003e\u003c/sup\u003e** Multiple attribute selectors for the same attribute are not supported (this includes mixing classnames and attribute selectors matching `class`).\n\nThe basic template for selectors (and order of features) looks like this:\n\n```js\n\"tag#id.class.name[attr*=value][otherattr^='start']\"\n```\n\n## Basic usage\n\n```js\nimport matchHelper from \"posthtml-match-helper\";\n\ntree.match(matchHelper(\"div.class\"), function (node) {\n  // do stuff with matched node...\n});\n```\n\n## Advanced usage\n\n```js\nimport matchHelper from \"posthtml-match-helper\";\n\ntree.match(matchHelper(\"input.my-control[type!='radio'][checked], input[value^='foo'][checked]\"), function (node) {\n  // do stuff with node that matched either of the selectors...\n});\n```\n\n## Classnames with escaped characters\n\nIf you need to match nodes with classnames that use escaped characters, like those in Tailwind CSS utilities with arbitrary values, use the following syntax:\n\n```js\nimport matchHelper from \"posthtml-match-helper\";\n\ntree.match(matchHelper(\"input.\\\\[display:none\\\\]\"), function (node) {\n  // do stuff with node that matched either of the selectors...\n});\n```\n\n\n## The helper function\n\n#### Arguments\n\n* `matcher` (string) - A CSS selector that describes the node you want to match in PostHTML.\n\n#### Returns\n\nA matcher object or an array of matcher objects.\n\n[npm]: https://www.npmjs.com/package/posthtml-match-helper\n[npm-version-shield]: https://img.shields.io/npm/v/posthtml-match-helper.svg\n[npm-stats]: http://npm-stat.com/charts.html?package=posthtml-match-helper\n[npm-stats-shield]: https://img.shields.io/npm/dt/posthtml-match-helper.svg\n[github-ci]: https://github.com/posthtml/posthtml-match-helper/actions/workflows/nodejs.yml\n[github-ci-shield]: https://github.com/posthtml/posthtml-match-helper/actions/workflows/nodejs.yml/badge.svg\n[license]: ./LICENSE\n[license-shield]: https://img.shields.io/npm/l/posthtml-match-helper.svg\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-match-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposthtml%2Fposthtml-match-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-match-helper/lists"}