clipboard-windows
v0.1.0
Published
A Node.js native addon for accessing Windows clipboard, supporting text and image operations
Maintainers
Readme
clipboard-windows
clipboard-windows: Windows Clipboard Access for Node.js
A Node.js native addon written in Rust for accessing Windows clipboard, supporting text and image operations.
This project was bootstrapped by create-neon.
Features
- Read and write text to/from clipboard
- Read and write images to/from clipboard (supports PNG, JPEG, GIF, BMP formats)
- Read HTML content from clipboard
- TypeScript support with type definitions
Installation
npm install clipboard-windowsUsage
import {
readClipboard,
writeClipboard,
readClipboardText,
writeClipboardText,
readClipboardImage,
readClipboardHtml
} from 'clipboard-windows';
// Write text to clipboard
writeClipboardText('Hello, World!');
// Read text from clipboard
const text = readClipboardText();
console.log(text);
// Write image to clipboard (supports PNG, JPEG, GIF, BMP)
import { readFileSync } from 'fs';
const imageBuffer = readFileSync('image.png');
writeClipboard('image', imageBuffer);
// Read clipboard contents with type detection
const clipboardData = readClipboard();
console.log(clipboardData.type); // 'text', 'richtext', or 'image'
console.log(clipboardData.data); // actual data
// Read image from clipboard (returns PNG buffer)
const image = readClipboardImage();Building clipboard-windows
Building clipboard-windows requires a supported version of Node and Rust.
To run the build, run:
$ npm run buildThis command uses the @neon-rs/cli utility to assemble the binary Node addon from the output of cargo.
Exploring clipboard-windows
After building clipboard-windows, you can explore its exports at the Node console:
$ npm i
$ npm run build
$ node
> require('.').hello('node')
'hello node'Available Scripts
In the project directory, you can run:
npm install
Installs the project, including running npm run build.
npm run build
Builds the Node addon (index.node) from source, generating a release build with cargo --release.
Additional cargo build arguments may be passed to npm run build and similar commands. For example, to enable a cargo feature:
npm run build -- --feature=beetlenpm run debug
Similar to npm run build but generates a debug build with cargo.
npm run cross
Similar to npm run build but uses cross-rs to cross-compile for another platform. Use the CARGO_BUILD_TARGET environment variable to select the build target.
npm test
Runs the unit tests by calling cargo test and Node.js tests. You can learn more about adding tests to your Rust code from the Rust book.
npm run clean
Clean the build artifacts.
Project Layout
The directory structure of this project is:
clipboard-windows/
├── Cargo.toml
├── README.md
├── src/
| └── lib.rs
├── index.node
├── package.json
└── target/| Entry | Purpose |
|----------------|------------------------------------------------------------------------------------------------------------------------------------------|
| Cargo.toml | The Cargo manifest file, which informs the cargo command. |
| README.md | This file. |
| src/ | The directory tree containing the Rust source code for the project. |
| lib.rs | Entry point for the Rust source code. |
| index.node | The main module, a Node addon generated by the build and pointed to by "main" in package.json. |
| package.json | The npm manifest file, which informs the npm command. |
| target/ | Binary artifacts generated by the Rust build. |
Learn More
Learn more about:
