nlcst-is-literal
nlcst utility to check whether a node is meant literally
Last updated 5 years ago by wooorm .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install nlcst-is-literal 
SYNC missed versions from official npm registry.

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

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

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:

import {readSync} from 'to-vfile'
import {unified} from 'unified'
import retextEnglish from 'retext-english'
import {visit} from 'unist-util-visit'
import {toString} from 'nlcst-to-string'
import {isLiteral} from 'nlcst-is-literal'

const file = readSync('example.txt')

const tree = unified().use(retextEnglish).parse(file)

visit(tree, 'WordNode', visitor)

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

Now, running node example yields:

foo
bar
baz
qux
quux

API

This package exports the following identifiers: isLiteral. There is no default export.

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:

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

Related

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

Current Tags

  • 2.1.0                                ...           latest (5 years ago)

9 Versions

  • 2.1.0                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.2.2                                ...           5 years ago
  • 1.2.1                                ...           6 years ago
  • 1.2.0                                ...           7 years ago
  • 1.1.2                                ...           8 years ago
  • 1.1.1                                ...           9 years ago
  • 1.1.0                                ...           9 years ago
  • 1.0.0                                ...           11 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (3)
Dev Dependencies (12)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |