New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

clipboardy

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clipboardy - npm Package Compare versions

Comparing version 2.3.0 to 3.0.0

13

browser.js
/* eslint-env browser */
'use strict';
export const write = async text => {
const clipboard = {};
clipboard.write = async text => {
await navigator.clipboard.writeText(text);
};
export const read = async () => navigator.clipboard.readText();
clipboard.read = async () => navigator.clipboard.readText();
export const readSync = () => {
clipboard.readSync = () => {
throw new Error('`.readSync()` is not supported in browsers!');
};
export const writeSync = () => {
clipboard.writeSync = () => {
throw new Error('`.writeSync()` is not supported in browsers!');
};
export default clipboard;

@@ -1,37 +0,71 @@

/**
Write (copy) to the clipboard asynchronously.
declare const clipboard: {
/**
Write (copy) to the clipboard asynchronously.
@param text - The text to write to the clipboard.
*/
export function write(text: string): Promise<void>;
@param text - The text to write to the clipboard.
/**
Write (copy) to the clipboard synchronously.
@example
```
import clipboard from 'clipboardy';
Doesn't work in browsers.
await clipboard.write('🦄');
@param text - The text to write to the clipboard.
await clipboard.read();
//=> '🦄'
```
*/
write(text: string): Promise<void>;
@example
```
import * as clipboardy from 'clipboardy';
/**
Read (paste) from the clipboard asynchronously.
clipboardy.writeSync('🦄');
@example
```
import clipboard from 'clipboardy';
clipboardy.readSync();
//=> '🦄'
```
*/
export function writeSync(text: string): void;
await clipboard.write('🦄');
/**
Read (paste) from the clipboard asynchronously.
*/
export function read(): Promise<string>;
await clipboard.read();
//=> '🦄'
```
*/
read(): Promise<string>;
/**
Read (paste) from the clipboard synchronously.
/**
Write (copy) to the clipboard synchronously.
Doesn't work in browsers.
*/
export function readSync(): string;
__Doesn't work in browsers.__
@param text - The text to write to the clipboard.
@example
```
import clipboard from 'clipboardy';
clipboard.writeSync('🦄');
clipboard.readSync();
//=> '🦄'
```
*/
writeSync(text: string): void;
/**
Read (paste) from the clipboard synchronously.
__Doesn't work in browsers.__
@example
```
import clipboard from 'clipboardy';
clipboard.writeSync('🦄');
clipboard.readSync();
//=> '🦄'
```
*/
readSync(): string;
};
export default clipboard;

@@ -1,7 +0,7 @@

'use strict';
const isWSL = require('is-wsl');
const termux = require('./lib/termux.js');
const linux = require('./lib/linux.js');
const macos = require('./lib/macos.js');
const windows = require('./lib/windows.js');
import process from 'node:process';
import isWSL from 'is-wsl';
import termux from './lib/termux.js';
import linux from './lib/linux.js';
import macos from './lib/macos.js';
import windows from './lib/windows.js';

@@ -30,3 +30,5 @@ const platformLib = (() => {

exports.write = async text => {
const clipboard = {};
clipboard.write = async text => {
if (typeof text !== 'string') {

@@ -39,5 +41,5 @@ throw new TypeError(`Expected a string, got ${typeof text}`);

exports.read = async () => platformLib.paste({stripEof: false});
clipboard.read = async () => platformLib.paste({stripFinalNewline: false});
exports.writeSync = text => {
clipboard.writeSync = text => {
if (typeof text !== 'string') {

@@ -50,2 +52,4 @@ throw new TypeError(`Expected a string, got ${typeof text}`);

exports.readSync = () => platformLib.pasteSync({stripEof: false}).stdout;
clipboard.readSync = () => platformLib.pasteSync({stripFinalNewline: false});
export default clipboard;

@@ -1,5 +0,7 @@

'use strict';
const path = require('path');
const execa = require('execa');
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import execa from 'execa';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const xsel = 'xsel';

@@ -26,6 +28,8 @@ const xselFallback = path.join(__dirname, '../fallbacks/linux/xsel');

try {
return await execa.stdout(xsel, argumentList, options);
const {stdout} = await execa(xsel, argumentList, options);
return stdout;
} catch (xselError) {
try {
return await execa.stdout(xselFallback, argumentList, options);
const {stdout} = await execa(xselFallback, argumentList, options);
return stdout;
} catch (fallbackError) {

@@ -39,6 +43,6 @@ throw makeError(xselError, fallbackError);

try {
return execa.sync(xsel, argumentList, options);
return execa.sync(xsel, argumentList, options).stdout;
} catch (xselError) {
try {
return execa.sync(xselFallback, argumentList, options);
return execa.sync(xselFallback, argumentList, options).stdout;
} catch (fallbackError) {

@@ -50,3 +54,3 @@ throw makeError(xselError, fallbackError);

module.exports = {
const clipboard = {
copy: async options => {

@@ -59,3 +63,5 @@ await xselWithFallback(copyArguments, options);

paste: options => xselWithFallback(pasteArguments, options),
pasteSync: options => xselWithFallbackSync(pasteArguments, options)
pasteSync: options => xselWithFallbackSync(pasteArguments, options),
};
export default clipboard;

@@ -1,14 +0,17 @@

'use strict';
const execa = require('execa');
import execa from 'execa';
const env = {
...process.env,
LC_CTYPE: 'UTF-8'
LC_CTYPE: 'UTF-8',
};
module.exports = {
const clipboard = {
copy: async options => execa('pbcopy', {...options, env}),
paste: async options => execa.stdout('pbpaste', {...options, env}),
paste: async options => {
const {stdout} = await execa('pbpaste', {...options, env});
return stdout;
},
copySync: options => execa.sync('pbcopy', {...options, env}),
pasteSync: options => execa.sync('pbpaste', {...options, env})
pasteSync: options => execa.sync('pbpaste', {...options, env}).stdout,
};
export default clipboard;

@@ -1,3 +0,2 @@

'use strict';
const execa = require('execa');
import execa from 'execa';

@@ -12,3 +11,3 @@ const handler = error => {

module.exports = {
const clipboard = {
copy: async options => {

@@ -23,3 +22,4 @@ try {

try {
return await execa.stdout('termux-clipboard-get', options);
const {stdout} = await execa('termux-clipboard-get', options);
return stdout;
} catch (error) {

@@ -38,7 +38,9 @@ handler(error);

try {
return execa.sync('termux-clipboard-get', options);
return execa.sync('termux-clipboard-get', options).stdout;
} catch (error) {
handler(error);
}
}
},
};
export default clipboard;

@@ -1,16 +0,23 @@

'use strict';
const path = require('path');
const execa = require('execa');
const arch = require('arch');
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import execa from 'execa';
import arch from 'arch';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const binarySuffix = arch() === 'x64' ? 'x86_64' : 'i686';
// Binaries from: https://github.com/sindresorhus/win-clipboard
const windowBinaryPath = arch() === 'x64' ?
path.join(__dirname, '../fallbacks/windows/clipboard_x86_64.exe') :
path.join(__dirname, '../fallbacks/windows/clipboard_i686.exe');
const windowBinaryPath = path.join(__dirname, `../fallbacks/windows/clipboard_${binarySuffix}.exe`);
module.exports = {
const clipboard = {
copy: async options => execa(windowBinaryPath, ['--copy'], options),
paste: async options => execa.stdout(windowBinaryPath, ['--paste'], options),
paste: async options => {
const {stdout} = await execa(windowBinaryPath, ['--paste'], options);
return stdout;
},
copySync: options => execa.sync(windowBinaryPath, ['--copy'], options),
pasteSync: options => execa.sync(windowBinaryPath, ['--paste'], options)
pasteSync: options => execa.sync(windowBinaryPath, ['--paste'], options).stdout,
};
export default clipboard;
{
"name": "clipboardy",
"version": "2.3.0",
"version": "3.0.0",
"description": "Access the system clipboard (copy/paste)",
"license": "MIT",
"repository": "sindresorhus/clipboardy",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": {
"node": "./index.js",
"default": "./browser.js"
},
"engines": {
"node": ">=8"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},

@@ -39,16 +45,14 @@ "scripts": {

"dependencies": {
"arch": "^2.1.1",
"execa": "^1.0.0",
"is-wsl": "^2.1.1"
"arch": "^2.2.0",
"execa": "^5.1.1",
"is-wsl": "^2.2.0"
},
"devDependencies": {
"ava": "^2.1.0",
"tsd": "^0.10.0",
"xo": "^0.25.3"
"ava": "^3.15.0",
"tsd": "^0.18.0",
"xo": "^0.45.0"
},
"browser": "browser.js",
"exports": {
"browser": "./browser.js",
"default": "./index.js"
"ava": {
"serial": true
}
}

@@ -1,12 +0,12 @@

# clipboardy [![Build Status](https://travis-ci.org/sindresorhus/clipboardy.svg?branch=master)](https://travis-ci.org/sindresorhus/clipboardy)
# clipboardy
> Access the system clipboard (copy/paste)
Cross-platform. Supports: macOS, Windows, Linux, OpenBSD, FreeBSD, Android with [Termux](https://termux.com/), [modern browsers](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API#Browser_compatibility).
Cross-platform. Supports: macOS, Windows, Linux, OpenBSD, FreeBSD, Android with [Termux](https://termux.com/), and [modern browsers](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API#Browser_compatibility).
## Install
```sh
npm install clipboardy
```
$ npm install clipboardy
```

@@ -16,7 +16,7 @@ ## Usage

```js
const clipboardy = require('clipboardy');
import clipboard from 'clipboardy';
clipboardy.writeSync('🦄');
clipboard.writeSync('🦄');
clipboardy.readSync();
clipboard.readSync();
//=> '🦄'

@@ -27,8 +27,10 @@ ```

### clipboardy
### clipboard
#### .write(text)
Write (copy) to the clipboard asynchronously. Returns a `Promise`.
Write (copy) to the clipboard asynchronously.
Returns a `Promise`.
##### text

@@ -42,4 +44,6 @@

Read (paste) from the clipboard asynchronously. Returns a `Promise`.
Read (paste) from the clipboard asynchronously.
Returns a `Promise`.
#### .writeSync(text)

@@ -49,3 +53,3 @@

Doesn't work in browsers.
**Doesn't work in browsers.**

@@ -62,3 +66,3 @@ ##### text

Doesn't work in browsers.
**Doesn't work in browsers.**

@@ -69,3 +73,3 @@ ## FAQ

The [Linux binary](https://github.com/sindresorhus/clipboardy/blob/master/fallbacks/linux/xsel) is just a bundled version of [`xsel`](https://linux.die.net/man/1/xsel). The source for the [Windows binary](https://github.com/sindresorhus/clipboardy/blob/master/fallbacks/windows/clipboard_x86_64.exe) can be found [here](https://github.com/sindresorhus/win-clipboard).
The [Linux binary](fallbacks/linux/xsel) is just a bundled version of [`xsel`](https://linux.die.net/man/1/xsel). The source for the [Windows binary](fallbacks/windows/clipboard_x86_64.exe) can be found [here](https://github.com/sindresorhus/win-clipboard).

@@ -72,0 +76,0 @@ ## Related

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc