(CI tests on Linux, Mac, Windows)
import { clipboard } from 'https://deno.land/x/clipboard/mod.ts';
await clipboard.writeText('some text');
const text = await clipboard.readText();
console.log(text === 'some text'); // true
- use Web Clipboard API
- use readText and writeText (no read and write, see the spec)
- work on Linux, macOS, Windows
- don't bundle any binaries
It will spawn external processes so unfortunately
it will require the all-powerful --allow-run
flag.
If Deno exposes a Clipboard API
(with new permissions like --allow-copy
and --allow-paste
)
then hopefully this will be obsolete. See the relevant issue:
On Linux it requires xsel
to be installed (probably installed by default).
The clipboard on Windows always adds a trailing newline if there was none which makes single line strings end with a newline and this module removes the trailing newline on Windows, but it means that if it was there originally then it will still be removed - to preserve single-line strings being single-line, but maybe this is not the right way to do it. The other option would be to preserve the trailing newline but also to get one if it wasn't there. Currently I chose to remove it because newlines in the clipboard sometimes are problematic (like automatically starting commands when pasted into the terminal). TODO: think about it.
For any bug reports or feature requests please post an issue on GitHub.
MIT License (Expat). See LICENSE.md for details.