Installations
npm install unist-builder
Developer
Developer Guide
Module System
ESM
Min. Node Version
Typescript Support
Yes
Node Version
20.0.0
NPM Version
9.7.2
Statistics
77 Stars
82 Commits
3 Forks
11 Watching
1 Branches
11 Contributors
Updated on 09 Nov 2024
Languages
JavaScript (80.01%)
TypeScript (19.99%)
Total Downloads
Cumulative downloads
Total Downloads
804,954,950
Last day
-6%
491,289
Compared to previous day
Last week
1.4%
2,771,051
Compared to previous week
Last month
9.9%
11,854,228
Compared to previous month
Last year
-36.4%
159,259,923
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
unist-builder
unist utility to create trees with ease.
Contents
- What is this?
- When should I use this?
- Install
- Use
- API
- Types
- Compatibility
- Related
- Contribute
- License
What is this?
This package is a hyperscript interface (like createElement
from React and
h
from Vue and such) to help with creating unist trees.
When should I use this?
You can use this utility in your project when you generate syntax trees with code. It helps because it replaces most of the repetition otherwise needed in a syntax tree with function calls.
You can instead use hastscript
or xastscript
when creating hast (HTML) or xast (XML) nodes.
Install
This package is ESM only. In Node.js (version 16+), install with npm:
1npm install unist-builder
In Deno with esm.sh
:
1import {u} from 'https://esm.sh/unist-builder@4'
In browsers with esm.sh
:
1<script type="module"> 2 import {u} from 'https://esm.sh/unist-builder@4?bundle' 3</script>
Use
1import {u} from 'unist-builder' 2 3const tree = u('root', [ 4 u('subtree', {id: 1}), 5 u('subtree', {id: 2}, [ 6 u('node', [u('leaf', 'leaf 1'), u('leaf', 'leaf 2')]), 7 u('leaf', {id: 3}, 'leaf 3'), 8 u('void', {id: 4}) 9 ]) 10]) 11 12console.dir(tree, {depth: undefined})
…yields:
1{ 2 type: 'root', 3 children: [ 4 {type: 'subtree', id: 1}, 5 { 6 type: 'subtree', 7 id: 2, 8 children: [ 9 { 10 type: 'node', 11 children: [ 12 {type: 'leaf', value: 'leaf 1'}, 13 {type: 'leaf', value: 'leaf 2'} 14 ] 15 }, 16 {type: 'leaf', id: 3, value: 'leaf 3'}, 17 {type: 'void', id: 4} 18 ] 19 } 20 ] 21}
API
This package exports the identifier u
.
There is no default export.
u(type[, props][, children|value])
Build a node.
Signatures
u(type[, props], children)
— create a parent (Parent
)u(type[, props], value)
— create a literal (Literal
)u(type[, props])
— create a void node (neither parent not literal)
Parameters
type
(string
) — node typeprops
(Record<string, unknown>
) — fields assigned to nodechildren
(Array<Node>
) — children of nodevalue
(*
) — value ofnode
(cast to string)
Returns
Built node (Node
).
ChildrenOrValue
List to use as children
or value to use as value
(TypeScript type).
Type
1type ChildrenOrValue = Array<Node> | string
Props
Other fields to add to the node (TypeScript type).
Type
1export type Props = Record<string, unknown>
Types
This package is fully typed with TypeScript.
It exports the additional types ChildrenOrValue
and
Props
.
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, unist-builder@^4
,
compatible with Node.js 16.
Related
hastscript
— create hast treesxastscript
— create xast trees
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 © Eugene Sharygin
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
Found 2/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- 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
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/bb.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/unist-builder/bb.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/unist-builder/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/unist-builder/main.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/syntax-tree/unist-builder/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:15
- 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 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'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 2 are checked with a SAST tool
Score
4.1
/10
Last Scanned on 2024-11-18
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 MoreOther packages similar to unist-builder
unist-util-visit-parents
unist utility to recursively walk over nodes, with ancestral information
unist-util-stringify-position
unist utility to serialize a node, position, or point as a human readable location
unist-util-is
unist utility to check if a node passes a test
unist-util-visit
unist utility to visit nodes