unified

Project: retextjs/retext-contractions

Package: retext-contractions@4.0.0

  1. Dependencies: 3·Dependents: 8
  2. retext plugin to check apostrophes in elided contractions
  1. unified 167
  2. plugin 130
  3. retext 33
  4. retext-plugin 21
  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

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:

var vfile = require('to-vfile')
var report = require('vfile-reporter')
var unified = require('unified')
var english = require('retext-english')
var stringify = require('retext-stringify')
var contractions = require('retext-contractions')

unified()
  .use(english)
  .use(contractions)
  .use(stringify)
  .process(vfile.readSync('example.txt'), function(err, file) {
    console.error(report(err || 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

retext().use(contractions[, 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