Skip to content

Commit bea8e55

Browse files
committed
Add improved docs
1 parent 282e12d commit bea8e55

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

lib/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ const open = Object.keys(pairs)
5656
* Check if the child in `parent` at `index` is enclosed by matching
5757
* delimiters.
5858
*
59+
* For example, `foo` is literal in the following samples:
60+
*
61+
* * `Foo - is meant as a literal.`
62+
* * `Meant as a literal is - foo.`
63+
* * `The word “foo” is meant as a literal.`
64+
*
5965
* @template {Parent} ParentType
6066
* Parent node.
6167
* @param {ParentType} parent

readme.md

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ about “monsieur”.
3939
## Install
4040

4141
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][]:
4343

4444
```sh
4545
npm install nlcst-is-literal
@@ -48,14 +48,14 @@ npm install nlcst-is-literal
4848
In Deno with [`esm.sh`][esmsh]:
4949

5050
```js
51-
import {isLiteral} from "https://esm.sh/nlcst-is-literal@2"
51+
import {isLiteral} from 'https://esm.sh/nlcst-is-literal@2'
5252
```
5353

5454
In browsers with [`esm.sh`][esmsh]:
5555

5656
```html
5757
<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'
5959
</script>
6060
```
6161

@@ -78,24 +78,20 @@ The word — quux — is meant as a literal.
7878
…and our module `example.js` looks as follows:
7979

8080
```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'
8483
import {visit} from 'unist-util-visit'
8584
import {toString} from 'nlcst-to-string'
8685
import {isLiteral} from 'nlcst-is-literal'
8786

88-
const file = readSync('example.txt')
87+
const file = await read('example.txt')
88+
const tree = new ParseEnglish().parse(String(file))
8989

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) {
9591
if (isLiteral(parent, index)) {
9692
console.log(toString(node))
9793
}
98-
}
94+
})
9995
```
10096

10197
…now running `node example.js` yields:
@@ -110,20 +106,32 @@ quux
110106

111107
## API
112108

113-
This package exports the identifier `isLiteral`.
109+
This package exports the identifier [`isLiteral`][isliteral].
114110
There is no default export.
115111

116112
### `isLiteral(parent, index|child)`
117113

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.
120115

121116
For example, `foo` is literal in the following samples:
122117

123118
* `Foo - is meant as a literal.`
124119
* `Meant as a literal is - foo.`
125120
* `The word “foo” is meant as a literal.`
126121

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+
127135
## Types
128136

129137
This package is fully typed with [TypeScript][].
@@ -133,7 +141,7 @@ It exports no additional types.
133141

134142
Projects maintained by the unified collective are compatible with all maintained
135143
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+.
137145
Our projects sometimes work with older versions, but this is not guaranteed.
138146

139147
## Related
@@ -207,6 +215,6 @@ abide by its terms.
207215

208216
[nlcst]: https://github.com/syntax-tree/nlcst
209217

210-
[index]: https://github.com/syntax-tree/unist#index
218+
[node]: https://github.com/syntax-tree/nlcst#nodes
211219

212-
[child]: https://github.com/syntax-tree/unist#child
220+
[isliteral]: #isliteralparent-indexchild

0 commit comments

Comments
 (0)