nlcst-emoji-modifier

nlcst utility to support emoji

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
nlcst-emoji-modifier
6.0.29 months ago9 years agoMinified + gzip package size for nlcst-emoji-modifier in KB

Readme

nlcst-emoji-modifier
!Buildbuild-badgebuild !Coveragecoverage-badgecoverage !Downloadsdownloads-badgedownloads !Sizesize-badgesize !Sponsorssponsors-badgecollective !Backersbackers-badgecollective !Chatchat-badgechat
nlcst utility to classify emoji and gemoji shortcodes as EmoticonNodes.

Contents

*   [`emojiModifier(node)`](#emojimodifiernode)

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-emojiretext-emoji wraps this utility and others at a higher-level (easier) abstraction.

Install

This package is ESM onlyesm. In Node.js (version 16+), install with npm:
npm install nlcst-emoji-modifier

In Deno with esm.shesmsh:
import {emojiModifier} from 'https://esm.sh/nlcst-emoji-modifier@6'

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

Use

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

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 identifier emojiModifierapi-emoji-modifier. There is no default export.

emojiModifier(node)

Classify emoji (πŸ‘) and Gemoji (GitHub emoji, :+1:) in node as Emoticons.
See Emoticon in nlcst-emoticon-modifieremoticon-mofifier-emoticon.
Parameters
β€” sentence to transform
Returns
Nothing (undefined).

Types

This package is fully typed with TypeScript. It exports no additional types
See Emoticon in nlcst-emoticon-modifieremoticon-mofifier-emoticon on how to register it in TypeScript.

Compatibility

Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, nlcst-emoji-modifier@^6, compatible with Node.js 16.

Related

β€” merge affix emoticons into the previous sentence in nlcst
β€” support emoticons

Contribute

See contributing.mdcontributing in syntax-tree/.githubhealth for ways to get started. See support.mdsupport 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.

License

MITlicense Β© Titus Wormerauthor