Convert Figma logo to code with AI

sindresorhus logoclipboardy

Access the system clipboard (copy/paste)

1,766
81
1,766
16

Top Related Projects

12,304

Node.js Desktop Automation.

:scissors: Modern copy to clipboard. No Flash. Just 3kb gzipped :clipboard:

Quick Overview

Clipboardy is a cross-platform Node.js library for accessing the system clipboard. It provides a simple API to read from and write to the clipboard, supporting both text and images on various operating systems including Windows, macOS, and Linux.

Pros

  • Cross-platform compatibility (Windows, macOS, Linux)
  • Simple and easy-to-use API
  • Supports both text and image clipboard operations
  • Actively maintained with regular updates

Cons

  • Limited to Node.js environments
  • May require additional setup on some Linux distributions
  • Doesn't support more complex clipboard formats (e.g., RTF, HTML)
  • Potential security concerns when accessing system clipboard

Code Examples

Reading from the clipboard:

import clipboard from 'clipboardy';

const text = await clipboard.read();
console.log(text);

Writing to the clipboard:

import clipboard from 'clipboardy';

await clipboard.write('Hello, World!');
console.log('Text copied to clipboard');

Using synchronous methods:

import clipboard from 'clipboardy';

clipboard.writeSync('Synchronous write');
const text = clipboard.readSync();
console.log(text);

Getting Started

To use Clipboardy in your Node.js project, follow these steps:

  1. Install the package using npm:

    npm install clipboardy
    
  2. Import the library in your JavaScript file:

    import clipboard from 'clipboardy';
    
  3. Use the provided methods to read from or write to the clipboard:

    // Write to clipboard
    await clipboard.write('Hello, Clipboardy!');
    
    // Read from clipboard
    const clipboardContent = await clipboard.read();
    console.log(clipboardContent);
    

Remember to handle potential errors and use try-catch blocks when working with asynchronous operations.

Competitor Comparisons

12,304

Node.js Desktop Automation.

Pros of RobotJS

  • Broader functionality: RobotJS offers mouse and keyboard automation, screen capture, and color detection
  • Cross-platform support: Works on Windows, macOS, and Linux
  • More powerful for complex automation tasks

Cons of RobotJS

  • Larger package size and more dependencies
  • Steeper learning curve due to more extensive API
  • Requires compilation, which can be challenging for some users

Code Comparison

Clipboardy (copying text):

const clipboardy = require('clipboardy');
clipboardy.writeSync('Hello, World!');

RobotJS (typing text):

const robot = require('robotjs');
robot.typeString('Hello, World!');

While Clipboardy focuses solely on clipboard operations, RobotJS provides a wider range of system automation features. Clipboardy is more lightweight and easier to use for simple clipboard tasks, while RobotJS offers more powerful automation capabilities at the cost of increased complexity and setup requirements.

Clipboardy is ideal for projects that only need clipboard functionality, whereas RobotJS is better suited for complex automation scripts or applications that require system-wide interaction beyond just clipboard operations.

:scissors: Modern copy to clipboard. No Flash. Just 3kb gzipped :clipboard:

Pros of clipboard.js

  • Browser-based, making it ideal for web applications
  • Lightweight and dependency-free
  • Supports copying text from attributes and non-input elements

Cons of clipboard.js

  • Limited to browser environments
  • Requires manual DOM manipulation for some operations
  • Less comprehensive API compared to clipboardy

Code Comparison

clipboard.js:

new ClipboardJS('.btn');
document.querySelector('.btn').addEventListener('click', () => {
  console.log('Copied!');
});

clipboardy:

const clipboardy = require('clipboardy');
clipboardy.writeSync('Hello, World!');
console.log(clipboardy.readSync());

Key Differences

clipboardy is a Node.js module that provides cross-platform clipboard access, making it suitable for both server-side and desktop applications. It offers a simpler API for reading and writing to the clipboard.

clipboard.js, on the other hand, is designed specifically for browser environments. It excels at copying text from various DOM elements and attributes, making it more flexible for web-based clipboard operations.

The choice between the two depends on the specific use case. For web applications requiring client-side clipboard manipulation, clipboard.js is often the better choice. For Node.js applications or those needing cross-platform clipboard access, clipboardy is more appropriate.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

clipboardy

Access the system clipboard (copy/paste)

Cross-platform. Supports: macOS, Windows, Linux, OpenBSD, FreeBSD, Android with Termux, and modern browsers.

Install

npm install clipboardy

Usage

import clipboard from 'clipboardy';

clipboard.writeSync('🦄');

clipboard.readSync();
//=> '🦄'

API

In the browser, it requires a secure context.

clipboard

.write(text)

Write (copy) to the clipboard asynchronously.

Returns a Promise.

text

Type: string

The text to write to the clipboard.

.read()

Read (paste) from the clipboard asynchronously.

Returns a Promise.

.writeSync(text)

Write (copy) to the clipboard synchronously.

Doesn't work in browsers.

text

Type: string

The text to write to the clipboard.

.readSync()

Read (paste) from the clipboard synchronously.

Doesn't work in browsers.

FAQ

Where can I find the source of the bundled binaries?

The Linux binary is just a bundled version of xsel. The source for the Windows binary can be found here.

Related

NPM DownloadsLast 30 Days