@@ -39,7 +39,7 @@ about “monsieur”.
39
39
## Install
40
40
41
41
This package is [ ESM only] [ esm ] .
42
- In Node.js (version 12.20+, 14.14+, 16.0+, 18 .0+), install with [ npm] [ ] :
42
+ In Node.js (version 14.14+ and 16 .0+), install with [ npm] [ ] :
43
43
44
44
``` sh
45
45
npm install nlcst-is-literal
@@ -48,14 +48,14 @@ npm install nlcst-is-literal
48
48
In Deno with [ ` esm.sh ` ] [ esmsh ] :
49
49
50
50
``` js
51
- import {isLiteral } from " https://esm.sh/nlcst-is-literal@2"
51
+ import {isLiteral } from ' https://esm.sh/nlcst-is-literal@2'
52
52
```
53
53
54
54
In browsers with [ ` esm.sh ` ] [ esmsh ] :
55
55
56
56
``` html
57
57
<script type =" module" >
58
- import {isLiteral } from " https://esm.sh/nlcst-is-literal@2?bundle"
58
+ import {isLiteral } from ' https://esm.sh/nlcst-is-literal@2?bundle'
59
59
</script >
60
60
```
61
61
@@ -78,24 +78,20 @@ The word — quux — is meant as a literal.
78
78
…and our module ` example.js ` looks as follows:
79
79
80
80
``` js
81
- import {readSync } from ' to-vfile'
82
- import {unified } from ' unified'
83
- import retextEnglish from ' retext-english'
81
+ import {read } from ' to-vfile'
82
+ import {ParseEnglish } from ' parse-english'
84
83
import {visit } from ' unist-util-visit'
85
84
import {toString } from ' nlcst-to-string'
86
85
import {isLiteral } from ' nlcst-is-literal'
87
86
88
- const file = readSync (' example.txt' )
87
+ const file = await read (' example.txt' )
88
+ const tree = new ParseEnglish ().parse (String (file))
89
89
90
- const tree = unified ().use (retextEnglish).parse (file)
91
-
92
- visit (tree, ' WordNode' , visitor)
93
-
94
- function visitor (node , index , parent ) {
90
+ visit (tree, ' WordNode' , function (node , index , parent ) {
95
91
if (isLiteral (parent, index)) {
96
92
console .log (toString (node))
97
93
}
98
- }
94
+ })
99
95
```
100
96
101
97
…now running ` node example.js ` yields:
@@ -110,20 +106,32 @@ quux
110
106
111
107
## API
112
108
113
- This package exports the identifier ` isLiteral ` .
109
+ This package exports the identifier [ ` isLiteral ` ] [ isliteral ] .
114
110
There is no default export.
115
111
116
112
### ` isLiteral(parent, index|child) `
117
113
118
- Check if the ` child ` in ` parent ` is enclosed by matching delimiters.
119
- If an ` index ` is given, the [ child] [ ] of ` parent ` at that [ index] [ ] is checked.
114
+ Check if the child in ` parent ` at ` index ` is enclosed by matching delimiters.
120
115
121
116
For example, ` foo ` is literal in the following samples:
122
117
123
118
* ` Foo - is meant as a literal. `
124
119
* ` Meant as a literal is - foo. `
125
120
* ` The word “foo” is meant as a literal. `
126
121
122
+ ###### Parameters
123
+
124
+ * ` parent ` ([ ` Node ` ] [ node ] )
125
+ — parent node
126
+ * ` index ` (` number ` )
127
+ — index of child in parent
128
+ * ` child ` ([ ` Node ` ] [ node ] )
129
+ — child node of parent
130
+
131
+ ###### Returns
132
+
133
+ Whether the child is a literal (` boolean ` ).
134
+
127
135
## Types
128
136
129
137
This package is fully typed with [ TypeScript] [ ] .
@@ -133,7 +141,7 @@ It exports no additional types.
133
141
134
142
Projects maintained by the unified collective are compatible with all maintained
135
143
versions of Node.js.
136
- As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18 .0+.
144
+ As of now, that is Node.js 14.14+ and 16 .0+.
137
145
Our projects sometimes work with older versions, but this is not guaranteed.
138
146
139
147
## Related
@@ -207,6 +215,6 @@ abide by its terms.
207
215
208
216
[ nlcst ] : https://github.com/syntax-tree/nlcst
209
217
210
- [ index ] : https://github.com/syntax-tree/unist#index
218
+ [ node ] : https://github.com/syntax-tree/nlcst#nodes
211
219
212
- [ child ] : https://github.com/syntax-tree/unist#child
220
+ [ isliteral ] : #isliteralparent-indexchild
0 commit comments