mdast-util-definitions

mdast utility to find definition nodes in a tree

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
mdast-util-definitions
805.1.26 days ago8 years agoMinified + gzip package size for mdast-util-definitions in KB

Readme

mdast-util-definitions
!Buildbuild-badgebuild !Coveragecoverage-badgecoverage !Downloadsdownloads-badgedownloads !Sizesize-badgesize !Sponsorssponsors-badgecollective !Backersbackers-badgecollective !Chatchat-badgechat
mdast utility to find definitions by identifier.

Contents

*   [`definitions(tree)`](#definitionstree)
*   [`GetDefinition`](#getdefinition)

What is this?

This package is a tiny utility that lets you find definitions.

When should I use this?

This utility can be useful because definitions can occur after the things that reference them. It’s small and protects against prototype pollution.

Install

This package is ESM onlyesm. In Node.js (version 14.14+ and 16.0+), install with npm:
npm install mdast-util-definitions

In Deno with esm.shesmsh:
import {definitions} from 'https://esm.sh/mdast-util-definitions@5'

In browsers with esm.shesmsh:
<script type="module">
  import {definitions} from 'https://esm.sh/mdast-util-definitions@5?bundle'
</script>

Use

import {fromMarkdown} from 'mdast-util-from-markdown'
import {definitions} from 'mdast-util-definitions'

const tree = fromMarkdown('[example]: https://example.com "Example"')

const definition = definitions(tree)

definition('example')
// => {type: 'definition', 'title': 'Example', …}

definition('foo')
// => null

API

This package exports the identifier definitionsapi-definitions. There is no default export.

definitions(tree)

Find definitions in tree.
Uses CommonMark precedence, which means that earlier definitions are preferred over duplicate later definitions.
Parameters
— tree to check
Returns
Getter (GetDefinitionapi-getdefinition).

GetDefinition

Get a definition by identifier (TypeScript type).
Parameters
  • identifier (string, optional)
— identifier of definition
Returns
Definition corresponding to identifier (Definitiondefinition) or null.

Types

This package is fully typed with TypeScript. It exports the additional type GetDefinitionapi-getdefinition.

Compatibility

Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. Our projects sometimes work with older versions, but this is not guaranteed.

Security

Use of mdast-util-definitions does not involve hast or user content so there are no openings for cross-site scripting (XSS)xss attacks. Additionally, safe guards are in place to protect against prototype poisoning.

Related

— index property values or computed keys to nodes

Contribute

See contributing.mdcontributing in syntax-tree/.githubhealth for ways to get started. See support.mdsupport for ways to get help.
This project has a code of conductcoc. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MITlicense © Titus Wormerauthor