unified

Project: syntax-tree/nlcst-is-literal

Package: nlcst-is-literal@1.2.2

  1. Dependencies: 1·Dependents: 4
  2. nlcst utility to check whether a node is meant literally
  1. util 119
  2. utility 115
  3. unist 111
  4. nlcst 14
  5. nlcst-util 8
  6. literal 4

nlcst-is-literal

Build Coverage Downloads Size Sponsors Backers Chat

nlcst utility to check if a node is meant literally.

Useful if a tool wants to exclude values that are possibly void of meaning. For example, a spell-checker could exclude these literal words, thus not warning about “monsieur”.

Install

npm:

npm install nlcst-is-literal

Use

Say we have the following file, example.txt:

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.

And our script, example.js, looks as follows:

var vfile = require('to-vfile')
var unified = require('unified')
var english = require('retext-english')
var visit = require('unist-util-visit')
var toString = require('nlcst-to-string')
var literal = require('nlcst-is-literal')

var file = vfile.readSync('example.txt')

var tree = unified()
  .use(english)
  .parse(file)

visit(tree, 'WordNode', visitor)

function visitor(node, index, parent) {
  if (literal(parent, index)) {
    console.log(toString(node))
  }
}

Now, running node example yields:

foo
bar
baz
qux
quux

API

isLiteral(parent, index|child)

Check if the child in parent is enclosed by matching delimiters. If index is given, the child of parent at that index is checked.

For example, foo is literal in the following samples:

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