tinyclip - System Clipboard Utility

0.1.12 · active · verified Sun Apr 19

tinyclip is a concise, cross-platform utility designed to interact with the system clipboard specifically within Node.js environments. It leverages native operating system clipboard functionalities for robust performance. The package is currently at version `0.1.12` and demonstrates an active development cadence, with frequent minor updates addressing features and bug fixes. A key differentiator is its minimalistic design and its exclusive focus on Node.js; starting from version `0.1.11`, `tinyclip` explicitly removed browser support, guiding developers to utilize the native browser Clipboard API for web contexts instead. This makes it an ideal choice for server-side or desktop applications built with Node.js that require reliable clipboard operations without additional heavy dependencies.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to write a string to the system clipboard and then read its content back, within a Node.js environment.

import { readText, writeText } from 'tinyclip';

async function clipboardExample() {
  const textToCopy = 'Hello from tinyclip! This text was written to your clipboard.';
  console.log(`Attempting to write: "${textToCopy}" to clipboard.`);
  try {
    await writeText(textToCopy);
    console.log('Text successfully written to clipboard.');

    console.log('Attempting to read text from clipboard...');
    const clipboardContent = await readText();
    console.log(`Text read from clipboard: "${clipboardContent}"`);

    if (clipboardContent === textToCopy) {
      console.log('Clipboard content matches the written text.');
    } else {
      console.log('Clipboard content does not match the written text. (This might be due to other applications modifying the clipboard or environment limitations)');
    }
  } catch (error: any) {
    console.error('Failed to interact with clipboard:', error.message);
    console.error('Ensure you are running in a Node.js environment with appropriate OS access.');
  }
}

clipboardExample();

view raw JSON →