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

clipify

v1.1.0

Published

A JavaScript library for managing multiple clipboard slots with enhanced functionality.

Downloads

130

Readme

Clipify: A Clipboard Management Utility

Clipify is a lightweight JavaScript/TypeScript library designed for enhanced clipboard management. It provides extended functionality for handling clipboard data, including text and files, maintaining a clipboard history, managing item expiry, and supporting event-driven clipboard updates.


Features

  • Copy Text: Copy text to the system clipboard and store it in a managed history.
  • Copy Files: Add files (e.g., images, documents) to the clipboard history for reference.
  • Retrieve History: Access clipboard history or specific items using keys.
  • Expiry Management: Automatically remove clipboard items after a specified expiry time.
  • Event Handling: Listen for clipboard events like copy or expire.
  • Clear History: Easily clear all stored clipboard history.
  • Browser Compatibility Check: Detect clipboard API support in the browser.

Installation

Using NPM

npm install clipify

Using Yarn

yarn add clipify

Alternatively, you can use it directly in your browser via a CDN:

<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>

Usage

Importing Clipify

import Clipify from 'clipify';

Initialization

const clipboard = new Clipify();

API Reference

Copy Text

Copies text to the clipboard and stores it in the history.

clipboard.copy({
  text: 'Hello, world!',
  expiryTime: 5000,  // Expires after 5000ms
  key: 'greeting'
});

Copy Files

Stores files in the clipboard history.

const fileBlob = new Blob(["File content"], { type: "text/plain" });
clipboard.copyFile(fileBlob, "fileKey", 10000); // Expires after 10000ms

Paste Text

Retrieves the most recent clipboard content.

const text = await clipboard.paste();
console.log(text);

Retrieve Clipboard History

Access all stored clipboard items or specific ones by their key.

// Get all history
const history = clipboard.getHistory();
console.log(history);

// Get specific item
const item = clipboard.getHistory("greeting");
console.log(item);

Clear Clipboard History

Removes all clipboard history items.

clipboard.clearHistory();

Add Event Listeners

Listen to clipboard events (copy, expire).

clipboard.on("copy", (data) => {
  console.log("Copied:", data);
});

clipboard.on("expire", (data) => {
  console.log("Expired:", data);
});

Check Clipboard Support

Verify if the browser supports clipboard APIs.

if (Clipify.isClipboardSupported()) {
  console.log("Clipboard API is supported!");
} else {
  console.log("Clipboard API is not supported.");
}

Example Use Case

import Clipify from 'clipify';

const clipboard = new Clipify();

// Copy text
clipboard.copy({
  text: "Important Note",
  expiryTime: 6000,  // Expires after 6000ms
  key: "note"
});

// Listen for copy events
clipboard.on("copy", (data) => {
  console.log(`Copied to clipboard: ${data}`);
});

// Get specific clipboard history item
const note = clipboard.getHistory("note");
console.log("Retrieved clipboard item:", note);

// Clear all clipboard history
clipboard.clearHistory();

Here’s an example demonstrating how to use Clipify in a browser-based project:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>clipify Example</title>
</head>
<body>
  <button id="store-btn">Store Clipboard</button>
  <button id="retrieve-btn">Retrieve Clipboard</button>
  
  <script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
  <script>
    const clipify = new Clipify();

    document.getElementById('copy-btn').addEventListener('click', () => {
      const textToStore = 'Clipboard Text Example';
      clipboard.copy({
        text: textToStore
      });
      clipify.copy(textToCopy);
      alert('Clipboard item stored!');
    });

    document.getElementById('history-btn').addEventListener('click', () => {
      const history = clipboard.getHistory();
      console.log(history);
    });
  </script>
</body>
</html>

Browser Support

Clipify uses the Clipboard API to manage clipboard actions. Ensure the browser supports navigator.clipboard for full functionality.


Contributions

Contributions, issues, and feature requests are welcome! Please submit them via GitHub Issues.


License

Clipify is licensed under the MIT License. See the LICENSE file for details.


Feel free to enhance this README further based on your project specifics or hosting platform. Let me know if you need help refining any section!