Gathering detailed insights and metrics for unist-util-index
Gathering detailed insights and metrics for unist-util-index
Gathering detailed insights and metrics for unist-util-index
Gathering detailed insights and metrics for unist-util-index
utility to index property values or computed keys to nodes
npm install unist-util-index
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
9 Stars
93 Commits
1 Forks
9 Watchers
1 Branches
12 Contributors
Updated on Nov 09, 2024
Latest Version
4.0.0
Package Id
unist-util-index@4.0.0
Unpacked Size
14.77 kB
Size
5.00 kB
File Count
7
NPM Version
9.7.2
Node Version
20.0.0
Published on
Jul 07, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
unist utility to create an index from certain nodes.
This utility creates a mutable index data structure, that maps property values or computed keys, to nodes. For example, you can use this to index all (footnote) definitions in a tree, or all headings of a certain rank, to later retrieve them without having to walk the tree each time.
This is a utility that helps you deal with indexing the tree. It’s pretty small, and you can definitely do it yourself, but this little wrapper makes it all a bit easier.
This package is ESM only. In Node.js (version 16+), install with npm:
1npm install unist-util-index
In Deno with esm.sh
:
1import {Index} from 'https://esm.sh/unist-util-index@4'
In browsers with esm.sh
:
1<script type="module"> 2 import {Index} from 'https://esm.sh/unist-util-index@4?bundle' 3</script>
1import fs from 'node:fs/promises' 2import {fromMarkdown} from 'mdast-util-from-markdown' 3import {toString} from 'mdast-util-to-string' 4import {Index} from 'unist-util-index' 5 6// Parse and read this repo’s readme: 7const tree = fromMarkdown(await fs.readFile('readme.md')) 8 9// Index on heading depth: 10const indexOnDepth = new Index('depth', tree, 'heading') 11 12console.log( 13 indexOnDepth.get(2).map(function (d) { 14 return toString(d) 15 }) 16) 17 18// Index on definition identifier: 19const indexOnIdentifier = new Index('identifier', tree, 'definition') 20 21console.log( 22 indexOnIdentifier.get('unist').map(function (node) { 23 return node.url 24 }) 25)
Yields:
1[ 2 'Contents', 3 'What is this?', 4 'When should I use this?', 5 'Install', 6 'Use', 7 'API', 8 'Types', 9 'Compatibility', 10 'Related', 11 'Contribute', 12 'License' 13] 14[ 'https://github.com/syntax-tree/unist' ]
This package exports the identifier Index
.
There is no default export.
Index(prop|keyFunction[, tree[, test]])
Create a mutable index data structure, that maps property values or computed keys, to nodes.
If tree
is given, the index is initialized with all nodes, optionally
filtered by test
.
prop
(string
)
— field to look up in each node to find keyskeyFunction
(KeyFunction
)
— function called with each node to calculate keystree
(Node
, optional)
— tree to indextest
(Test
, optional)
— unist-util-is
compatible testInstance (Index
).
Index#get(key)
Get nodes by key
.
key
(unknown
)
— key to retrieve, can be anything that can be used as a key in a
Map
List of zero or more nodes (Array<Node>
).
Index#add(node)
Add node
to the index (if not already present).
node
(Node
)
— node to indexCurrent instance (Index
).
Index#remove(node)
Remove node
from the index (if present).
node
(Node
)
— node to removeCurrent instance (Index
).
KeyFunction
Function called with every added node to calculate the key to index on (TypeScript type).
node
(Node
)
— node to calculate a key forKey to index on (unknown
).
Can be anything that can be used as a key in a Map
.
Test
unist-util-is
compatible test (TypeScript type).
This package is fully typed with TypeScript.
It exports the additional types KeyFunction
and
Test
.
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-util-index@^4
,
compatible with Node.js 16.
unist-util-is
— utility to check if a node passes a testunist-util-visit
— utility to recursively walk over nodesunist-util-select
— select nodes with CSS-like selectorsSee 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, organisation, or community you agree to abide by its terms.
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
Reason
security policy file detected
Details
Reason
Found 0/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
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no SAST tool detected
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-30
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