A command line utility that allows read/write (i.e copy/paste) access to the system clipboard. It wraps:
- pbcopy/pbpaste for OSX
- xclip for Linux, FreeBSD, and OpenBSD
- clip for Windows
Currently works with node.js v8+ with text only.
The text is put in your system's clipboard, if any character in it are not supported by your system's default character set, the result won't be pretty. The character sets are:
- UTF16_LE: for Windows
- UTF8: for all other systems
It was copied from node-copy-paste because this security-related PR was never merged.
I was first willing to only make a simple fix and eventually remove this repository when my PR was merged but after a bit of fiddling I found myself re-writing most of the code.
The differences with node-copy-paste
- upgrade the code to newer JS syntax => now runs on NodeJS 8+
- remove deprecated methods (silent, noConflict)
- switch from callbacks to async/await
- upgrade all dependencies to their latest versions
- fix xclip API misuse that lead to node never exiting properly
- change the API significantly to have better control over encoding matters
- remove the method
global
as globals are evil - the Windows code has not changed a bit (Windows ain't my cup of tee) and all credits for Windows-related code should go to @xavi-
When require("copy-paste-2")
is executed, an object with the following properties is returned:
-
encodings
: A map of all the encodings that are supported. -
copy({ input: stream|buffer|string|array|object, inputEncoding: string })
: Asynchronously replaces the current content of the clipboard with the input.-
input
: In case the input is an array or object, the node methodrequire('util').inspect(object, { depth: null })
is used to serialize it. If it is a stream, it should be a raw stream and the encoding should be specified ininputEncoding
. -
inputEncoding
: The encoding of the input. The default is UTF-8, use the values inencoding
(and benefit from syntactic completion), example:copy({ input: 'toto', inputEncoding: encodings.UTF16_LE })
.
-
-
paste()
: Asynchronously returns the current contents of the system clip board.
const ncp = require("copy-paste");
// With async/await
const myBusinessMethod = async (someText) => {
const copied = await ncp.copy({ input: someText });
// Go on with your business logic
}
// With promises
ncp.copy({ input: 'some text' })
.then((copiedText) => {
// Your business logic here
});
npm install copy-paste-2
- [x] Install code quality/security tools
- [x] Add post-install script to check that dependencies are installed
- [x] Test more thoroughly, currently only text copies are tested. Not objects, arrays, streams...
- [ ] Properly test on all platforms (currently only tested on linux mint)
- [ ] Publish to NPM