npm.io
1.0.2 • Published 5 years ago

@loopmode/set-clipboard-data

Licence
MIT
Version
1.0.2
Deps
0
Size
5 kB
Vulns
0
Weekly
0

set-clipboard-data

Sets data to the clipboard via document.execComand("copy") and returns a promise.

The promise is resolved when the data has been set to the clipboard. This is detected via document.addEventListener("copy"). It is rejected if the clipboard does not contain the specified value after the copy event, or if the event is not fired after a specific time (rejectTimeout option)

Usage

import setClipboardData from '@loopmode/set-clipboard-data';

async function handleCopyClick() {
    const clipboardValue = await setClipboardData(this.state.currentValue);
    console.log('done!', clipboardValue);
}

Options

Signature:

setClipboardData(data = '', { mime = 'text/plain', timeout = 60000 } = {})