1.3.3 • Published 3 months ago
@clairelizbet/copy-to-clipboard v1.3.3
Copy to Clipboard
Small (~600 bytes minified+gzipped) script for copying text to the clipboard.
It uses the modern Clipboard API and falls back to the deprecated execCommand method as needed.
Installation
npm install @clairelizbet/copy-to-clipboard
You can also find the latest compiled and minified version on the current release page.
Usage
The script is written as a module, with named exports.
copyToClipboard(text: string)
- Copies using the best available method (Clipboard or Selection API)copyToClipboardViaSelection(text: string)
- Copies using the legacy Selection API
import { copyToClipboard } from "@clairelizbet/copy-to-clipboard"
import { copyToClipboardViaSelection } from "@clairelizbet/copy-to-clipboard"
These methods are asynchronous and may throw an Error if the copy command is rejected so it's a good idea to have error handling.