GitXplorerGitXplorer
q

node-copy-paste-2

public
1 stars
0 forks
1 issues

Commits

List of commits on branch master.
Verified
5970832f6c7a995d110fe48fdf08842ed3c4c9bd

:memo: Update minimal Node JS version

qquilicicf committed 7 years ago
Unverified
f8f56937b152a5a5f9cba63c63a97d7fa5924d01

:shower: Move lodash to dev dependencies

committed 7 years ago
Unverified
553b86fcb21a9d5a1992dad096f121bd4741989d

:up: Improve encoding handling

committed 7 years ago
Unverified
3184ffd266b559c2ee7e7e875908d8e05883476e

:green_heart: Fix build

committed 7 years ago
Unverified
e1b75df8e84882c22ad3a15d1fc988b00e451035

:bug: Bump minimal node version to 8 (to use spread operator)

committed 7 years ago
Unverified
87f635532779af33204874c756c8e892adbd2f6b

:white_check_mark: Automatize testing

committed 7 years ago

README

The README file for this repository.

node-copy-paste-2

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

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

History

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-

Info

License: MIT

Status

Dependency Status Known Vulnerabilities Build status

Static analysis

Maintainability Codacy Badge

The API

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 method require('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 in inputEncoding.
    • inputEncoding: The encoding of the input. The default is UTF-8, use the values in encoding (and benefit from syntactic completion), example: copy({ input: 'toto', inputEncoding: encodings.UTF16_LE }).
  • paste(): Asynchronously returns the current contents of the system clip board.

Example

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
  });

Install

npm install copy-paste-2

TODO list

  • [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