clipboard-sys
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

clipboard-sys

Tested Released Supported node LTS versions

Access the system clipboard

  • copy/paste text
  • copy/paste image
  • copy/paste files

Cross-platform!

Supports:

  • Windows
  • Linux (xclip supporting systems) should be installed xclip (sudo apt-get install xclip)
  • MacOS

Install

npm install clipboard-sys

Usage

import { clipboard } from './index';
import fs from 'fs';

async function readWriteText() {
  await clipboard.writeText('some text');
  console.log('text from clipboard:', await clipboard.readText());
}
readWriteText();

async function readWriteImage() {
  await clipboard.writeImage('./source.png');
  await clipboard.readImage('./destination.png');

  await clipboard.writeImage(fs.readFileSync('./source.png')); //buffer
  return await clipboard.readImage(); //buffer
}
readWriteImage();

async function copyFiles() {
  await clipboard.writeFiles('./source1.txt', './source2.png');
  console.log(await clipboard.readFiles());
}
copyFiles();

async function pasteFiles() {
  await clipboard.pasteFiles('Copy', './destinationFolder', './source1.png', './source2.png');
  await clipboard.pasteFiles('Cut', './destinationFolder', './source1.png', './source2.png');
}
pasteFiles();

API

export interface SysClipboard {
  readText(): Promise<string>;
  writeText(text: string): Promise<void>;
  readImage(file?: string): Promise<Buffer>;
  writeImage(file: string | Buffer): Promise<void>;
  readFiles(): Promise<Array<string>>;
  pasteFiles(action: 'Copy' | 'Cut', destinationFolder: string, ...files: Array<string>): Promise<void>;
  writeFiles(...files: Array<string>): Promise<boolean>;
}

Contribution

Opened for contribution https://github.com/udarrr/clipboard-sys

Package Sidebar

Install

npm i clipboard-sys

Weekly Downloads

563

Version

1.2.1

License

MIT

Unpacked Size

53 kB

Total Files

26

Last publish

Collaborators

  • udarrr