unified

Project: retextjs/retext-contractions

Package: retext-contractions@5.2.0

  1. Dependents: 0
  2. retext plugin to check apostrophes in elided contractions
  1. unified 179
  2. plugin 138
  3. retext 42
  4. retext-plugin 26
  5. apostrophe 2

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 12.20+, 14.14+, 16.0+, or 18.0+), install with npm:

npm install retext-contractions

In Deno with esm.sh:

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

In browsers with esm.sh:

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

Use

Say our document example.txt contains:

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

…and our module example.js looks as follows:

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

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

console.error(reporter(file))

…now running node example.js yields:

example.txt
  1:10-1:17  warning  Expected the apostrophe in `does’nt` to be like this: `doesn’t`  retext-contractions  retext-contractions
  1:36-1:40  warning  Expected an apostrophe in `yall`, like this: `y’all`             retext-contractions  retext-contractions
  1:45-1:49  warning  Expected an apostrophe in `isnt`, like this: `isn’t`             retext-contractions  retext-contractions
  1:59-1:63  warning  Expected the apostrophe in `80’s` to be like this: `’80s`        retext-contractions  retext-contractions

⚠ 4 warnings

API

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

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

Check apostrophes in contractions.

options

Configuration (optional).

options.straight

Suggest straight (') instead of smart () apostrophes (boolean, default: false). Use retext-quotes if you want to properly check that though.

options.allowLiterals

Include literal phrases (boolean, default: false). The default is to ignore them.

Messages

The following VFileMessages are used:

sourceruleIdExampleReason
retext-contractionsmissing-smart-apostropheYallExpected an apostrophe in Yall, like this: Y’all
retext-contractionsmissing-straight-apostropheYall, with straight: trueExpected an apostrophe in Dont, like this: Don't
retext-contractionsstraight-apostropheDon'tExpected the apostrophe in Don't to be like this: Don’t
retext-contractionssmart-apostropheDon’t, with straight: trueExpected the apostrophe in Don’t to be like this: Don't

The offending value is stored at message.actual, and the suggested values are stored at message.expected.

Types

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

Compatibility

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

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