Socket
Socket
Sign inDemoInstall

img-clipboard

Package Overview
Dependencies
7
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    img-clipboard

A cross platform utility to copy images to clipboard


Version published
Weekly downloads
951
decreased by-5.18%
Maintainers
1
Install size
177 kB
Created
Weekly downloads
 

Readme

Source

img-clipboard

A cross platform Node.js utility to copy images to clipboard.

Installation

npm install --save img-clipboard

Usage

You can use the copyImg function to copy either an image Buffer, or a file path String.

const { copyImg } = require('img-clipboard');

copyImg(Buffer.from(imageData, 'base64'));

copyImg returns a Promise of [err, stdout, stderr].

Linux use

In order for this utility to work on Linux, some external dependencies are required. xclip is required for X11 systems and wl-clipboard is required for Wayland systems.

They can generally be installed with your distro's package manager.

# Ubuntu / Debian
sudo apt install xclip
sudo apt install wl-clipboard

# Arch / Manjaro
pacman -S xclip
pacman -S wl-clipboard

Package missing logging

There are a couple of extra exports to help you log errors when the required packages are missing on Linux. Here's an example of how to use them:

const { copyImg, ErrorCodes, isWayland } = require('img-clipboard');

const copyToClipboard = async (imageData) => {
  const [err, stdout, stderr] = await copyImg(Buffer.from(imageData, 'base64'));
  if (err) {
    if (err.code === ErrorCodes.COMMAND_NOT_FOUND && process.platform === 'linux')
      console.err(isWayland() ? 'wl-clipboard' : 'xclip' + ' is not installed');
    else console.err(stdout + stderr);
  }
};

Keywords

FAQs

Last updated on 15 Apr 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc