nlcst-is-literal

2018-11-13 admin

nlcst-is-literal是什么

什么是nlcst-is-literal,Check whether an NLCST node is meant literally

nlcst-is-literal使用教程帮助文档

nlcst-is-literal Build Status Coverage Status

Check if 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

Usage

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)

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

For example, foo is literal in the following samples:

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

Contribute

See contributing.md in syntax-tree/nlcst for ways to get started.

This organisation has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.

License

MIT © Titus Wormer

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-45329.html

文章标题:nlcst-is-literal

回到顶部