lite-clipboard
v0.3.0
Published
Zero-dependency clipboard in 166 bytes. React hook included. Framework-agnostic core.
Maintainers
Readme
lite-clipboard
~400 bytes. No dependencies. Works.
npm install lite-clipboardUsage
import { useClipboard } from 'lite-clipboard';
function CopyButton({ text }) {
const { copied, copy } = useClipboard();
return <button onClick={() => copy(text)}>{copied ? 'Copied!' : 'Copy'}</button>;
}Vanilla JS
import { copy } from 'lite-clipboard';
// String, Blob, ClipboardItem — all work
await copy('Hello!');
await copy(imageBlob);
await copy(new ClipboardItem({ 'text/html': htmlBlob }));
// Convenience helpers
await copyHtml('<b>Bold</b>');
await copyJson({ name: 'Alice' });API
// React hook
const { copied, copy, error, supported } = useClipboard({ timeout: 2000 });
await copy('text');
// Core
copy(text: string | Blob | ClipboardItem): Promise<CopyResult>
copyText(text: string): Promise<CopyResult>
copyHtml(html: string, plainText?: string): Promise<CopyResult>
copyJson(data: unknown): Promise<CopyResult>
isSupported(): booleanCopyResult
{ success: true } | { success: false, error: string }Size
| Module | Gzipped | |--------|---------| | Core | 327B | | React hook | 518B |
Browser Support
Requires navigator.clipboard. All modern browsers.
