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

clipboard-utils

v1.0.3

Published

A clipboard utility library

Downloads

6

Readme

Clipboard

面向现代浏览器的轻量级剪贴板工具库。此文档为中文默认版本,如需英文说明请查看 English Version

特性

  • ✅ 文本复制 / 读取,内置回退方案
  • 🖼️ 支持复制与读取图片(File / Blob / ImageData / URL)
  • 🔐 仅在安全上下文(HTTPS / localhost)中启用 Clipboard API
  • 📦 TypeScript 类型声明与 ES2015 构建产物,适合 npm 发布

安装

npm install clipboard-utils

使用示例

import { 
  copyToClipboard, 
  readFromClipboard, 
  copyImageToClipboard,
  readImageFromClipboard,
  isClipboardSupported 
} from 'clipboard-utils';

// 检查当前环境是否支持 Clipboard API
if (isClipboardSupported()) {
  // 复制文本
  await copyToClipboard('Hello, World!');
  
  // 读取文本
  const text = await readFromClipboard();
  console.log(text);
  
  // 复制图片(支持 File、Blob、ImageData 或 URL)
  const fileInput = document.querySelector('input[type="file"]') as HTMLInputElement;
  if (fileInput.files && fileInput.files[0]) {
    await copyImageToClipboard(fileInput.files[0]);
  }
  
  // 或通过 URL 复制图片
  await copyImageToClipboard('https://example.com/image.png');
  
  // 读取图片
  const imageBlob = await readImageFromClipboard();
  if (imageBlob) {
    const imageUrl = URL.createObjectURL(imageBlob);
    // 使用 imageUrl 渲染或下载图片
  }
}

API 说明

copyToClipboard(text: string, options?: ClipboardOptions): Promise<void>

复制文本到剪贴板。

  • text:要复制的文本内容
  • options.timeout:预留的超时参数(目前未使用)

readFromClipboard(): Promise<string>

从剪贴板读取文本。

copyImageToClipboard(image: File | Blob | ImageData | string): Promise<void>

复制图片到剪贴板。

  • image:待复制的图片,可以是
    • File:文件输入获取的图片
    • Blob:包含图片数据的 Blob
    • ImageData:Canvas 的像素数据
    • string:图片 URL,内部会自动下载

readImageFromClipboard(): Promise<Blob | null>

从剪贴板读取图片数据。

  • 返回值:若存在图片则为 Blob,否则为 null

isClipboardSupported(): boolean

判断当前环境是否支持 Clipboard API。

开发说明

# 安装依赖
npm install

# 构建
npm run build

# 开发模式(监听文件变更)
npm run dev

# 类型检查
npm run type-check

包体积

  • 发布包默认不包含 *.map,通过 prepublishOnly 清理 dist/**/*.map,有效降低体积
  • 构建启用 Terser 的 compress + mangle,进一步压缩并进行轻量混淆
  • 实测 npm pack(v1.0.3):package size ≈ 4.2 kBunpacked size ≈ 12.9 kB
  • 验证方式:在项目根目录运行 npm pack 查看包内文件和体积

许可证

MIT