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 2.0.0 to 2.1.0

85

lib/linux.js

@@ -5,57 +5,54 @@ 'use strict';

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');
const xsel = 'xsel';
const xselFallback = path.join(__dirname, '../fallbacks/linux/xsel');
const copyArguments = ['--clipboard', '--input'];
const pasteArguments = ['--clipboard', '--output'];
const makeError = (xselError, fallbackError) => {
let error;
if (xselError.code === 'ENOENT') {
error = new Error('Couldn\'t find the `xsel` binary and fallback didn\'t work. On Debian/Ubuntu you can install xsel with: sudo apt install xsel');
} else {
error = new Error('Both xsel and fallback failed');
error.xselError = xselError;
}
throw error;
error.fallbackError = fallbackError;
return error;
};
const xsel = path.join(__dirname, '../fallbacks/linux/xsel');
module.exports = {
copy: async options => {
const xselWithFallback = async (argumentList, options) => {
try {
return await execa.stdout(xsel, argumentList, options);
} catch (xselError) {
try {
await execa(xsel, ['--clipboard', '--input'], options);
} catch (_) {
try {
await execa('xsel', ['--clipboard', '--input'], options);
} catch (error) {
handler(error);
}
return await execa.stdout(xselFallback, argumentList, options);
} catch (fallbackError) {
throw makeError(xselError, fallbackError);
}
},
paste: async options => {
}
};
const xselWithFallbackSync = (argumentList, options) => {
try {
return execa.sync(xsel, argumentList, options);
} catch (xselError) {
try {
return await execa.stdout(xsel, ['--clipboard', '--output'], options);
} catch (_) {
try {
return await execa.stdout('xsel', ['--clipboard', '--output'], options);
} catch (error) {
handler(error);
}
return execa.sync(xselFallback, argumentList, options);
} catch (fallbackError) {
throw makeError(xselError, fallbackError);
}
}
};
module.exports = {
copy: async options => {
await xselWithFallback(copyArguments, options);
},
copySync: options => {
try {
execa.sync(xsel, ['--clipboard', '--input'], options);
} catch (_) {
try {
execa.sync('xsel', ['--clipboard', '--input'], options);
} catch (error) {
handler(error);
}
}
xselWithFallbackSync(copyArguments, options);
},
pasteSync: options => {
try {
return execa.sync(xsel, ['--clipboard', '--output'], options);
} catch (_) {
try {
return execa.sync('xsel', ['--clipboard', '--output'], options);
} catch (error) {
handler(error);
}
}
}
paste: options => xselWithFallback(pasteArguments, options),
pasteSync: options => xselWithFallbackSync(pasteArguments, options)
};
{
"name": "clipboardy",
"version": "2.0.0",
"version": "2.1.0",
"description": "Access the system clipboard (copy/paste)",

@@ -42,6 +42,6 @@ "license": "MIT",

"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"ava": "^2.1.0",
"tsd": "^0.7.3",
"xo": "^0.24.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