Skip to content

Commit cd7e943

Browse files
committed
Add improved docs
1 parent e468aee commit cd7e943

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

lib/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
* @param {string | null | undefined} [identifier]
1313
* Identifier of definition.
1414
* @returns {Definition | null}
15-
* Definition corresponding to `identifier`, if found.
15+
* Definition corresponding to `identifier` or `null`.
1616
*/
1717

1818
import {visit} from 'unist-util-visit'
1919

2020
const own = {}.hasOwnProperty
2121

2222
/**
23-
* Find definitions in `node`.
23+
* Find definitions in `tree`.
2424
*
2525
* Uses CommonMark precedence, which means that earlier definitions are
2626
* preferred over duplicate later definitions.

readme.md

+30-16
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
* [Install](#install)
1818
* [Use](#use)
1919
* [API](#api)
20-
* [`definitions(node)`](#definitionsnode)
21-
* [`definition(identifier)`](#definitionidentifier)
20+
* [`definitions(tree)`](#definitionstree)
21+
* [`GetDefinition`](#getdefinition)
2222
* [Types](#types)
2323
* [Compatibility](#compatibility)
2424
* [Security](#security)
@@ -39,7 +39,7 @@ It’s small and protects against prototype pollution.
3939
## Install
4040

4141
This package is [ESM only][esm].
42-
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
42+
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
4343

4444
```sh
4545
npm install mdast-util-definitions
@@ -78,37 +78,49 @@ definition('foo')
7878

7979
## API
8080

81-
This package exports the identifier `definitions`.
81+
This package exports the identifier [`definitions`][api-definitions].
8282
There is no default export.
8383

84-
### `definitions(node)`
84+
### `definitions(tree)`
8585

86-
Find [definition][]s in `node` ([`Node`][node]).
87-
Uses CommonMark precedence, which means that earlier definitions are preferred
88-
over duplicate later definitions.
86+
Find definitions in `tree`.
87+
88+
Uses CommonMark precedence, which means that earlier definitions are
89+
preferred over duplicate later definitions.
90+
91+
###### Parameters
92+
93+
* `tree` ([`Node`][node])
94+
— tree to check
8995

9096
###### Returns
9197

92-
`definition` ([`Function`][fn-definition]).
98+
Getter ([`GetDefinition`][api-getdefinition]).
99+
100+
### `GetDefinition`
93101

94-
### `definition(identifier)`
102+
Get a definition by identifier (TypeScript type).
95103

96-
Get a node from the bound definition cache by its `identifier` (`string`).
104+
###### Parameters
105+
106+
* `identifier` (`string`, optional)
107+
— identifier of definition
97108

98109
###### Returns
99110

100-
[Definition][], if found ([`Node?`][node])
111+
Definition corresponding to `identifier` ([`Definition`][definition]) or
112+
`null`.
101113

102114
## Types
103115

104116
This package is fully typed with [TypeScript][].
105-
There are no additional exported types.
117+
It exports the additional type [`GetDefinition`][api-getdefinition].
106118

107119
## Compatibility
108120

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

114126
## Security
@@ -188,10 +200,12 @@ abide by its terms.
188200

189201
[node]: https://github.com/syntax-tree/unist#node
190202

191-
[fn-definition]: #definitionidentifier
192-
193203
[definition]: https://github.com/syntax-tree/mdast#definition
194204

195205
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
196206

197207
[hast]: https://github.com/syntax-tree/hast
208+
209+
[api-definitions]: #definitionstree
210+
211+
[api-getdefinition]: #getdefinition

0 commit comments

Comments
 (0)