JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 32425
  • Score
    100M100P100Q167371F
  • License MIT

Check whether an NLCST node is meant literally

Package Exports

  • nlcst-is-literal

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nlcst-is-literal) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

nlcst-is-literal Build Status Coverage Status

Check whether an NLCST node is meant literally. Useful if a tool wants to exclude these values possibly void of meaning.

As an example, a spell-checker could exclude these literal words, thus not warning about “monsieur”.

Installation

npm:

npm install nlcst-is-literal

nlcst-is-literal is also available for bower, component, and duo, and as an AMD, CommonJS, and globals module, uncompressed and compressed.

Usage

var retext = require('retext');
var visit = require('unist-util-visit');
var toString = require('nlcst-to-string');
var isLiteral = require('.');

retext().use(function () {
    return function (cst) {
        visit(cst, 'WordNode', function (node, index, parent) {
            if (isLiteral(parent, index)) {
                console.log(toString(node));
            }
        });
    }
}).process([
    '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.'
].join('\n\n'));

Yields:

foo
bar
baz
qux
quux

API

isLiteral(parent, index)

Check if the node in parent at position is enclosed by matching delimiters.

For example, in:

  • Foo - is meant as a literal.;
  • Meant as a literal is - foo.;
  • The word “foo” is meant as a literal.;

...foo is literal.

Parameters

  • node (NLCSTParentNode) — Parent to search.

  • nodes (Array.<NLCSTNode>) — Position of node to check.

Returns

boolean — Whether the node is literal.

Throws

  • Error — When no parent node is given;
  • Error — When no index is given.

License

MIT © Titus Wormer