nlcst utility to classify ASCII emoticons as EmoticonNode
s.
- What is this?
- When should I use this?
- Install
- Use
- API
- Types
- Compatibility
- Related
- Contribute
- License
This utility searches for emoticons made with punctuation marks and symbols, and turns them into separate nodes.
This package is a tiny utility that helps when dealing with plain-text emoticons in natural language. The plugin retext-emoji
wraps this utility and others at a higher-level (easier) abstraction.
This package is ESM only. In Node.js (version 12.20+, 14.14+, 16.0+, 18.0+), install with npm:
npm install nlcst-emoticon-modifier
In Deno with esm.sh
:
import {emoticonModifier} from "https://esm.sh/nlcst-emoticon-modifier@2"
In browsers with esm.sh
:
<script type="module"> import {emoticonModifier} from "https://esm.sh/nlcst-emoticon-modifier@2?bundle" </script>
import {emoticonModifier} from 'nlcst-emoticon-modifier' import {inspect} from 'unist-util-inspect' import {ParseEnglish} from 'parse-english' const sentence = new ParseEnglish().parse('This makes me feel :).').children[0].children[0] emoticonModifier(sentence) console.log(inspect(sentence))
Yields:
SentenceNode[10] ├─ WordNode[1] │ └─ TextNode: 'This' ├─ WhiteSpaceNode: ' ' ├─ WordNode[1] │ └─ TextNode: 'makes' ├─ WhiteSpaceNode: ' ' ├─ WordNode[1] │ └─ TextNode: 'me' ├─ WhiteSpaceNode: ' ' ├─ WordNode[1] │ └─ TextNode: 'feel' ├─ WhiteSpaceNode: ' ' ├─ EmoticonNode: ':)' └─ PunctuationNode: '.'
This package exports the identifier emoticonModifier
. There is no default export.
Classify ASCII emoticons in node
(Sentence
) as EmoticonNode
s.
This package is fully typed with TypeScript. It exports no additional types.
It also registers the Emoticon
node type with @types/nlcst
. If you’re working with the syntax tree, make sure to import this utility somewhere in your types, as that registers the new node types in the tree.
/** * @typedef {import('nlcst-emoticon-modifier')} */ import {visit} from 'unist-util-visit' /** @type {import('nlcst').Root} */ const tree = getNodeSomeHow() visit(tree, (node) => { // `node` can now be a `Emoticon` node. })
Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+. Our projects sometimes work with older versions, but this is not guaranteed.
nlcst-affix-emoticon-modifier
— merge affix emoticons into the previous sentence in nlcstnlcst-emoji-modifier
— support emoji
See contributing.md
in syntax-tree/.github
for ways to get started. See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.