Skip to content

Get text and context (sentence, paragraph...) from window.getSelection().

License

Notifications You must be signed in to change notification settings

crimx/get-selection-more

Repository files navigation

Get Selection More npm-version Build Status Coverage Status

Get Selection More

APIs

/**
 * Returns the selected text
 */
function getText(win?: Window): string
function getTextFromSelection(selection: Selection | null, win?: Window): string
/**
 * Returns the paragraph containing the selection text.
 */
function getParagraph(win?: Window): string
function getParagraphFromSelection(selection: Selection | null): string
/**
 * Returns the sentence containing the selection text.
 */
function getSentence(win?: Window): string
function getSentenceFromSelection(selection: Selection | null): string

Optionally pass window of other frame to get selection within that frame.

Usage

import { getText, getParagraph, getSentence } from 'get-selection-more'

document.addEventListener('selectionchange', () => {
  console.log(getText(), getParagraph(), getSentence())
})

Or load the UMD module directly which exposes getSelectionMore global.

About

Get text and context (sentence, paragraph...) from window.getSelection().

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published