New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

copy-paste

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

copy-paste

A command line utility that allows read/write (i.e copy/paste) access to the system clipboard.

Source
npmnpm
Version
2.1.0
Version published
Weekly downloads
169K
-24.09%
Maintainers
1
Weekly downloads
 
Created
Source

node-copy-paste

A command line utility that allows read/write (i.e copy/paste) access to the system clipboard. It does this by wrapping pbcopy/pbpaste (for OSX), xclip (for Linux, FreeBSD, and OpenBSD), and clip (for Windows). Currently works with node.js v0.8+.

The API

When require("copy-paste") is executed, an object with the following properties is returned:

  • copy(text[, callback]): asynchronously replaces the current contents of the clip board with text. Takes either a string, array, object, or readable stream. Returns the same value passed in. Optional callback will fire when the copy operation is complete.
  • copy.json(obj[, callback]): asynchronously replaces the current contents of the clip board with the JSON string of obj. Returns the same value passed in. Optional callback will fire when the copy operation is complete.
  • paste([callback]): if no callback is provided, paste synchronously returns the current contents of the system clip board. Otherwise, the contents of the system clip board are passed to the callback as the second parameter. The first one being a potential error.
  • require("copy-paste").global(): adds copy and paste to the global namespace. Returns an object with copy and paste as properties.

Promise-based API

For modern JavaScript applications, you can use the promise-based interface by requiring the promises submodule:

const clipboard = require('copy-paste/promises');

The promise-based API provides the following methods:

  • copy(text): Returns a promise that resolves with the copied text when the operation is complete
  • copy.json(obj): Returns a promise that resolves with the copied JSON string when the operation is complete
  • paste(): Returns a promise that resolves with the clipboard contents when the operation is complete

Example usage with async/await:

const clipboard = require('copy-paste/promises');

// Copy text
await clipboard.copy('Hello World');

// Copy JSON
await clipboard.copy.json({ hello: 'world' });

// Paste text
const text = await clipboard.paste();

Example

var clipboard = require("copy-paste");

clipboard.copy("some text", (err, text) => {
  // complete...
});

Getting node-copy-paste

The easiest way to get node-copy-paste is with npm:

npm install copy-paste

Alternatively you can clone this git repository:

git clone git://github.com/xavi-/node-copy-paste.git

Future plans

I'm hoping to add various fallbacks for instances when xclip or clip is not avaiable (see experimental-fallbacks branch). Also this library needs to be more thoroughly tested on windows.

Developed by

  • Xavi Ramirez

License

This project is released under The MIT License.

Keywords

copy

FAQs

Package last updated on 23 Apr 2025

Related posts