retext plugin to check apostrophes in contractions.
- What is this?
- When should I use this?
- Install
- Use
- API
- Messages
- Types
- Compatibility
- Related
- Contribute
- License
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).
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.
This package is ESM only. In Node.js (version 16+), install with npm:
npm install retext-contractionsIn 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>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 warningsThis package exports no identifiers.
The default export is retextContractions.
Check apostrophes in contractions.
options(Options, optional) — configuration
Transform (Transformer).
Configuration (TypeScript type).
allowLiterals(boolean, default:false) — include literal phrases; normally they are ignoredstraight(boolean, default:false) — suggest straight (') instead of smart (’) apostrophes; seeretext-quotesif you want to properly check that though
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.
This package is fully typed with TypeScript.
It exports the additional type Options.
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.
retext-diacritics— check for proper use of diacriticsretext-quotes— check quote and apostrophe usageretext-sentence-spacing— check spacing between sentences
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.