Skip to content

syntax-tree/nlcst-emoticon-modifier

nlcst-emoticon-modifier

Build Coverage Downloads Size Sponsors Backers Chat

nlcst utility to classify ASCII emoticons as EmoticonNodes.

Contents

What is this?

This utility searches for emoticons made with punctuation marks and symbols, and turns them into separate nodes.

When should I use this?

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.

Install

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>

Use

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: '.'

API

This package exports the identifier emoticonModifier. There is no default export.

emoticonModifier(node)

Classify ASCII emoticons in node (Sentence) as EmoticonNodes.

Types

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. })

Compatibility

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.

Related

Contribute

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.

License

MIT © Titus Wormer

About

utility to support emoticons in nlcst

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors 2

  •  
  •