{"id":11402,"library":"nlcst-is-literal","title":"nlcst Literal Node Checker","description":"nlcst-is-literal is a focused utility within the `unified` ecosystem, designed to determine if a `WordNode` within an NLCST (Natural Language Concrete Syntax Tree) parent node is semantically considered a \"literal.\" This check typically involves analyzing surrounding punctuation, such as quotes, parentheses, or dashes, that enclose the word. The package is currently stable at version `3.0.0` and follows the `unified` collective's release cadence, typically aligning major versions with Node.js LTS updates and significant architectural shifts like the transition to ESM. It's primarily used by tools that process natural language, such as spell-checkers or linting tools, to correctly identify and potentially exclude words that are meant as examples or explicitly quoted text rather than standard vocabulary, rather than actual words to be evaluated.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/syntax-tree/nlcst-is-literal","tags":["javascript","unist","nlcst","nlcst-util","util","utility","literal","word","typescript"],"install":[{"cmd":"npm install nlcst-is-literal","lang":"bash","label":"npm"},{"cmd":"yarn add nlcst-is-literal","lang":"bash","label":"yarn"},{"cmd":"pnpm add nlcst-is-literal","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is ESM-only since v2; CommonJS `require` is not supported.","wrong":"const { isLiteral } = require('nlcst-is-literal')","symbol":"isLiteral","correct":"import { isLiteral } from 'nlcst-is-literal'"},{"note":"For Deno or browser environments via esm.sh.","symbol":"isLiteral","correct":"import {isLiteral} from 'https://esm.sh/nlcst-is-literal@3'"},{"note":"The package ships TypeScript types; ensure your NLCST nodes conform to `nlcst`'s `Node` interface.","symbol":"isLiteral","correct":"import type { Node } from 'nlcst'; /* ... */ isLiteral(parent: Node, index: number)"}],"quickstart":{"code":"import { read } from 'to-vfile';\nimport { ParseEnglish } from 'parse-english';\nimport { visit } from 'unist-util-visit';\nimport { toString } from 'nlcst-to-string';\nimport { isLiteral } from 'nlcst-is-literal';\n\nasync function processDocument() {\n  const exampleText = `\n    The word “foo” is meant as a literal.\n    The word «bar» is meant as a literal.\n    The word (baz) is meant as a literal.\n    The word, qux, is meant as a literal.\n    The word — quux — is meant as a literal.\n    This sentence includes a regular word.\n  `;\n\n  // Create a mock vfile for the example text\n  const file = {\n    path: 'example.txt',\n    contents: exampleText,\n    toString() { return this.contents; }\n  };\n\n  const tree = new ParseEnglish().parse(String(file));\n\n  console.log('Literal words identified:');\n  visit(tree, 'WordNode', function (node, index, parent) {\n    if (isLiteral(parent, index)) {\n      console.log(`- ${toString(node)}`);\n    }\n  });\n}\n\nprocessDocument().catch(console.error);\n","lang":"javascript","description":"This quickstart demonstrates how to parse a text, visit its word nodes, and use `isLiteral` to identify and log words that are enclosed by delimiters such as quotes, parentheses, or dashes."},"warnings":[{"fix":"Upgrade your Node.js environment to version 16 or higher.","message":"Version 3.0.0 requires Node.js 16 or later. Older Node.js versions are no longer supported.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Always import modules directly from the package name, e.g., `import { isLiteral } from 'nlcst-is-literal'`.","message":"Version 3.0.0 transitioned to use the `exports` field in `package.json`. Direct imports of internal module paths (e.g., `nlcst-is-literal/index.js`) might break.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Migrate your project to use ES Modules or use an older version of the package if CommonJS is strictly required (not recommended for new projects).","message":"Version 2.0.0 made the package ESM-only. It cannot be imported using CommonJS `require()` statements.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Consult the NLCST specification and examples to understand how punctuation creates literal contexts. Inspect your NLCST tree if unexpected results occur.","message":"The `isLiteral` function determines literal status based on the presence and type of surrounding punctuation nodes in the NLCST tree. Users should be familiar with NLCST structures to correctly interpret its behavior.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change `const { isLiteral } = require('nlcst-is-literal')` to `import { isLiteral } from 'nlcst-is-literal'` and ensure your project supports ESM.","cause":"Attempting to use `require()` on `nlcst-is-literal`, which is an ES Module.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ...nlcst-is-literal/index.js from ... is not supported."},{"fix":"Ensure you are using `import { isLiteral } from 'nlcst-is-literal'` and not attempting to import it as a default export or through a path that mangles the named export.","cause":"Incorrect import syntax, typically when a bundler (like Webpack) processes an ESM module incorrectly, or when trying to access a named export as a default.","error":"TypeError: (0 , nlcst_is_literal__WEBPACK_IMPORTED_MODULE_0__.isLiteral) is not a function"},{"fix":"Verify your `import { isLiteral } from 'nlcst-is-literal'` statement is correct and at the top level of your module, and that the file is treated as an ES Module.","cause":"The `isLiteral` function was not successfully imported or is being used outside its scope.","error":"ReferenceError: isLiteral is not defined"}],"ecosystem":"npm"}