JSPM

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

nlcst utility to check whether a node is meant literally

Package Exports

  • nlcst-is-literal
  • nlcst-is-literal/index.js

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 Coverage Downloads Size Sponsors Backers Chat

nlcst utility to check if a node is meant literally.

Contents

What is this?

This utility can check if a node is meant literally.

When should I use this?

This package is a tiny utility that helps when dealing with words. It’s 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. In Node.js (version 14.14+ and 16.0+), install with npm:

npm install nlcst-is-literal

In Deno with esm.sh:

import {isLiteral} from 'https://esm.sh/nlcst-is-literal@2'

In browsers with esm.sh:

<script type="module">
  import {isLiteral} from 'https://esm.sh/nlcst-is-literal@2?bundle'
</script>

Use

Say our document example.txt contains:

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 module example.js looks as follows:

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'

const file = await read('example.txt')
const tree = new ParseEnglish().parse(String(file))

visit(tree, 'WordNode', function (node, index, parent) {
  if (isLiteral(parent, index)) {
    console.log(toString(node))
  }
})

…now running node example.js yields:

foo
bar
baz
qux
quux

API

This package exports the identifier isLiteral. There is no default export.

isLiteral(parent, index|child)

Check if the child in parent at index 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.
Parameters
  • parent (Node) — parent node
  • index (number) — index of child in parent
  • child (Node) — child node of parent
Returns

Whether the child is a literal (boolean).

Types

This package is fully typed with TypeScript. It exports no additional types.

Compatibility

Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. Our projects sometimes work with older versions, but this is not guaranteed.

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