Neurotic Programmer Masquerade

    retext-contractions
    TypeScript icon, indicating that this package has built-in type declarations

    5.2.0 • Public • Published

    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:

    source ruleId Example Reason
    retext-contractions missing-smart-apostrophe Yall Expected an apostrophe in Yall, like this: Y’all
    retext-contractions missing-straight-apostrophe Yall, with straight: true Expected an apostrophe in Dont, like this: Don't
    retext-contractions straight-apostrophe Don't Expected the apostrophe in Don't to be like this: Don’t
    retext-contractions smart-apostrophe Don’t, with straight: true Expected 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.

    Related

    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

    Install

    npm i retext-contractions

    DownloadsWeekly Downloads

    4,611

    Version

    5.2.0

    License

    MIT

    Unpacked Size

    14 kB

    Total Files

    7

    Last publish

    Collaborators

    • wooorm