sentences-per-line
v0.5.6
Published
Utility functions to detect the number of sentences per line in Markdown files. ๐
Readme
Usage
Looking for the ESLint, Markdownlint, or Prettier plugins to enforce
sentences-per-line? See ../../README.md > ## Packages.
npm i sentences-per-linegetIndexBeforeSecondSentence
Retrieves the first index after the period, question mark, or exclamation mark of the line's first sentence, if a second sentence follows it.
This is the driving function behind enforcing one sentence per line in the sentences-per-line monorepo's packages.
import { getIndexBeforeSecondSentence } from "sentences-per-line";
// undefined
getIndexBeforeSecondSentence("The only sentence.");
// 15
getIndexBeforeSecondSentence("First sentence. Second sentence.");Lines that can't contain a line break, such as headings and table rows, are never reported.
// undefined
getIndexBeforeSecondSentence("| First sentence. Second sentence. | Third |");It optionally takes in an array of additional words to treat as abbreviations instead of sentence endings.
// undefined
getIndexBeforeSecondSentence("Bonjour Mme. Dupont.", ["Mme."]);It also optionally takes in a BCP 47 locale tag describing the language the Markdown is written in.
It defaults to "en-US".
// 4
getIndexBeforeSecondSentence("Foo; Bar baz", [], "el");Sentence boundaries are found with Intl.Segmenter.
isSentenceContinuedOnNextLine
Determines whether a line's last sentence is unfinished, and so continues onto the next line. Lines that start a different Markdown block, such as headings and table rows, are never considered continued.
import { isSentenceContinuedOnNextLine } from "sentences-per-line";
// false
isSentenceContinuedOnNextLine("The only sentence.", "Another sentence.");
// true
isSentenceContinuedOnNextLine("A sentence that spans", "multiple lines.");It optionally takes in an array of additional words to treat as abbreviations instead of sentence endings.
// true
isSentenceContinuedOnNextLine("Bonjour Mme.", "Dupont.", ["Mme."]);