clipboardy
Advanced tools
Comparing version 1.1.1 to 1.1.2
86
index.js
'use strict'; | ||
const path = require('path'); | ||
const execa = require('execa'); | ||
const termux = require('./lib/termux.js'); | ||
const linux = require('./lib/linux.js'); | ||
const macos = require('./lib/macos.js'); | ||
const windows = require('./lib/windows.js'); | ||
const handler = err => { | ||
if (err.code === 'ENOENT') { | ||
let message = 'Couldn\'t find the required `xsel` binary. On Debian/Ubuntu you can install it with: sudo apt install xsel'; | ||
if (err.path === 'termux-clipboard-get' || err.path === 'termux-clipboard-set') { | ||
message = 'Couldn\'t find the termux-api scripts. You can install them with: apt install termux-api'; | ||
} | ||
throw new Error(message); | ||
} | ||
throw err; | ||
}; | ||
const darwin = { | ||
copy: opts => execa('pbcopy', opts), | ||
paste: opts => execa.stdout('pbpaste', opts), | ||
copySync: opts => execa.sync('pbcopy', opts), | ||
pasteSync: opts => execa.sync('pbpaste', opts) | ||
}; | ||
// Binaries from: https://github.com/sindresorhus/win-clipboard | ||
const winReadBinPath = path.join(__dirname, 'fallbacks/win/paste.exe'); | ||
const winWriteBinPath = path.join(__dirname, 'fallbacks/win/copy.exe'); | ||
const win32 = { | ||
copy: opts => { | ||
const input = opts.input; | ||
delete opts.input; | ||
return execa(winWriteBinPath, [input], opts); | ||
}, | ||
paste: opts => execa.stdout(winReadBinPath, opts), | ||
copySync: opts => { | ||
const input = opts.input; | ||
delete opts.input; | ||
return execa.sync(winWriteBinPath, [input], opts); | ||
}, | ||
pasteSync: opts => execa.sync(winReadBinPath, opts) | ||
}; | ||
const xsel = path.join(__dirname, 'vendor/xsel'); | ||
const linux = { | ||
copy: opts => { | ||
return execa(xsel, ['--clipboard', '--input'], opts) | ||
.catch(() => execa('xsel', ['--clipboard', '--input'], opts)) | ||
.catch(handler); | ||
}, | ||
paste: opts => { | ||
return execa.stdout(xsel, ['--clipboard', '--output'], opts) | ||
.catch(() => execa.stdout('xsel', ['--clipboard', '--output'], opts)) | ||
.catch(handler); | ||
}, | ||
copySync: opts => { | ||
try { | ||
return execa.sync(xsel, ['--clipboard', '--input'], opts); | ||
} catch (err) { | ||
try { | ||
return execa.sync('xsel', ['--clipboard', '--input'], opts); | ||
} catch (err) { | ||
handler(err); | ||
} | ||
} | ||
}, | ||
pasteSync: opts => { | ||
try { | ||
return execa.sync(xsel, ['--clipboard', '--output'], opts); | ||
} catch (err) { | ||
try { | ||
return execa.sync('xsel', ['--clipboard', '--output'], opts); | ||
} catch (err) { | ||
handler(err); | ||
} | ||
} | ||
} | ||
}; | ||
function platform() { | ||
switch (process.platform) { | ||
case 'darwin': | ||
return darwin; | ||
return macos; | ||
case 'win32': | ||
return win32; | ||
return windows; | ||
case 'android': | ||
@@ -91,3 +17,3 @@ if (process.env.PREFIX !== '/data/data/com.termux/files/usr') { | ||
} | ||
return termux(handler); | ||
return termux; | ||
default: | ||
@@ -94,0 +20,0 @@ return linux; |
'use strict'; | ||
const execa = require('execa'); | ||
module.exports = handler => { | ||
return { | ||
copy: opts => execa('termux-clipboard-set', opts).catch(handler), | ||
paste: opts => execa.stdout('termux-clipboard-get', opts).catch(handler), | ||
copySync: opts => { | ||
try { | ||
return execa.sync('termux-clipboard-set', opts); | ||
} catch (err) { | ||
handler(err); | ||
} | ||
}, | ||
pasteSync: opts => { | ||
try { | ||
return execa.sync('termux-clipboard-get', opts); | ||
} catch (err) { | ||
handler(err); | ||
} | ||
const handler = err => { | ||
if (err.code === 'ENOENT') { | ||
throw new Error('Couldn\'t find the termux-api scripts. You can install them with: apt install termux-api'); | ||
} | ||
throw err; | ||
}; | ||
module.exports = { | ||
copy: opts => execa('termux-clipboard-set', opts).catch(handler), | ||
paste: opts => execa.stdout('termux-clipboard-get', opts).catch(handler), | ||
copySync: opts => { | ||
try { | ||
return execa.sync('termux-clipboard-set', opts); | ||
} catch (err) { | ||
handler(err); | ||
} | ||
}; | ||
}, | ||
pasteSync: opts => { | ||
try { | ||
return execa.sync('termux-clipboard-get', opts); | ||
} catch (err) { | ||
handler(err); | ||
} | ||
} | ||
}; |
{ | ||
"name": "clipboardy", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Access the system clipboard (copy/paste)", | ||
@@ -21,4 +21,3 @@ "license": "MIT", | ||
"lib", | ||
"fallbacks", | ||
"vendor" | ||
"fallbacks" | ||
], | ||
@@ -25,0 +24,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 3 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 3 instances in 1 package
172285
11
133
3