nlcst-emoji-modifier
!Buildbuild-badgebuild
!Coveragecoverage-badgecoverage
!Downloadsdownloads-badgedownloads
!Sizesize-badgesize
!Sponsorssponsors-badgecollective
!Backersbackers-badgecollective
!Chatchat-badgechatnlcst utility to classify emoji and gemoji shortcodes as
EmoticonNode
s.Contents
* [`emojiModifier(node)`](#emojimodifiernode)
* [`Emoticon`](#emoticon)
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 pluginretext-emoji
retext-emoji wraps this utility and others at a
higher-level (easier) abstraction.Install
This package is ESM onlyesm. In Node.js (version 14.14+ and 16.0+), install with npm:npm install nlcst-emoji-modifier
In Deno with
esm.sh
esmsh:import {emojiModifier} from 'https://esm.sh/nlcst-emoji-modifier@5'
In browsers with
esm.sh
esmsh:<script type="module">
import {emojiModifier} from 'https://esm.sh/nlcst-emoji-modifier@5?bundle'
</script>
Use
import {emojiModifier} from 'nlcst-emoji-modifier'
import {inspect} from 'unist-util-inspect'
import {ParseEnglish} from 'parse-english'
const english = new ParseEnglish()
english.tokenizeSentencePlugins.unshift(emojiModifier)
console.log(inspect(english.parse('Itβs raining :cat:s and :dog:s.')))
Yields:
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)
API
This package exports the identifieremojiModifier
emojimodifier.
There is no default export.emojiModifier(node)
Classify emoji (π) and Gemoji (GitHub emoji, :+1:) in node
as Emoticon
s.Parameters
β sentence to transform
Returns
Given, transformed, node (Sentence
sentence).Emoticon
Emoticon node (TypeScript type).See
Emoticon
in nlcst-emoticon-modifier
emoticon-mofifier-emoticon.Types
This package is fully typed with TypeScript. It exports the additional typeEmoticon
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.
})
Compatibility
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.Related
β merge affix emoticons into the previous sentence in nlcst
β support emoticons
Contribute
Seecontributing.md
contributing in syntax-tree/.github
health for
ways to get started.
See support.md
support for ways to get help.This project has a code of conductcoc. By interacting with this repository, organization, or community you agree to abide by its terms.