8
8
[ ![ Backers] [ backers-badge ]] [ collective ]
9
9
[ ![ Chat] [ chat-badge ]] [ chat ]
10
10
11
- [ ** unist** ] [ unist ] utility to pretty print the positional information of a node.
11
+ ** [ unist] [ ] ** utility to pretty print the positional information of a node.
12
12
13
- ## Install
13
+ ## Contents
14
+
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
+ * [ ` stringifyPosition(node|position|point) ` ] ( #stringifypositionnodepositionpoint )
21
+ * [ Types] ( #types )
22
+ * [ Compatibility] ( #compatibility )
23
+ * [ Security] ( #security )
24
+ * [ Related] ( #related )
25
+ * [ Contribute] ( #contribute )
26
+ * [ License] ( #license )
27
+
28
+ ## What is this?
29
+
30
+ This package is a utility that takes any [ unist] [ ] (whether mdast, hast, etc)
31
+ node, position, or point, and serializes its positional info.
14
32
15
- This package is [ ESM only] ( https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c ) :
16
- Node 12+ is needed to use it and it must be ` import ` ed instead of ` require ` d.
33
+ ## When should I use this?
34
+
35
+ This utility is useful to display where something occurred in the original
36
+ document, in one standard way, for humans.
37
+ For example, when throwing errors or warning messages about something.
38
+
39
+ ## Install
17
40
18
- [ npm] [ ] :
41
+ This package is [ ESM only] [ esm ] .
42
+ In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
19
43
20
44
``` sh
21
45
npm install unist-util-stringify-position
22
46
```
23
47
24
- ## Use
48
+ In Deno with [ ` esm.sh ` ] [ esmsh ] :
25
49
26
50
``` js
27
- import {stringifyPosition } from ' unist-util-stringify-position'
51
+ import {stringifyPosition } from ' https://esm.sh/unist-util-stringify-position@3'
52
+ ```
53
+
54
+ In browsers with [ ` esm.sh ` ] [ esmsh ] :
55
+
56
+ ``` html
57
+ <script type =" module" >
58
+ import {stringifyPosition } from ' https://esm.sh/unist-util-stringify-position@3?bundle'
59
+ </script >
60
+ ```
28
61
29
- // Point
30
- stringifyPosition ({line: 2 , column: 3 }) // => '2:3'
62
+ ## Use
31
63
32
- // Position
33
- stringifyPosition ({start : {line : 2 }, end : {line : 3 }}) // => '2:1-3:1 '
64
+ ``` js
65
+ import { stringifyPosition } from ' unist-util-stringify-position '
34
66
35
- // Node
67
+ stringifyPosition ({line: 2 , column: 3 }) // => '2:3' (point)
68
+ stringifyPosition ({start: {line: 2 }, end: {line: 3 }}) // => '2:1-3:1' (position)
36
69
stringifyPosition ({
37
70
type: ' text' ,
38
71
value: ' !' ,
39
72
position: {
40
73
start: {line: 5 , column: 11 },
41
74
end: {line: 5 , column: 12 }
42
75
}
43
- }) // => '5:11-5:12'
76
+ }) // => '5:11-5:12' (node)
44
77
```
45
78
46
79
## API
47
80
48
- This package exports the following identifiers: ` stringifyPosition ` .
81
+ This package exports the identifier ` stringifyPosition ` .
49
82
There is no default export.
50
83
51
84
### ` stringifyPosition(node|position|point) `
52
85
53
- Stringify one [ point] [ ] , a [ position] [ ] (start and end [ point] [ ] s), or a node’s
54
- [ positional information] [ positional-information ] .
86
+ Stringify a [ point] [ ] , [ position] [ ] , or a [ node] [ ] .
55
87
56
88
###### Parameters
57
89
58
90
* ` node ` ([ ` Node ` ] [ node ] )
59
- — Node whose ` 'position' ` property to stringify
91
+ — node whose ` 'position' ` property to stringify
60
92
* ` position ` ([ ` Position ` ] [ position ] )
61
- — Position whose ` 'start' ` and ` 'end' ` points to stringify
93
+ — position whose ` 'start' ` and ` 'end' ` points to stringify
62
94
* ` point ` ([ ` Point ` ] [ point ] )
63
- — Point whose ` 'line' ` and ` 'column' ` to stringify
95
+ — point whose ` 'line' ` and ` 'column' ` to stringify
64
96
65
97
###### Returns
66
98
@@ -70,16 +102,32 @@ Stringify one [point][], a [position][] (start and end [point][]s), or a node’
70
102
An empty string (` '' ` ) is returned if the given value is neither ` node ` ,
71
103
` position ` , nor ` point ` .
72
104
105
+ ## Types
106
+
107
+ This package is fully typed with [ TypeScript] [ ] .
108
+ There are no additional types exported.
109
+
110
+ ## Compatibility
111
+
112
+ Projects maintained by the unified collective are compatible with all maintained
113
+ versions of Node.js.
114
+ As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
115
+ Our projects sometimes work with older versions, but this is not guaranteed.
116
+
117
+ ## Security
118
+
119
+ This project is safe.
120
+
73
121
## Related
74
122
75
123
* [ ` unist-util-generated ` ] ( https://github.com/syntax-tree/unist-util-generated )
76
- — Check if a node is generated
124
+ — check if a node is generated
77
125
* [ ` unist-util-position ` ] ( https://github.com/syntax-tree/unist-util-position )
78
- — Get positional info of nodes
126
+ — get positional info of nodes
79
127
* [ ` unist-util-remove-position ` ] ( https://github.com/syntax-tree/unist-util-remove-position )
80
- — Remove positional info from trees
128
+ — remove positional info from trees
81
129
* [ ` unist-util-source ` ] ( https://github.com/syntax-tree/unist-util-source )
82
- — Get the source of a value (node or position) in a file
130
+ — get the source of a value (node or position) in a file
83
131
84
132
## Contribute
85
133
@@ -129,6 +177,12 @@ abide by its terms.
129
177
130
178
[ author ] : https://wooorm.com
131
179
180
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
181
+
182
+ [ esmsh ] : https://esm.sh
183
+
184
+ [ typescript ] : https://www.typescriptlang.org
185
+
132
186
[ contributing ] : https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
133
187
134
188
[ support ] : https://github.com/syntax-tree/.github/blob/HEAD/support.md
@@ -142,5 +196,3 @@ abide by its terms.
142
196
[ position ] : https://github.com/syntax-tree/unist#position
143
197
144
198
[ point ] : https://github.com/syntax-tree/unist#point
145
-
146
- [ positional-information ] : https://github.com/syntax-tree/unist#positional-information
0 commit comments