Skip to content

Commit 32bfb7c

Browse files
committed
Add improved docs
1 parent 46a6e0d commit 32bfb7c

File tree

2 files changed

+92
-22
lines changed

2 files changed

+92
-22
lines changed

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import {emoticon} from 'emoticon'
1919
// has walked 5 characters.
2020
const maxEmoticonLength = 5
2121

22-
/** @type {Array.<string>} */
22+
/** @type {Array<string>} */
2323
const emoticons = []
24-
/** @type {Array.<string>} */
24+
/** @type {Array<string>} */
2525
const start = []
26-
/** @type {Array.<string>} */
26+
/** @type {Array<string>} */
2727
const end = []
2828

2929
unpack()

readme.md

Lines changed: 89 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,57 @@
88
[![Backers][backers-badge]][collective]
99
[![Chat][chat-badge]][chat]
1010

11-
[**nlcst**][nlcst] utility to classify ASCII [emoticon][]s as `EmoticonNode`s.
11+
[nlcst][] utility to classify ASCII [emoticon][]s as `EmoticonNode`s.
1212

13-
> **Note**: You probably want to use [retext-emoji][].
13+
## Contents
1414

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+
* [`emoticonModifier(node)`](#emoticonmodifiernode)
21+
* [Types](#types)
22+
* [Compatibility](#compatibility)
23+
* [Related](#related)
24+
* [Contribute](#contribute)
25+
* [License](#license)
26+
27+
## What is this?
1628

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.
29+
This utility searches for emoticons made with punctuation marks and symbols,
30+
and turns them into separate nodes.
1931

20-
[npm][]:
32+
## When should I use this?
33+
34+
This package is a tiny utility that helps when dealing with plain-text emoticons
35+
in natural language.
36+
The plugin [`retext-emoji`][retext-emoji] wraps this utility and others at a
37+
higher-level (easier) abstraction.
38+
39+
## Install
40+
41+
This package is [ESM only][esm].
42+
In Node.js (version 12.20+, 14.14+, 16.0+, 18.0+), install with [npm][]:
2143

2244
```sh
2345
npm install nlcst-emoticon-modifier
2446
```
2547

48+
In Deno with [`esm.sh`][esmsh]:
49+
50+
```js
51+
import {emoticonModifier} from "https://esm.sh/nlcst-emoticon-modifier@2"
52+
```
53+
54+
In browsers with [`esm.sh`][esmsh]:
55+
56+
```html
57+
<script type="module">
58+
import {emoticonModifier} from "https://esm.sh/nlcst-emoticon-modifier@2?bundle"
59+
</script>
60+
```
61+
2662
## Use
2763

2864
```js
@@ -59,30 +95,56 @@ SentenceNode[10]
5995

6096
## API
6197

62-
This package exports the following identifiers: `emoticonModifier`.
98+
This package exports the identifier `emoticonModifier`.
6399
There is no default export.
64100

65-
### `emoticonModifier(sentence)`
101+
### `emoticonModifier(node)`
66102

67-
Classify ASCII [emoticon][]s as `EmoticonNode`s.
103+
Classify ASCII [emoticon][]s in `node` ([`Sentence`][sentence]) as
104+
`EmoticonNode`s.
68105

69-
##### Parameters
106+
## Types
70107

71-
###### `sentence`
108+
This package is fully typed with [TypeScript][].
109+
It exports no additional types.
72110

73-
Node to process ([`Sentence`][sentence]).
111+
It also registers the `Emoticon` node type with `@types/nlcst`.
112+
If you’re working with the syntax tree, make sure to import this utility
113+
somewhere in your types, as that registers the new node types in the tree.
114+
115+
```js
116+
/**
117+
* @typedef {import('nlcst-emoticon-modifier')}
118+
*/
119+
120+
import {visit} from 'unist-util-visit'
121+
122+
/** @type {import('nlcst').Root} */
123+
const tree = getNodeSomeHow()
124+
125+
visit(tree, (node) => {
126+
// `node` can now be a `Emoticon` node.
127+
})
128+
```
129+
130+
## Compatibility
131+
132+
Projects maintained by the unified collective are compatible with all maintained
133+
versions of Node.js.
134+
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
135+
Our projects sometimes work with older versions, but this is not guaranteed.
74136

75137
## Related
76138

77139
* [`nlcst-affix-emoticon-modifier`](https://github.com/syntax-tree/nlcst-affix-emoticon-modifier)
78-
Merge affix emoticons into the previous sentence in nlcst
140+
merge affix emoticons into the previous sentence in nlcst
79141
* [`nlcst-emoji-modifier`](https://github.com/syntax-tree/nlcst-emoji-modifier)
80-
Support emoji
142+
support emoji
81143

82144
## Contribute
83145

84-
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
85-
started.
146+
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
147+
ways to get started.
86148
See [`support.md`][support] for ways to get help.
87149

88150
This project has a [code of conduct][coc].
@@ -123,15 +185,23 @@ abide by its terms.
123185

124186
[npm]: https://docs.npmjs.com/cli/install
125187

188+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
189+
190+
[esmsh]: https://esm.sh
191+
192+
[typescript]: https://www.typescriptlang.org
193+
126194
[license]: license
127195

128196
[author]: https://wooorm.com
129197

130-
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
198+
[health]: https://github.com/syntax-tree/.github
199+
200+
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
131201

132-
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
202+
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
133203

134-
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
204+
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
135205

136206
[retext-emoji]: https://github.com/retextjs/retext-emoji
137207

0 commit comments

Comments
 (0)