forked from udarrr/clipboard-sys
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
106 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# sys-clipboard | ||
|
||
> Access the system clipboard (copy/paste text, images, files) | ||
Cross-platform! | ||
|
||
Supports: | ||
|
||
- Windows(text, images, files) | ||
- Linux (text,images,files) *should be installed xclip (`sudo apt install xclip`))* | ||
- MacOS (text, images), | ||
|
||
## Install | ||
|
||
``` | ||
npm install sys-clipboard | ||
``` | ||
|
||
## Usage | ||
|
||
```typescript | ||
import sysClipboard from 'sysClipboard'; | ||
|
||
async function readWriteText() { | ||
await sysClipboard.writeText('some text'); | ||
console.log('text from clipboard:', await sysClipboard.readText()); | ||
} | ||
readWriteText(); | ||
|
||
async function readWriteImage() { | ||
await sysClipboard.writeImage('./source.png'); | ||
await sysClipboard.writeImage(fs.readFileSync('./source.png')); //buffer | ||
|
||
await sysClipboard.readImage('./destination.png'); | ||
await sysClipboard.readImage(); //buffer | ||
} | ||
readWriteImage(); | ||
|
||
async function copyPasteFiles() { | ||
await sysClipboard.pasteFiles('Copy', './', './source1.png', './source2.png'); | ||
await sysClipboard.pasteFiles('Cut', './', './source1.png', './source2.png'); | ||
} | ||
copyPasteFiles(); | ||
|
||
//For windows | ||
await sysClipboard.writeFiles('./source.png', './some.png'); // only windows | ||
console.log(await sysClipboard.readFiles()); // only windows | ||
``` | ||
|
||
## API | ||
```typescript | ||
export interface SysClipboard { | ||
readText(): Promise<string>; | ||
writeText: (text: string) => Promise<void>; | ||
readImage(file?: string): Promise<Buffer>; | ||
writeImage(file: string | Buffer): Promise<void>; | ||
readFiles(): Promise<Array<string>>; | ||
pasteFiles(action: 'Copy' | 'Cut', destinationFolder: string, ...files: Array<string>): Promise<void>; | ||
writeFiles(...files: Array<string>): Promise<boolean>; | ||
} | ||
``` | ||
|
||
#### Contribution | ||
|
||
Opened for contribution https://github.com/udarrr/sys-clipboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters