npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

node-clip-it

v1.0.4

Published

A Node.js library for clipboard operations with support for text and buffers.

Readme

Clip It

Clip It is a Node.js library for clipboard operations with support for text and buffers. It provides both synchronous and asynchronous methods for reading from and writing to the clipboard. The library works on Windows, Linux, and macOS.

Features

  • Cross-platform: Works on Windows, Linux, and macOS.
  • Text and Buffer Support: Copy and paste text or binary data (buffers).
  • Synchronous and Asynchronous Methods: Choose between writeSync/readSync and writeAsync/readAsync.
  • Easy to Use: Simple API for clipboard operations.

Supported File Types

Clip It supports copying and pasting all file types as buffers, including:

  • Text files (.txt, .json, etc.)
  • PDFs (.pdf)
  • Images (.png, .jpg, etc.)
  • Videos (.mp4, .mov, etc.)
  • Audio files (.mp3, .wav, etc.)
  • Binary files (.bin, .exe, etc.)

Example: Copying and Pasting a PDF

import ClipIt from 'clip-it';
import fs from 'fs';

const clip = new ClipIt();

// Read a PDF file as a buffer
const pdfBuffer = fs.readFileSync('example.pdf');

// Write the PDF buffer to the clipboard
clip.writeSync(pdfBuffer);

// Read the PDF buffer from the clipboard
const clipboardContent = clip.readSync();
fs.writeFileSync('output.pdf', clipboardContent); // Save the buffer to a file

---

## Requirements
- **Node.js**: Version 12 or higher.
- **Platform-Specific Tools**:
  - **Windows**: `clip` and `powershell` (pre-installed).
  - **Linux**: `xclip` (install with `sudo apt-get install xclip`).
  - **macOS**: `pbcopy` and `pbpaste` (pre-installed).

---

## Installation

1. Clone the repository:
   ```bash
   git clone https://github.com/Ferencz/clip-it.git
   cd clip-it
   
Install the package using npm:

```bash
npm install clip-it

Usage

Import the Library

// Using ES Modules
import ClipIt from 'clip-it';

// Using CommonJS
const ClipIt = require('clip-it');

Create an Instance

const clip = new ClipIt();

Methods

1. Synchronous Methods

  • writeSync(content: string | Buffer): Writes text or buffer content to the clipboard synchronously.
  • readSync(): string | Buffer: Reads text or buffer content from the clipboard synchronously.

Example: Synchronous Usage

// Write text to the clipboard
clip.writeSync('Hello, Clip It!');

// Read text from the clipboard
const textContent = clip.readSync();
console.log(textContent); // Output: Hello, Clip It!

// Write buffer to the clipboard
const buffer = Buffer.from('Hello, Buffer!');
clip.writeSync(buffer);

// Read buffer from the clipboard
const bufferContent = clip.readSync();
console.log(bufferContent.toString()); // Output: Hello, Buffer!

2. Asynchronous Methods

  • writeAsync(content: string | Buffer): Promise<void>: Writes text or buffer content to the clipboard asynchronously.
  • readAsync(): Promise<string | Buffer>: Reads text or buffer content from the clipboard asynchronously.

Example: Asynchronous Usage

// Write text to the clipboard
await clip.writeAsync('Hello, Clip It Async!');

// Read text from the clipboard
const textContent = await clip.readAsync();
console.log(textContent); // Output: Hello, Clip It Async!

// Write buffer to the clipboard
const buffer = Buffer.from('Hello, Buffer Async!');
await clip.writeAsync(buffer);

// Read buffer from the clipboard
const bufferContent = await clip.readAsync();
console.log(bufferContent.toString()); // Output: Hello, Buffer Async!

3. File Handling

You can also copy and paste file contents as buffers.

Example: File Handling

import fs from 'fs';

// Read a file as a buffer
const fileBuffer = fs.readFileSync('example.txt');

// Write the file buffer to the clipboard
clip.writeSync(fileBuffer);

// Read the file buffer from the clipboard
const clipboardContent = clip.readSync();
fs.writeFileSync('output.txt', clipboardContent); // Save the buffer to a file

Preload Clipboard Content

You can check if the clipboard already contains content before performing operations.

Example: Preload Clipboard Content

// Read preloaded content from the clipboard
const preloadedContent = clip.readSync();
if (preloadedContent) {
    console.log('Preloaded clipboard content:', preloadedContent);
} else {
    console.log('Clipboard is empty.');
}

// Overwrite preloaded content
clip.writeSync('New clipboard content');
const updatedContent = clip.readSync();
console.log('Updated clipboard content:', updatedContent);

API Reference

ClipIt Class

Methods

| Method | Description | |----------------------|--------------------------------------------------| | writeSync(content) | Writes text or buffer content to the clipboard. | | readSync() | Reads text or buffer content from the clipboard. | | writeAsync(content)| Writes text or buffer content to the clipboard. | | readAsync() | Reads text or buffer content from the clipboard. |


Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.


Support

If you encounter any issues or have questions, please open an issue.

Enjoy using Clip It! 🎉