@rtorcato/browser-common / clipboard
clipboard
Functions
isClipboardApiAvailable()
isClipboardApiAvailable():
boolean
Defined in: clipboard/index.ts:10
Checks if the Clipboard API is available in the browser.
Returns
boolean
True if available, false otherwise.
Example
import { isClipboardApiAvailable } from '@rtorcato/browser-common/clipboard'
if (isClipboardApiAvailable()) showCopyButton()
readFromClipboard()
readFromClipboard():
Promise<string|null>
Defined in: clipboard/index.ts:25
Reads text from the clipboard, if supported by the browser.
Returns
Promise<string | null>
The clipboard text, or null if not available.
Remarks
Requires HTTPS or a user-gesture-initiated handler in most browsers.
Example
import { readFromClipboard } from '@rtorcato/browser-common/clipboard'
const text = await readFromClipboard()
copyElementTextToClipboard()
copyElementTextToClipboard(
element):Promise<boolean>
Defined in: clipboard/index.ts:46
Copies the text content of a DOM element to the clipboard.
Parameters
element
Element
The element whose text to copy.
Returns
Promise<boolean>
True if the copy succeeded, false otherwise.
Example
import { copyElementTextToClipboard } from '@rtorcato/browser-common/clipboard'
await copyElementTextToClipboard(document.querySelector('#snippet')!)
copyToClipboard()
copyToClipboard(
text):Promise<boolean>
Defined in: clipboard/index.ts:61
Copies a string to the clipboard, if supported by the browser.
Parameters
text
string
The text to copy.
Returns
Promise<boolean>
True if the copy succeeded, false otherwise.
Remarks
Requires HTTPS or a user-gesture-initiated handler in most browsers.
Example
import { copyToClipboard } from '@rtorcato/browser-common/clipboard'
await copyToClipboard('hello')