Registry / testing / nlcst-is-literal

nlcst-is-literal

JSON →
library3.0.0jsnpmunverified

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.

npm install nlcst-is-literal
INSTALL
IMPORT
SIG · NLCST-IS-LITERAL
N
nlcst-is-literal
testingjavascriptv3.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

isLiteral
import { isLiteral } from 'nlcst-is-literal'
const { isLiteral } = require('nlcst-is-literal')
Package is ESM-only since v2; CommonJS `require` is not supported.
isLiteral
import {isLiteral} from 'https://esm.sh/nlcst-is-literal@3'
For Deno or browser environments via esm.sh.
isLiteral
import type { Node } from 'nlcst'; /* ... */ isLiteral(parent: Node, index: number)
The package ships TypeScript types; ensure your NLCST nodes conform to `nlcst`'s `Node` interface.

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.

import { read } from 'to-vfile'; import { ParseEnglish } from 'parse-english'; import { visit } from 'unist-util-visit'; import { toString } from 'nlcst-to-string'; import { isLiteral } from 'nlcst-is-literal'; async function processDocument() { const exampleText = ` The word “foo” is meant as a literal. The word «bar» is meant as a literal. The word (baz) is meant as a literal. The word, qux, is meant as a literal. The word — quux — is meant as a literal. This sentence includes a regular word. `; // Create a mock vfile for the example text const file = { path: 'example.txt', contents: exampleText, toString() { return this.contents; } }; const tree = new ParseEnglish().parse(String(file)); console.log('Literal words identified:'); visit(tree, 'WordNode', function (node, index, parent) { if (isLiteral(parent, index)) { console.log(`- ${toString(node)}`); } }); } processDocument().catch(console.error);
Debug
Known issues
breakingVersion 3.0.0 requires Node.js 16 or later. Older Node.js versions are no longer supported.
fix
Upgrade your Node.js environment to version 16 or higher.
affects: >=3.0.0
breakingVersion 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.
fix
Always import modules directly from the package name, e.g., `import { isLiteral } from 'nlcst-is-literal'`.
affects: >=3.0.0
breakingVersion 2.0.0 made the package ESM-only. It cannot be imported using CommonJS `require()` statements.
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).
affects: >=2.0.0
gotchaThe `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.
fix
Consult the NLCST specification and examples to understand how punctuation creates literal contexts. Inspect your NLCST tree if unexpected results occur.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module ...nlcst-is-literal/index.js from ... is not supported.
Attempting to use `require()` on `nlcst-is-literal`, which is an ES Module.
fix
Change `const { isLiteral } = require('nlcst-is-literal')` to `import { isLiteral } from 'nlcst-is-literal'` and ensure your project supports ESM.
TypeError: (0 , nlcst_is_literal__WEBPACK_IMPORTED_MODULE_0__.isLiteral) is not a function
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.
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.
ReferenceError: isLiteral is not defined
The `isLiteral` function was not successfully imported or is being used outside its scope.
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.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
nlcst-is-literal — npm install nlcst-is-literal · libregistry