text-copier
Simple clipboard function, written in TypeScript.
Installation
npm install --save text-copier
Usage
import { copyText } from 'text-copier';
// When user clicks on a button,
// trigger the function
async function onClick() {
await copyText('Hello World');
alert('Copied to clipboard');
}
Error Handling
import { copyText, Clipboard } from 'text-copier';
async function onClick() {
try {
await copyText('Hello World');
alert('Copied to clipboard');
} catch(event: Clipboard.Event) {
console.error(event);
}
}