|
8 | 8 | [![Backers][backers-badge]][collective]
|
9 | 9 | [![Chat][chat-badge]][chat]
|
10 | 10 |
|
11 |
| -[**nlcst**][nlcst] utility to classify ASCII [emoticon][]s as `EmoticonNode`s. |
| 11 | +[nlcst][] utility to classify ASCII [emoticon][]s as `EmoticonNode`s. |
12 | 12 |
|
13 |
| -> **Note**: You probably want to use [retext-emoji][]. |
| 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 | + * [`emoticonModifier(node)`](#emoticonmodifiernode) |
| 21 | +* [Types](#types) |
| 22 | +* [Compatibility](#compatibility) |
| 23 | +* [Related](#related) |
| 24 | +* [Contribute](#contribute) |
| 25 | +* [License](#license) |
| 26 | + |
| 27 | +## What is this? |
16 | 28 |
|
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. |
19 | 31 |
|
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][]: |
21 | 43 |
|
22 | 44 | ```sh
|
23 | 45 | npm install nlcst-emoticon-modifier
|
24 | 46 | ```
|
25 | 47 |
|
| 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 | + |
26 | 62 | ## Use
|
27 | 63 |
|
28 | 64 | ```js
|
@@ -59,30 +95,56 @@ SentenceNode[10]
|
59 | 95 |
|
60 | 96 | ## API
|
61 | 97 |
|
62 |
| -This package exports the following identifiers: `emoticonModifier`. |
| 98 | +This package exports the identifier `emoticonModifier`. |
63 | 99 | There is no default export.
|
64 | 100 |
|
65 |
| -### `emoticonModifier(sentence)` |
| 101 | +### `emoticonModifier(node)` |
66 | 102 |
|
67 |
| -Classify ASCII [emoticon][]s as `EmoticonNode`s. |
| 103 | +Classify ASCII [emoticon][]s in `node` ([`Sentence`][sentence]) as |
| 104 | +`EmoticonNode`s. |
68 | 105 |
|
69 |
| -##### Parameters |
| 106 | +## Types |
70 | 107 |
|
71 |
| -###### `sentence` |
| 108 | +This package is fully typed with [TypeScript][]. |
| 109 | +It exports no additional types. |
72 | 110 |
|
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. |
74 | 136 |
|
75 | 137 | ## Related
|
76 | 138 |
|
77 | 139 | * [`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 |
79 | 141 | * [`nlcst-emoji-modifier`](https://github.com/syntax-tree/nlcst-emoji-modifier)
|
80 |
| - — Support emoji |
| 142 | + — support emoji |
81 | 143 |
|
82 | 144 | ## Contribute
|
83 | 145 |
|
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. |
86 | 148 | See [`support.md`][support] for ways to get help.
|
87 | 149 |
|
88 | 150 | This project has a [code of conduct][coc].
|
@@ -123,15 +185,23 @@ abide by its terms.
|
123 | 185 |
|
124 | 186 | [npm]: https://docs.npmjs.com/cli/install
|
125 | 187 |
|
| 188 | +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c |
| 189 | + |
| 190 | +[esmsh]: https://esm.sh |
| 191 | + |
| 192 | +[typescript]: https://www.typescriptlang.org |
| 193 | + |
126 | 194 | [license]: license
|
127 | 195 |
|
128 | 196 | [author]: https://wooorm.com
|
129 | 197 |
|
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 |
131 | 201 |
|
132 |
| -[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md |
| 202 | +[support]: https://github.com/syntax-tree/.github/blob/main/support.md |
133 | 203 |
|
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 |
135 | 205 |
|
136 | 206 | [retext-emoji]: https://github.com/retextjs/retext-emoji
|
137 | 207 |
|
|
0 commit comments