retext-contractions
TypeScript icon, indicating that this package has built-in type declarations

6.0.0 • Public • Published

retext-contractions

Build Coverage Downloads Size Sponsors Backers Chat

retext plugin to check apostrophes in contractions.

Contents

What is this?

This package is a unified (retext) plugin to check apostrophes in elided contractions. It checks whether they exist (isnt > isn’t) and if they are placed correctly (is’nt > isn’t).

When should I use this?

You can opt-into this plugin when you’re dealing with content that might contain grammar mistakes, and have authors that can fix that content.

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install retext-contractions

In Deno with esm.sh:

import retextContractions from 'https://esm.sh/retext-contractions@6'

In browsers with esm.sh:

<script type="module">
  import retextContractions from 'https://esm.sh/retext-contractions@6?bundle'
</script>

Use

Say our document example.txt contains:

Well, it does’nt have to be so bad yall, it isnt like the 80s.

…and our module example.js contains:

import retextContractions from 'retext-contractions'
import retextEnglish from 'retext-english'
import retextStringify from 'retext-stringify'
import {read} from 'to-vfile'
import {unified} from 'unified'
import {reporter} from 'vfile-reporter'

const file = await unified()
  .use(retextEnglish)
  .use(retextContractions)
  .use(retextStringify)
  .process(await read('example.txt'))

console.error(reporter(file))

…then running node example.js yields:

example.txt
1:10-1:17 warning Unexpected straight apostrophe in `does’nt`, expected `doesn’t` missing-smart-apostrophe retext-contractions
1:36-1:40 warning Unexpected missing apostrophe in `yall`, expected `y’all`       missing-smart-apostrophe retext-contractions
1:45-1:49 warning Unexpected missing apostrophe in `isnt`, expected `isn’t`       missing-smart-apostrophe retext-contractions

⚠ 3 warnings

API

This package exports no identifiers. The default export is retextContractions.

unified().use(retextContractions[, options])

Check apostrophes in contractions.

Parameters
  • options (Options, optional) — configuration
Returns

Transform (Transformer).

Options

Configuration (TypeScript type).

Fields
  • allowLiterals (boolean, default: false) — include literal phrases; normally they are ignored
  • straight (boolean, default: false) — suggest straight (') instead of smart () apostrophes; see retext-quotes if you want to properly check that though

Messages

Each message is emitted as a VFileMessage on file, with source set to 'retext-contractions', ruleId to 'missing-smart-apostrophe' or 'missing-straight-apostrophe', actual to the unexpected value, and expected to the expected value.

Types

This package is fully typed with TypeScript. It exports the additional type Options.

Compatibility

Projects maintained by the unified collective are compatible with maintained versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, retext-contractions@^6, compatible with Node.js 16.

Related

Contribute

See contributing.md in retextjs/.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

Dependencies (5)

Dev Dependencies (10)

Package Sidebar

Install

npm i retext-contractions

Weekly Downloads

2,429

Version

6.0.0

License

MIT

Unpacked Size

15.9 kB

Total Files

9

Last publish

Collaborators

  • wooorm