Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
posthtml-match-helper
Advanced tools
A helper to expand CSS selectors into PostHTML matcher objects
This PostHTML plugin can turn simple CSS selectors into matcher objects.
Supported features:
"div"
returns {tag: "div"}
."#bar"
returns {attrs: {id: "bar"}}
..foo
returns {attrs: { class: /(?:^|\s)foo(?:\\s|$)/ }}
. Any number of classnames supported.[attr!=value]
: matches attributes with values that do not contain value
."div, span"
returns [{tag: "div"}, {tag: "span"}]
.1 Multiple attribute selectors for the same attribute are not supported (this includes mixing classnames and attribute selectors matching class
).
The basic template for selectors (and order of features) looks like this:
"tag#id.class.name[attr*=value][otherattr^='start']"
import matchHelper from "posthtml-match-helper";
tree.match(matchHelper("div.class"), function (node) {
// do stuff with matched node...
});
import matchHelper from "posthtml-match-helper";
tree.match(matchHelper("input.my-control[type!='radio'][checked], input[value^='foo'][checked]"), function (node) {
// do stuff with node that matched either of the selectors...
});
If you need to match nodes with classnames that use escaped characters, like those in Tailwind CSS utilities with arbitrary values, use the following syntax:
import matchHelper from "posthtml-match-helper";
tree.match(matchHelper("input.\\[display:none\\]"), function (node) {
// do stuff with node that matched either of the selectors...
});
matcher
(string) - A CSS selector that describes the node you want to match in PostHTML.A matcher object or an array of matcher objects.
FAQs
A helper to expand CSS selectors into PostHTML matcher objects
The npm package posthtml-match-helper receives a total of 42,668 weekly downloads. As such, posthtml-match-helper popularity was classified as popular.
We found that posthtml-match-helper demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.