Gathering detailed insights and metrics for hast-util-from-selector
Gathering detailed insights and metrics for hast-util-from-selector
Gathering detailed insights and metrics for hast-util-from-selector
Gathering detailed insights and metrics for hast-util-from-selector
utility to parse CSS selectors to hast nodes
npm install hast-util-from-selector
Typescript
Module System
Node Version
NPM Version
85.4
Supply Chain
99.5
Quality
78.7
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
198,860
Last Day
278
Last Week
3,089
Last Month
12,605
Last Year
91,778
MIT License
2 Stars
59 Commits
1 Forks
8 Watchers
1 Branches
10 Contributors
Updated on Nov 19, 2024
Minified
Minified + Gzipped
Latest Version
3.0.1
Package Id
hast-util-from-selector@3.0.1
Unpacked Size
15.29 kB
Size
5.64 kB
File Count
9
NPM Version
10.9.0
Node Version
23.1.0
Published on
Nov 19, 2024
Cumulative downloads
Total Downloads
Last Day
-1.8%
278
Compared to previous day
Last Week
-19.7%
3,089
Compared to previous week
Last Month
24.7%
12,605
Compared to previous month
Last Year
85.1%
91,778
Compared to previous year
hast utility to create nodes from a complex CSS selectors.
This package is a utility that can generate elements from complex CSS selectors.
You can use this when you’re generating a bunch of elements, and manually
creating objects each time is starting to feel like a waste.
This package is much more powerful than
hast-util-parse-selector
,
and similar to hastscript
.
This package is ESM only. In Node.js (version 16+), install with npm:
1npm install hast-util-from-selector
In Deno with esm.sh
:
1import {fromSelector} from 'https://esm.sh/hast-util-from-selector@3'
In browsers with esm.sh
:
1<script type="module"> 2 import {fromSelector} from 'https://esm.sh/hast-util-from-selector@3?bundle' 3</script>
1import {fromSelector} from 'hast-util-from-selector' 2 3console.log(fromSelector('p svg[viewbox="0 0 10 10"] circle[cx=10][cy=10][r=10]'))
Yields:
1{ 2 type: 'element', 3 tagName: 'p', 4 properties: {}, 5 children: [ 6 { 7 type: 'element', 8 tagName: 'svg', 9 properties: {viewBox: '0 0 10 10'}, 10 children: [ 11 { 12 type: 'element', 13 tagName: 'circle', 14 properties: {cx: '10', cy: '10', r: '10'}, 15 children: [] 16 } 17 ] 18 } 19 ] 20}
This package exports the identifier fromSelector
.
There is no default export.
fromSelector(selector?[, options])
Create one or more Element
s from a CSS selector.
selector
(string
, default: ''
)
— CSS selectoroptions
(Options
, optional)
— configurationOptions
Configuration (TypeScript type).
space
(Space
, default: 'html'
)
— which space first element in the selector is in.
When an svg
element is created in HTML, the space is automatically
switched to SVGSpace
Name of namespace (TypeScript type).
1type Space = 'html' | 'svg'
*
(universal selector, creates a div
in HTML, g
in SVG)p
(type selector).class
(class selector)#id
(id selector)[attr]
(attribute existence, creates a boolean)[attr=value]
(attribute equality)article p
(descendant combinator)article > p
(child combinator)section h1 + p
(next-sibling combinator, not at root)section h1 ~ p
(subsequent-sibling combinator, not at root)This package is fully typed with TypeScript.
It exports the additional types Options
and
Space
.
Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
hast-util-from-selector@^3
, compatible with Node.js 16.
Use of hast-util-from-selector
can open you up to a
cross-site scripting (XSS) attack as values are injected into the syntax
tree.
Either do not use user input in from-selector
or use
hast-util-santize
.
hast-util-parse-selector
— create an element from a simple CSS selectorSee contributing.md
in syntax-tree/.github
for
ways to get started.
See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More