|
8 | 8 | [![Backers][backers-badge]][collective]
|
9 | 9 | [![Chat][chat-badge]][chat]
|
10 | 10 |
|
11 |
| -[**nlcst**][nlcst] utility to move initial emoticons into the previous sentence. |
12 |
| -Useful because many people place an emoticon, representing emotion related to |
13 |
| -the previous sentence, after a terminal marker. :unamused: |
| 11 | +[nlcst][] utility to move initial emoticons into the previous sentence. |
14 | 12 |
|
15 |
| -> **Note**: You probably want to use [retext-emoji][]. |
| 13 | +## Contents |
16 | 14 |
|
17 |
| -## 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 | + * [`affixEmoticonModifier(paragraph)`](#affixemoticonmodifierparagraph) |
| 21 | +* [Types](#types) |
| 22 | +* [Compatibility](#compatibility) |
| 23 | +* [Related](#related) |
| 24 | +* [Contribute](#contribute) |
| 25 | +* [License](#license) |
| 26 | + |
| 27 | +## What is this? |
| 28 | + |
| 29 | +This utility searches emoticon nodes (from |
| 30 | +[`nlcst-emoticon-modifier`][nlcst-emoticon-modifier] and |
| 31 | +[`nlcst-emoji-modifier`][nlcst-emoji-modifier]) that start a sentence and then |
| 32 | +moves them into the previous sentence. |
| 33 | + |
| 34 | +## When should I use this? |
18 | 35 |
|
19 |
| -This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): |
20 |
| -Node 12+ is needed to use it and it must be `import`ed instead of `require`d. |
| 36 | +This package is a tiny utility that helps when dealing with emoticons in natural |
| 37 | +language. |
| 38 | +It’s useful because many people place an emoticon or emoji, representing emotion |
| 39 | +related to the previous sentence, after a terminal marker. |
| 40 | +😒 |
| 41 | + |
| 42 | +The plugin [`retext-emoji`][retext-emoji] wraps this utility and others at a |
| 43 | +higher-level (easier) abstraction. |
| 44 | + |
| 45 | +## Install |
21 | 46 |
|
22 |
| -[npm][]: |
| 47 | +This package is [ESM only][esm]. |
| 48 | +In Node.js (version 12.20+, 14.14+, 16.0+, 18.0+), install with [npm][]: |
23 | 49 |
|
24 | 50 | ```sh
|
25 | 51 | npm install nlcst-affix-emoticon-modifier
|
26 | 52 | ```
|
27 | 53 |
|
| 54 | +In Deno with [`esm.sh`][esmsh]: |
| 55 | + |
| 56 | +```js |
| 57 | +import {affixEmoticonModifier} from "https://esm.sh/nlcst-affix-emoticon-modifier@2" |
| 58 | +``` |
| 59 | + |
| 60 | +In browsers with [`esm.sh`][esmsh]: |
| 61 | + |
| 62 | +```html |
| 63 | +<script type="module"> |
| 64 | + import {affixEmoticonModifier} from "https://esm.sh/nlcst-affix-emoticon-modifier@2?bundle" |
| 65 | +</script> |
| 66 | +``` |
| 67 | + |
28 | 68 | ## Use
|
29 | 69 |
|
30 | 70 | ```js
|
@@ -70,30 +110,55 @@ RootNode[1] (1:1-1:25, 0-24)
|
70 | 110 |
|
71 | 111 | ## API
|
72 | 112 |
|
73 |
| -This package exports the following identifiers: `affixEmoticonModifier`. |
| 113 | +This package exports the identifier `affixEmoticonModifier`. |
74 | 114 | There is no default export.
|
75 | 115 |
|
76 | 116 | ### `affixEmoticonModifier(paragraph)`
|
77 | 117 |
|
78 |
| -Merge affix emoticons (`EmoticonNode`) into the previous sentence. |
| 118 | +Merge affix emoticons (`EmoticonNode`) in `node` ([`Paragraph`][paragraph]). |
79 | 119 |
|
80 |
| -##### Parameters |
| 120 | +## Types |
81 | 121 |
|
82 |
| -###### `paragraph` |
| 122 | +This package is fully typed with [TypeScript][]. |
| 123 | +It exports no additional types. |
83 | 124 |
|
84 |
| -The node to process ([`Paragraph`][paragraph]). |
| 125 | +It also registers the `Emoticon` node type with `@types/nlcst`. |
| 126 | +If you’re working with the syntax tree, make sure to import this utility |
| 127 | +somewhere in your types, as that registers the new node types in the tree. |
| 128 | + |
| 129 | +```js |
| 130 | +/** |
| 131 | + * @typedef {import('nlcst-affix-emoticon-modifier')} |
| 132 | + */ |
| 133 | + |
| 134 | +import {visit} from 'unist-util-visit' |
| 135 | + |
| 136 | +/** @type {import('nlcst').Root} */ |
| 137 | +const tree = getNodeSomeHow() |
| 138 | + |
| 139 | +visit(tree, (node) => { |
| 140 | + // `node` can now be a `Emoticon` node. |
| 141 | +}) |
| 142 | +``` |
| 143 | + |
| 144 | +## Compatibility |
| 145 | + |
| 146 | +Projects maintained by the unified collective are compatible with all maintained |
| 147 | +versions of Node.js. |
| 148 | +As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+. |
| 149 | +Our projects sometimes work with older versions, but this is not guaranteed. |
85 | 150 |
|
86 | 151 | ## Related
|
87 | 152 |
|
88 | 153 | * [`nlcst-emoticon-modifier`](https://github.com/syntax-tree/nlcst-emoticon-modifier)
|
89 |
| - — Support emoticons |
| 154 | + — support emoticons |
90 | 155 | * [`nlcst-emoji-modifier`](https://github.com/syntax-tree/nlcst-emoji-modifier)
|
91 |
| - — Support emoji |
| 156 | + — support emoji and gemoji |
92 | 157 |
|
93 | 158 | ## Contribute
|
94 | 159 |
|
95 |
| -See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get |
96 |
| -started. |
| 160 | +See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for |
| 161 | +ways to get started. |
97 | 162 | See [`support.md`][support] for ways to get help.
|
98 | 163 |
|
99 | 164 | This project has a [Code of Conduct][coc].
|
@@ -134,18 +199,30 @@ abide by its terms.
|
134 | 199 |
|
135 | 200 | [npm]: https://docs.npmjs.com/cli/install
|
136 | 201 |
|
| 202 | +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c |
| 203 | + |
| 204 | +[esmsh]: https://esm.sh |
| 205 | + |
| 206 | +[typescript]: https://www.typescriptlang.org |
| 207 | + |
137 | 208 | [license]: license
|
138 | 209 |
|
139 | 210 | [author]: https://wooorm.com
|
140 | 211 |
|
141 |
| -[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md |
| 212 | +[health]: https://github.com/syntax-tree/.github |
142 | 213 |
|
143 |
| -[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md |
| 214 | +[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md |
144 | 215 |
|
145 |
| -[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md |
| 216 | +[support]: https://github.com/syntax-tree/.github/blob/main/support.md |
| 217 | + |
| 218 | +[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md |
146 | 219 |
|
147 | 220 | [retext-emoji]: https://github.com/retextjs/retext-emoji
|
148 | 221 |
|
149 | 222 | [nlcst]: https://github.com/syntax-tree/nlcst
|
150 | 223 |
|
151 | 224 | [paragraph]: https://github.com/syntax-tree/nlcst#paragraph
|
| 225 | + |
| 226 | +[nlcst-emoticon-modifier]: https://github.com/syntax-tree/nlcst-emoticon-modifier |
| 227 | + |
| 228 | +[nlcst-emoji-modifier]: https://github.com/syntax-tree/nlcst-emoji-modifier |
0 commit comments