nlcst-emoticon-modifier
nlcst-emoticon-modifier is a specialized utility within the `unified` ecosystem, designed to process Natural Language Concrete Syntax Trees (NLCST). It identifies ASCII-based emoticons (e.g., `:)`, `:(`) within text and transforms them into dedicated `EmoticonNode` objects in the syntax tree. This package is currently stable at version `3.0.1` and follows the `unified` collective's release strategy, which typically involves new major versions for significant breaking changes like Node.js version updates or module system transitions. It is a foundational tool for natural language processing, offering a precise way to classify emoticons, distinguishing itself by its integration with the `nlcst` specification and its ESM-only distribution. Higher-level plugins, such as `retext-emoji`, build upon this utility for broader emoji and emoticon support.
Common errors
-
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/nlcst-emoticon-modifier/index.js not supported.
cause Attempting to use `require()` to import an ESM-only package.fixRefactor your code to use `import { emoticonModifier } from 'nlcst-emoticon-modifier'` within an ES module context. Ensure your `package.json` has `"type": "module"` or files end with `.mjs`. -
TypeError: emoticonModifier is not a function
cause Incorrectly importing the `emoticonModifier` symbol, typically by trying to import a default export or using `require()` incorrectly.fixUse a named import: `import { emoticonModifier } from 'nlcst-emoticon-modifier'`. The package does not provide a default export. -
TS2307: Cannot find module 'nlcst-emoticon-modifier' or its corresponding type declarations.
cause TypeScript compiler cannot locate the type definitions for the package, often related to `moduleResolution` settings or `skipLibCheck`.fixEnsure `npm install` has been run and `@types/nlcst` is installed if you're working with nlcst nodes directly. Check `tsconfig.json` for `moduleResolution` set to `node16` or `bundler` for modern ESM environments.
Warnings
- breaking Version 3.0.0 updated the minimum Node.js requirement to Node.js 16 and above.
- breaking Version 2.0.0 switched the package to be ESM-only. CommonJS `require()` statements are no longer supported.
- breaking Version 3.0.0 introduced the `exports` field in `package.json`, which affects how modules are resolved, especially for direct file imports (e.g., `require('pkg/file.js')`).
- breaking Version 3.0.0 removed the `complex-types.d.ts` file.
- gotcha To correctly register the `Emoticon` node type for TypeScript within the `nlcst` ecosystem (e.g., for `unist-util-visit`), you need to import the `nlcst-emoticon-modifier` package somewhere in your type declarations or application.
Install
-
npm install nlcst-emoticon-modifier -
yarn add nlcst-emoticon-modifier -
pnpm add nlcst-emoticon-modifier
Imports
- emoticonModifier
const emoticonModifier = require('nlcst-emoticon-modifier')import { emoticonModifier } from 'nlcst-emoticon-modifier' - Emoticon
import { Emoticon } from 'nlcst-emoticon-modifier'import type { Emoticon } from 'nlcst-emoticon-modifier'
Quickstart
import { emoticonModifier } from 'nlcst-emoticon-modifier';
import { ParseEnglish } from 'parse-english';
import { inspect } from 'unist-util-inspect';
const parser = new ParseEnglish();
parser.tokenizeSentencePlugins.unshift(emoticonModifier);
const sentence = parser.parse('This makes me feel :).').children[0].children[0];
console.log(inspect(sentence));