retext-contractions

retext plugin to check apostrophes in elided contractions

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
retext-contractions
806.0.08 months ago8 years agoMinified + gzip package size for retext-contractions in KB

Readme

retext-contractions
!Buildbuild-badgebuild !Coveragecoverage-badgecoverage !Downloadsdownloads-badgedownloads !Sizesize-badgesize !Sponsorssponsors-badgecollective !Backersbackers-badgecollective !Chatchat-badgechat
retext plugin to check apostrophes in contractions.

Contents

*   [`unified().use(retextContractions[, options])`](#unifieduseretextcontractions-options)
*   [`Options`](#options)

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 onlyesm. In Node.js (version 16+), install with npm:
npm install retext-contractions

In Deno with esm.shesmsh:
import retextContractions from 'https://esm.sh/retext-contractions@6'

In browsers with esm.shesmsh:
<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 retextContractionsapi-retext-contractions.

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

Check apostrophes in contractions.
Parameters
— configuration
Returns
Transform (Transformerunified-transformer).

Options

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

Messages

Each message is emitted as a VFileMessagevfile-message 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 Optionsapi-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

— check for proper use of diacritics
— check quote and apostrophe usage
— check spacing between sentences

Contribute

See contributing.mdcontributing in retextjs/.githubhealth for ways to get started. See support.mdsupport for ways to get help.
This project has a code of conductcoc. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MITlicense © Titus Wormerauthor