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 🙏

© 2026 – Pkg Stats / Ryan Hefner

easy-copy-clipboard

v1.1.0

Published

A lightweight utility to copy text to clipboard with fallback support for older browsers

Readme

easy-copy-clipboard

A feature-rich, TypeScript-first clipboard utility with modern API support, React hooks, toast notifications, and more.

Features

  • 🚀 Modern Clipboard API - Uses native navigator.clipboard with fallback support
  • 📖 Read Clipboard - Read text content from clipboard
  • 🖼️ Copy Images - Copy images from URLs or Blobs
  • ⏱️ Auto-Clear - Automatically clear clipboard after a timeout (for security)
  • ⚛️ React Hook - Ready-to-use useCopyToClipboard hook
  • 🔔 Toast Notifications - Built-in toast notifications
  • 📝 HTML to Plain Text - Strip HTML and copy as plain text
  • 🔗 Copy URL - Quick helper to copy current page URL
  • 🪶 Lightweight - Zero dependencies, minimal bundle size
  • 💪 TypeScript - Full TypeScript support with type definitions

Installation

npm install easy-copy-clipboard

Usage

Basic Copy

import { copyToClipboard } from 'easy-copy-clipboard';

// Simple copy
await copyToClipboard('Hello, World!');

// With result handling
const result = await copyToClipboard('Text to copy');
if (result.success) {
  console.log('Copied!');
}

With Toast Notifications

await copyToClipboard('Hello!', { 
  showToast: true,
  successMessage: '✓ Copied!',
  errorMessage: '✗ Failed to copy'
});

Auto-Clear (Security Feature)

// Clipboard will be cleared after 30 seconds
await copyToClipboard('secret-api-key', { 
  autoClearMs: 30000 
});

Read from Clipboard

import { readFromClipboard } from 'easy-copy-clipboard';

const result = await readFromClipboard();
if (result.success) {
  console.log('Clipboard content:', result.data);
}

Copy Images

import { copyImage } from 'easy-copy-clipboard';

// From URL
await copyImage('https://example.com/image.png');

// From Blob
await copyImage(imageBlob, { showToast: true });

Copy HTML as Plain Text

import { copyHtmlAsPlainText } from 'easy-copy-clipboard';

await copyHtmlAsPlainText('<b>Hello</b> <i>World</i>');
// Copies: "Hello World"

Copy Current URL

import { copyCurrentUrl } from 'easy-copy-clipboard';

await copyCurrentUrl({ showToast: true });

Copy Rich Content (HTML)

import { copyRichContent } from 'easy-copy-clipboard';

await copyRichContent('<b>Bold text</b>', 'text/html');

React Hook

import { useCopyToClipboard } from 'easy-copy-clipboard';

function CopyButton() {
  const { copy, copied, error } = useCopyToClipboard();

  return (
    <button onClick={() => copy('Hello!')}>
      {copied ? '✓ Copied!' : 'Copy'}
    </button>
  );
}

Show Custom Toast

import { showToast } from 'easy-copy-clipboard';

showToast({ 
  message: 'Custom notification!', 
  type: 'success', // 'success' | 'error' | 'info'
  duration: 3000 
});

Check Browser Support

import { isClipboardSupported } from 'easy-copy-clipboard';

const support = isClipboardSupported();
console.log(support);
// {
//   modern: true,
//   legacy: true,
//   writeText: true,
//   write: true,
//   read: true,
//   readText: true
// }

API Reference

copyToClipboard(text, options?)

| Parameter | Type | Description | |-----------|------|-------------| | text | string | The text to copy | | options.onSuccess | () => void | Success callback | | options.onError | (error: Error) => void | Error callback | | options.autoClearMs | number | Auto-clear after ms | | options.showToast | boolean | Show toast notification | | options.successMessage | string | Custom success message | | options.errorMessage | string | Custom error message |

readFromClipboard()

Returns Promise<ClipboardResult<string>> with clipboard text.

copyImage(source, options?)

Copy image from URL or Blob to clipboard.

copyHtmlAsPlainText(html, options?)

Strip HTML tags and copy as plain text.

copyCurrentUrl(options?)

Copy the current page URL.

copyRichContent(content, mimeType?, options?)

Copy rich content like HTML to clipboard.

useCopyToClipboard(timeout?)

React hook for clipboard operations. Returns { copy, read, copied, error, value, reset }.

showToast(options)

Display a toast notification.

isClipboardSupported()

Check browser clipboard API support.

Browser Support

| Browser | Clipboard API | Fallback | |---------|--------------|----------| | Chrome 66+ | ✅ | ✅ | | Firefox 63+ | ✅ | ✅ | | Safari 13.1+ | ✅ | ✅ | | Edge 79+ | ✅ | ✅ | | IE 11 | ❌ | ✅ |

License

MIT