8
8
[ ![ Backers] [ backers-badge ]] [ collective ]
9
9
[ ![ Chat] [ chat-badge ]] [ chat ]
10
10
11
- [ ** mdast** ] [ mdast ] utility to get definitions by ` identifier ` .
11
+ [ mdast] [ ] utility to find definitions by ` identifier ` .
12
12
13
- Supports funky keys, like ` __proto__ ` or ` toString ` .
13
+ ## Contents
14
14
15
- ## Install
15
+ * [ What is this?] ( #what-is-this )
16
+ * [ When should I use this?] ( #when-should-i-use-this )
17
+ * [ Install] ( #install )
18
+ * [ Use] ( #use )
19
+ * [ API] ( #api )
20
+ * [ ` definitions(node) ` ] ( #definitionsnode )
21
+ * [ ` definition(identifier) ` ] ( #definitionidentifier )
22
+ * [ Types] ( #types )
23
+ * [ Compatibility] ( #compatibility )
24
+ * [ Security] ( #security )
25
+ * [ Related] ( #related )
26
+ * [ Contribute] ( #contribute )
27
+ * [ License] ( #license )
28
+
29
+ ## What is this?
16
30
17
- This package is [ ESM only] ( https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c ) :
18
- Node 12+ is needed to use it and it must be ` import ` ed instead of ` require ` d.
31
+ This package is a tiny utility that lets you find definitions.
19
32
20
- [ npm] [ ] :
33
+ ## When should I use this?
34
+
35
+ This utility can be useful because definitions can occur after the things that
36
+ reference them.
37
+ It’s small and protects against prototype pollution.
38
+
39
+ ## Install
40
+
41
+ This package is [ ESM only] [ esm ] .
42
+ In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
21
43
22
44
``` sh
23
45
npm install mdast-util-definitions
24
46
```
25
47
48
+ In Deno with [ ` esm.sh ` ] [ esmsh ] :
49
+
50
+ ``` js
51
+ import {definitions } from ' https://esm.sh/mdast-util-definitions@5'
52
+ ```
53
+
54
+ In browsers with [ ` esm.sh ` ] [ esmsh ] :
55
+
56
+ ``` html
57
+ <script type =" module" >
58
+ import {definitions } from ' https://esm.sh/mdast-util-definitions@5?bundle'
59
+ </script >
60
+ ```
61
+
26
62
## Use
27
63
28
64
``` js
29
- import {remark } from ' remark '
65
+ import {fromMarkdown } from ' mdast-util-from-markdown '
30
66
import {definitions } from ' mdast-util-definitions'
31
67
32
- const tree = remark (). parse (' [example]: https://example.com "Example"' )
68
+ const tree = fromMarkdown (' [example]: https://example.com "Example"' )
33
69
34
70
const definition = definitions (tree)
35
71
@@ -42,35 +78,43 @@ definition('foo')
42
78
43
79
## API
44
80
45
- This package exports the following identifiers: ` definitions ` .
81
+ This package exports the identifier ` definitions ` .
46
82
There is no default export.
47
83
48
- ### ` definitions(tree ) `
84
+ ### ` definitions(node ) `
49
85
50
- Create a cache of all [ definition] [ ] s in [ ` tree ` ] [ node ] .
51
-
52
- Uses CommonMark precedence: prefers the first definitions for duplicate
53
- definitions.
86
+ Find [ definition] [ ] s in ` node ` ([ ` Node ` ] [ node ] ).
87
+ Uses CommonMark precedence, which means that earlier definitions are preferred
88
+ over duplicate later definitions.
54
89
55
90
###### Returns
56
91
57
- [ ` Function ` ] [ fn-definition ]
92
+ ` definition ` ( [ ` Function ` ] [ fn-definition ] ).
58
93
59
94
### ` definition(identifier) `
60
95
61
- ###### Parameters
62
-
63
- * ` identifier ` (` string ` ) — [ Identifier] [ ] of [ definition] [ ] .
96
+ Get a node from the bound definition cache by its ` identifier ` (` string ` ).
64
97
65
98
###### Returns
66
99
67
- [ ` Node? ` ] [ node ] — [ Definition] [ ] , if found.
100
+ [ Definition] [ ] , if found ( [ ` Node? ` ] [ node ] )
68
101
69
- ## Security
102
+ ## Types
103
+
104
+ This package is fully typed with [ TypeScript] [ ] .
105
+ There are no additional exported types.
106
+
107
+ ## Compatibility
108
+
109
+ Projects maintained by the unified collective are compatible with all maintained
110
+ versions of Node.js.
111
+ As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
112
+ Our projects sometimes work with older versions, but this is not guaranteed.
70
113
71
- Use of ` mdast-util-definitions ` does not involve [ ** hast** ] [ hast ] or user
72
- content so there are no openings for [ cross-site scripting (XSS)] [ xss ] attacks.
114
+ ## Security
73
115
116
+ Use of ` mdast-util-definitions ` does not involve ** [ hast] [ ] ** or user content so
117
+ there are no openings for [ cross-site scripting (XSS)] [ xss ] attacks.
74
118
Additionally, safe guards are in place to protect against prototype poisoning.
75
119
76
120
## Related
@@ -80,8 +124,8 @@ Additionally, safe guards are in place to protect against prototype poisoning.
80
124
81
125
## Contribute
82
126
83
- See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
84
- started.
127
+ See [ ` contributing.md ` ] [ contributing ] in [ ` syntax-tree/.github ` ] [ health ] for
128
+ ways to get started.
85
129
See [ ` support.md ` ] [ support ] for ways to get help.
86
130
87
131
This project has a [ code of conduct] [ coc ] .
@@ -126,11 +170,19 @@ abide by its terms.
126
170
127
171
[ npm ] : https://docs.npmjs.com/cli/install
128
172
129
- [ contributing ] : https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
173
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
174
+
175
+ [ esmsh ] : https://esm.sh
176
+
177
+ [ typescript ] : https://www.typescriptlang.org
130
178
131
- [ support ] : https://github.com/syntax-tree/.github/blob/HEAD/support.md
179
+ [ health ] : https://github.com/syntax-tree/.github
132
180
133
- [ coc ] : https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
181
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/main/contributing.md
182
+
183
+ [ support ] : https://github.com/syntax-tree/.github/blob/main/support.md
184
+
185
+ [ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
134
186
135
187
[ mdast ] : https://github.com/syntax-tree/mdast
136
188
@@ -140,8 +192,6 @@ abide by its terms.
140
192
141
193
[ definition ] : https://github.com/syntax-tree/mdast#definition
142
194
143
- [ identifier ] : https://github.com/syntax-tree/mdast#association
144
-
145
195
[ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
146
196
147
197
[ hast ] : https://github.com/syntax-tree/hast
0 commit comments