Installations
npm install hast-util-from-selector
Developer Guide
Typescript
Yes
Module System
ESM
Node Version
23.1.0
NPM Version
10.9.0
Score
75.2
Supply Chain
99.5
Quality
78.7
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
160,256
Last Day
402
Last Week
2,525
Last Month
10,506
Last Year
67,077
GitHub Statistics
MIT License
2 Stars
59 Commits
1 Forks
9 Watchers
1 Branches
10 Contributors
Updated on Nov 19, 2024
Bundle Size
36.38 kB
Minified
12.04 kB
Minified + Gzipped
Sponsor this package
Package Meta Information
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
Total Downloads
Cumulative downloads
Total Downloads
160,256
Last Day
6.1%
402
Compared to previous day
Last Week
19.7%
2,525
Compared to previous week
Last Month
52%
10,506
Compared to previous month
Last Year
32.6%
67,077
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
hast-util-from-selector
hast utility to create nodes from a complex CSS selectors.
Contents
- What is this?
- When should I use this?
- Install
- Use
- API
- Support
- Types
- Compatibility
- Security
- Related
- Contribute
- License
What is this?
This package is a utility that can generate elements from complex CSS selectors.
When should I use this?
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
.
Install
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>
Use
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}
API
This package exports the identifier fromSelector
.
There is no default export.
fromSelector(selector?[, options])
Create one or more Element
s from a CSS selector.
Parameters
selector
(string
, default:''
) — CSS selectoroptions
(Options
, optional) — configuration
Returns
Options
Configuration (TypeScript type).
Fields
space
(Space
, default:'html'
) — which space first element in the selector is in. When ansvg
element is created in HTML, the space is automatically switched to SVG
Space
Name of namespace (TypeScript type).
Type
1type Space = 'html' | 'svg'
Support
-
*
(universal selector, creates adiv
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)
Types
This package is fully typed with TypeScript.
It exports the additional types Options
and
Space
.
Compatibility
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.
Security
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
.
Related
hast-util-parse-selector
— create an element from a simple CSS selector
Contribute
See 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.
License
MIT © Titus Wormer

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
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/syntax-tree/.github/security.md:1
- Info: Found linked content: github.com/syntax-tree/.github/security.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/syntax-tree/.github/security.md:1
- Info: Found text in security policy: github.com/syntax-tree/.github/security.md:1
Reason
9 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 7
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/bb.yml:5: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/hast-util-from-selector/bb.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:6: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/hast-util-from-selector/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:7: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/hast-util-from-selector/main.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/hast-util-from-selector/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:11
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/bb.yml:1
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Score
4.7
/10
Last Scanned on 2025-02-03
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