Project: syntax-tree/nlcst-emoji-modifier

Package: nlcst-emoji-modifier@5.1.0

  1. Dependents: 0
  2. nlcst utility to support emoji
  1. util 147
  2. utility 143
  3. unist 129
  4. nlcst 14
  5. nlcst-util 9
  6. emoji 5
  7. emoticon 4


Build Coverage Downloads Size Sponsors Backers Chat

nlcst utility to classify emoji and gemoji shortcodes as EmoticonNodes.


What is this?

This utility searches for emoji (πŸ‘) and gemoji shortcodes (:+1:) and turns them into separate nodes.

When should I use this?

This package is a tiny utility that helps when dealing with emoji and gemoji 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 14.14+ and 16.0+), install with npm:

npm install nlcst-emoji-modifier

In Deno with esm.sh:

import {emojiModifier} from 'https://esm.sh/nlcst-emoji-modifier@5'

In browsers with esm.sh:

<script type="module">
  import {emojiModifier} from 'https://esm.sh/nlcst-emoji-modifier@5?bundle'


import {emojiModifier} from 'nlcst-emoji-modifier'
import {inspect} from 'unist-util-inspect'
import {ParseEnglish} from 'parse-english'

const english = new ParseEnglish()

console.log(inspect(english.parse('It’s raining :cat:s and :dog:s.')))


RootNode[1] (1:1-1:32, 0-31)
└─ ParagraphNode[1] (1:1-1:32, 0-31)
   └─ SentenceNode[11] (1:1-1:32, 0-31)
      β”œβ”€ WordNode[3] (1:1-1:5, 0-4)
      β”‚  β”œβ”€ TextNode: "It" (1:1-1:3, 0-2)
      β”‚  β”œβ”€ PunctuationNode: "’" (1:3-1:4, 2-3)
      β”‚  └─ TextNode: "s" (1:4-1:5, 3-4)
      β”œβ”€ WhiteSpaceNode: " " (1:5-1:6, 4-5)
      β”œβ”€ WordNode[1] (1:6-1:13, 5-12)
      β”‚  └─ TextNode: "raining" (1:6-1:13, 5-12)
      β”œβ”€ WhiteSpaceNode: " " (1:13-1:14, 12-13)
      β”œβ”€ EmoticonNode: ":cat:" (1:14-1:19, 13-18)
      β”œβ”€ WordNode[1] (1:19-1:20, 18-19)
      β”‚  └─ TextNode: "s" (1:19-1:20, 18-19)
      β”œβ”€ WhiteSpaceNode: " " (1:20-1:21, 19-20)
      β”œβ”€ WordNode[1] (1:21-1:24, 20-23)
      β”‚  └─ TextNode: "and" (1:21-1:24, 20-23)
      β”œβ”€ WhiteSpaceNode: " " (1:24-1:25, 23-24)
      β”œβ”€ EmoticonNode: ":dog:" (1:25-1:30, 24-29)
      └─ WordNode[2] (1:30-1:32, 29-31)
         β”œβ”€ TextNode: "s" (1:30-1:31, 29-30)
         └─ PunctuationNode: "." (1:31-1:32, 30-31)


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


Classify emoji (πŸ‘) and Gemoji (GitHub emoji, πŸ‘) in node as Emoticons.


Given, transformed, node (Sentence).


Emoticon node (TypeScript type).

See Emoticon in nlcst-emoticon-modifier.


This package is fully typed with TypeScript. It exports the additional type Emoticon.

It also registers the Emoticon node type with @types/nlcst in SentenceContentMap. 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-emoji-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 14.14+ and 16.0+. Our projects sometimes work with older versions, but this is not guaranteed.


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.


MIT Β© Titus Wormer