Nicely Printed Maps

    nlcst-emoticon-modifier
    TypeScript icon, indicating that this package has built-in type declarations

    2.1.1 • Public • Published

    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 14.14+ and 16.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)

    Merge emoticons in a SentenceNode into EmoticonNodes.

    Parameters
    • node (Sentence) — nlcst sentence to transform
    Returns

    Nothing (void).

    Emoticon

    Emoticon node (TypeScript type).

    Type
    import type {Literal} from 'nlcst'
    
    interface Emoticon extends Literal {
      type: 'EmoticonNode'
    }

    Types

    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-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 14.14+ and 16.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

    Install

    npm i nlcst-emoticon-modifier

    DownloadsWeekly Downloads

    8,619

    Version

    2.1.1

    License

    MIT

    Unpacked Size

    13.6 kB

    Total Files

    8

    Last publish

    Collaborators

    • wooorm
    • kmck