unified

Project: retextjs/retext-contractions

Package: retext-contractions@5.1.0

  1. Dependents: 8
  2. retext plugin to check apostrophes in elided contractions
  1. unified 174
  2. plugin 137
  3. retext 37
  4. retext-plugin 24
  5. apostrophe 2

retext-contractions

Build Coverage Downloads Size Sponsors Backers Chat

retext plugin to check apostrophes in elided contractions: if they exist (isnt > isn’t) and if they are placed properly (is’nt > isn’t).

Install

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

npm:

npm install retext-contractions

Use

Say we have the following file, example.txt:

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

…and our script, example.js, looks like this:

import {readSync} 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 = readSync('example.txt')

unified()
  .use(retextEnglish)
  .use(retextContractions)
  .use(retextStringify)
  .process(file, (file) => {
    console.error(reporter(file))
  })

Now, running node example 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.

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

Emit warnings when a) elided contractions don’t have their required apostrophe, and b) when that apostrophe isn’t placed correctly.

options
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.

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