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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@johnlindquist/clipboard

v0.1.38

Published

Cross Platform Clipboard listener that detects both text and image update in clipboard

Downloads

252

Readme

General Clipboard Listener

A Cross-Platform clipboard listener that listens for both text and image (screenshots). Designed for NodeJS, not for web. Provides API to read and write text/image from/to clipboard.

Forked from: https://www.npmjs.com/package/@crosscopy/clipboard

Installation

npm i @johnlindquist/clipboard

Usage

It has a very easy to use event-based system.

See demo.ts for a demo.

Run ts-node demo.ts.

import clipboardEventListener from "./@crosscopy/clipboard";

console.log(clipboard.readTextSync());
  console.log(await clipboard.readText());
  const imgBuf = clipboard.readImageSync();
  // console.log(imgBuf.toString("base64"));
  // console.log(clipboard.readImageBase64Sync());
  // await clipboard.writeImage(base64img); // add fake image to clipboard
  clipboard.writeImageSync(base64img); // add fake image to clipboard
  console.log(""); // give some time
  console.assert(clipboard.readImageBase64Sync() === base64img);

  // * test readimage
  clipboard.writeImageSync(base64img);
  console.log();
  console.assert(
    (await clipboard.readImage()).toString("base64") === base64img
  );

  await clipboard.writeImage(base64img);
  console.log();
  console.assert((await clipboard.readImageBase64()) === base64img);
  clipboard.on("text", (text) => {
    console.log(text);
  });
  clipboard.on("image", (data) => {
    fs.writeFileSync("test.png", data);
  });
  clipboard.listen();
  setTimeout(() => {
    clipboard.close();
  }, 10000);

Explanation

It's achieved using child process + stdout.

I took a golang version of the listener from golang-design/clipboard.

When a change is detected, IMAGE_CHANGED or TEXT_CHANGED is printed to stdout.

This library runs compiled go-version clipboard listener using child process and listen to the stdout.

If it sees the keywords in child process's stdout, an event will be emitted.

Run npm run demo to see a demo for 10 sec. Once started, copy some text and screenshot and check the terminal.

Supported Platforms

Format: process.platform/process.arch

The process here is from nodejs.

Supported platforms can be found in go-clipboard/binaries.

If your nodejs gives different platform or arch, it may not work.

Release

Cross Compile doesn't work due to some CGO problem. Have to build on different platforms manually.

Within go-clipboard folder.

go build -o binaries/go-clipboard-darwin-arm64
go build -o binaries/go-clipboard-darwin-x64
go build -o binaries/go-clipboard-win32-x64.exe
go build -o binaries/go-clipboard-linux-x64
go build -o binaries/go-clipboard-linux-arm
go build -o binaries/go-clipboard-linux-arm64