Huge News!Announcing our $40M Series B led by Abstract Ventures.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 1.2.3 to 2.0.0

index.d.ts

25

index.js

@@ -7,3 +7,3 @@ 'use strict';

function platform() {
const platformLib = (() => {
switch (process.platform) {

@@ -18,2 +18,3 @@ case 'darwin':

}
return termux;

@@ -23,22 +24,22 @@ default:

}
}
})();
exports.write = input => {
if (typeof input !== 'string') {
return Promise.reject(new TypeError(`Expected a string, got ${typeof input}`));
exports.write = async text => {
if (typeof text !== 'string') {
throw new TypeError(`Expected a string, got ${typeof text}`);
}
return platform().copy({input}).then(() => {});
await platformLib.copy({input: text});
};
exports.read = () => platform().paste({stripEof: false});
exports.read = async () => platformLib.paste({stripEof: false});
exports.writeSync = input => {
if (typeof input !== 'string') {
throw new TypeError(`Expected a string, got ${typeof input}`);
exports.writeSync = text => {
if (typeof text !== 'string') {
throw new TypeError(`Expected a string, got ${typeof text}`);
}
platform().copySync({input});
platformLib.copySync({input: text});
};
exports.readSync = () => platform().pasteSync({stripEof: false}).stdout;
exports.readSync = () => platformLib.pasteSync({stripEof: false}).stdout;

@@ -5,8 +5,8 @@ 'use strict';

const handler = err => {
if (err.code === 'ENOENT') {
const handler = error => {
if (error.code === 'ENOENT') {
throw new Error('Couldn\'t find the required `xsel` binary. On Debian/Ubuntu you can install it with: sudo apt install xsel');
}
throw err;
throw error;
};

@@ -17,31 +17,43 @@

module.exports = {
copy: opts => {
return execa(xsel, ['--clipboard', '--input'], opts)
.catch(() => execa('xsel', ['--clipboard', '--input'], opts))
.catch(handler);
copy: async options => {
try {
await execa(xsel, ['--clipboard', '--input'], options);
} catch (_) {
try {
await execa('xsel', ['--clipboard', '--input'], options);
} catch (error) {
handler(error);
}
}
},
paste: opts => {
return execa.stdout(xsel, ['--clipboard', '--output'], opts)
.catch(() => execa.stdout('xsel', ['--clipboard', '--output'], opts))
.catch(handler);
paste: async options => {
try {
return await execa.stdout(xsel, ['--clipboard', '--output'], options);
} catch (_) {
try {
return await execa.stdout('xsel', ['--clipboard', '--output'], options);
} catch (error) {
handler(error);
}
}
},
copySync: opts => {
copySync: options => {
try {
return execa.sync(xsel, ['--clipboard', '--input'], opts);
} catch (err) {
execa.sync(xsel, ['--clipboard', '--input'], options);
} catch (_) {
try {
return execa.sync('xsel', ['--clipboard', '--input'], opts);
} catch (err) {
handler(err);
execa.sync('xsel', ['--clipboard', '--input'], options);
} catch (error) {
handler(error);
}
}
},
pasteSync: opts => {
pasteSync: options => {
try {
return execa.sync(xsel, ['--clipboard', '--output'], opts);
} catch (err) {
return execa.sync(xsel, ['--clipboard', '--output'], options);
} catch (_) {
try {
return execa.sync('xsel', ['--clipboard', '--output'], opts);
} catch (err) {
handler(err);
return execa.sync('xsel', ['--clipboard', '--output'], options);
} catch (error) {
handler(error);
}

@@ -48,0 +60,0 @@ }

'use strict';
const execa = require('execa');
const env = Object.assign({}, process.env, {LC_CTYPE: 'UTF-8'});
const env = {
...process.env,
LC_CTYPE: 'UTF-8'
};
module.exports = {
copy: opts => execa('pbcopy', Object.assign({}, opts, {env})),
paste: opts => execa.stdout('pbpaste', Object.assign({}, opts, {env})),
copySync: opts => execa.sync('pbcopy', Object.assign({}, opts, {env})),
pasteSync: opts => execa.sync('pbpaste', Object.assign({}, opts, {env}))
copy: async options => execa('pbcopy', {...options, env}),
paste: async options => execa.stdout('pbpaste', {...options, env}),
copySync: options => execa.sync('pbcopy', {...options, env}),
pasteSync: options => execa.sync('pbpaste', {...options, env})
};
'use strict';
const execa = require('execa');
const handler = err => {
if (err.code === 'ENOENT') {
const handler = error => {
if (error.code === 'ENOENT') {
throw new Error('Couldn\'t find the termux-api scripts. You can install them with: apt install termux-api');
}
throw err;
throw error;
};
module.exports = {
copy: opts => execa('termux-clipboard-set', opts).catch(handler),
paste: opts => execa.stdout('termux-clipboard-get', opts).catch(handler),
copySync: opts => {
copy: async options => {
try {
return execa.sync('termux-clipboard-set', opts);
} catch (err) {
handler(err);
await execa('termux-clipboard-set', options);
} catch (error) {
handler(error);
}
},
pasteSync: opts => {
paste: async options => {
try {
return execa.sync('termux-clipboard-get', opts);
} catch (err) {
handler(err);
return await execa.stdout('termux-clipboard-get', options);
} catch (error) {
handler(error);
}
},
copySync: options => {
try {
execa.sync('termux-clipboard-set', options);
} catch (error) {
handler(error);
}
},
pasteSync: options => {
try {
return execa.sync('termux-clipboard-get', options);
} catch (error) {
handler(error);
}
}
};

@@ -7,3 +7,3 @@ 'use strict';

// Binaries from: https://github.com/sindresorhus/win-clipboard
const winBinPath = arch() === 'x64' ?
const windowBinaryPath = arch() === 'x64' ?
path.join(__dirname, '../fallbacks/windows/clipboard_x86_64.exe') :

@@ -13,6 +13,6 @@ path.join(__dirname, '../fallbacks/windows/clipboard_i686.exe');

module.exports = {
copy: opts => execa(winBinPath, ['--copy'], opts),
paste: opts => execa.stdout(winBinPath, ['--paste'], opts),
copySync: opts => execa.sync(winBinPath, ['--copy'], opts),
pasteSync: opts => execa.sync(winBinPath, ['--paste'], opts)
copy: async options => execa(windowBinaryPath, ['--copy'], options),
paste: async options => execa.stdout(windowBinaryPath, ['--paste'], options),
copySync: options => execa.sync(windowBinaryPath, ['--copy'], options),
pasteSync: options => execa.sync(windowBinaryPath, ['--paste'], options)
};
{
"name": "clipboardy",
"version": "1.2.3",
"version": "2.0.0",
"description": "Access the system clipboard (copy/paste)",

@@ -13,9 +13,10 @@ "license": "MIT",

"engines": {
"node": ">=4"
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts",
"lib",

@@ -38,9 +39,10 @@ "fallbacks"

"dependencies": {
"arch": "^2.1.0",
"execa": "^0.8.0"
"arch": "^2.1.1",
"execa": "^1.0.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}

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

# clipboardy [![Build Status: macOS & Linux](https://travis-ci.org/sindresorhus/clipboardy.svg?branch=master)](https://travis-ci.org/sindresorhus/clipboardy) [![Build status: Windows](https://ci.appveyor.com/api/projects/status/gflt3gjn1ia0a3vo/branch/master?svg=true)](https://ci.appveyor.com/project/sindresorhus/clipboardy/branch/master)
# clipboardy [![Build Status](https://travis-ci.org/sindresorhus/clipboardy.svg?branch=master)](https://travis-ci.org/sindresorhus/clipboardy)

@@ -31,10 +31,12 @@ > Access the system clipboard (copy/paste)

#### .write(input)
#### .write(text)
Write (copy) to the clipboard asynchronously. Returns a `Promise`.
##### input
##### text
Type: `string`
The text to write to the clipboard.
#### .read()

@@ -44,10 +46,12 @@

#### .writeSync(input)
#### .writeSync(text)
Write (copy) to the clipboard synchronously.
##### input
##### text
Type: `string`
The text to write to the clipboard.
#### .readSync()

@@ -54,0 +58,0 @@

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