clipboardy
Access the system clipboard (copy/paste)

clipboardy downloads clipboardy version clipboardy license

clipboardy類似套件:
npm下載趨勢
3 年
🌟 在 clipboardy 的 README.md 中顯示即時使用量圖表,只需複製下面的代碼。
## Usage Trend
[![Usage Trend of clipboardy](https://npm-compare.com/img/npm-trend/THREE_YEARS/clipboardy.png)](https://npm-compare.com/clipboardy#timeRange=THREE_YEARS)
Cumulative GitHub Star Trend
🌟 在 clipboardy 的 README.md 中顯示 GitHub stars 趨勢圖表,只需複製下面的代碼。
## GitHub Stars Trend
[![GitHub Stars Trend of clipboardy](https://npm-compare.com/img/github-trend/clipboardy.png)](https://npm-compare.com/clipboardy)
統計詳情
套件
下載數
Stars
大小
Issues
發布時間
許可
clipboardy5,477,6841,859920 kB161 個月前MIT
clipboardy 的 README

clipboardy

Access the system clipboard (copy/paste)

Cross-platform. Supports: macOS, Windows, Linux (including Wayland), OpenBSD, FreeBSD, Android with Termux, and modern browsers.

Install

npm install clipboardy

Usage

import clipboard from 'clipboardy';

await clipboard.write('🦄');

await clipboard.read();
//=> '🦄'

// Or use the synchronous API
clipboard.writeSync('🦄');

clipboard.readSync();
//=> '🦄'

API

Browser usage: Requires a secure context (HTTPS). Synchronous methods are not available in browsers.

clipboard

.write(text)

Write (copy) to the clipboard asynchronously.

Returns a Promise<void>.

text

Type: string

The text to write to the clipboard.

await clipboard.write('🦄');

.read()

Read (paste) from the clipboard asynchronously.

Returns a Promise<string>.

const content = await clipboard.read();
//=> '🦄'

.writeSync(text)

Write (copy) to the clipboard synchronously.

Doesn't work in browsers.

text

Type: string

The text to write to the clipboard.

clipboard.writeSync('🦄');

.readSync()

Read (paste) from the clipboard synchronously.

Returns a string.

Doesn't work in browsers.

const content = clipboard.readSync();
//=> '🦄'

FAQ

Where can I find the source of the bundled binaries?

The Linux binary is just a bundled version of xsel. The source for the Windows binary can be found here.

On Windows, clipboardy first tries the native PowerShell cmdlets (Set-Clipboard/Get-Clipboard) and falls back to the bundled binary if PowerShell is unavailable or restricted.

Does this work on Wayland?

Yes. On Linux, clipboardy automatically detects Wayland sessions and uses wl-clipboard when available. If not, it gracefully falls back to X11 tools. Also works with WSLg (Windows Subsystem for Linux GUI). Install wl-clipboard using your distribution's package manager.

Related