clipboardy
Advanced tools
Comparing version 0.1.2 to 1.0.0
106
index.js
'use strict'; | ||
const execa = require('execa'); | ||
const writeCmd = () => { | ||
switch (process.platform) { | ||
case 'darwin': | ||
return ['pbcopy']; | ||
case 'win32': | ||
return ['clip']; | ||
default: | ||
return ['xsel', '--clipboard', '--input']; | ||
const handler = err => { | ||
if (err.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; | ||
}; | ||
const readCmd = () => { | ||
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) | ||
}; | ||
const win32 = { | ||
copy: opts => execa('clip', [], opts), | ||
paste: opts => execa.stdout('cscript', ['/Nologo', '.\\fallbacks\\win-read.vbs'], opts), | ||
copySync: opts => execa.sync('clip', [], opts), | ||
pasteSync: opts => execa.sync('cscript', ['/Nologo', '.\\fallbacks\\win-read.vbs'], opts) | ||
}; | ||
const linux = { | ||
copy: opts => { | ||
return execa('./vendor/xsel', ['--clipboard', '--input'], opts) | ||
.catch(() => execa('xsel', ['--clipboard', '--input'], opts)) | ||
.catch(handler); | ||
}, | ||
paste: opts => { | ||
return execa.stdout('./vendor/xsel', ['--clipboard', '--output'], opts) | ||
.catch(() => execa.stdout('xsel', ['--clipboard', '--output'], opts)) | ||
.catch(handler); | ||
}, | ||
copySync: opts => { | ||
try { | ||
return execa.sync('./vendor/xsel', ['--clipboard', '--input'], opts); | ||
} catch (err) { | ||
try { | ||
return execa.sync('xsel', ['--clipboard', '--input'], opts); | ||
} catch (err) { | ||
handler(err); | ||
} | ||
} | ||
}, | ||
pasteSync: opts => { | ||
try { | ||
return execa.sync('./vendor/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 ['pbpaste']; | ||
return darwin; | ||
case 'win32': | ||
return ['cscript', '/Nologo', '.\\fallbacks\\win-read.vbs']; | ||
return win32; | ||
default: | ||
return ['xsel', '--clipboard', '--output']; | ||
return linux; | ||
} | ||
}; | ||
} | ||
const handler = err => { | ||
if (err.code === 'ENOENT' && process.platform !== 'darwin' && process.platform !== 'win32') { | ||
throw new Error('Couldn\'t find the required `xsel` binary. On Debian/Ubuntu you can install it with: sudo apt install xsel'); | ||
} | ||
throw err; | ||
}; | ||
exports.write = input => { | ||
@@ -39,10 +77,6 @@ if (typeof input !== 'string') { | ||
const args = writeCmd(); | ||
return execa(args.shift(), args, {input}).then(() => {}).catch(handler); | ||
return platform().copy({input}).then(() => {}); | ||
}; | ||
exports.read = () => { | ||
const args = readCmd(); | ||
return execa.stdout(args.shift(), args).catch(handler); | ||
}; | ||
exports.read = () => platform().paste(); | ||
@@ -54,19 +88,5 @@ exports.writeSync = input => { | ||
const args = writeCmd(); | ||
const results = execa.sync(args.shift(), args, {input}); | ||
if (results.error) { | ||
handler(results.error); | ||
} | ||
platform().copySync({input}); | ||
}; | ||
exports.readSync = () => { | ||
const args = readCmd(); | ||
const results = execa.sync(args.shift(), args); | ||
if (results.error) { | ||
handler(results.error); | ||
} | ||
return results.stdout; | ||
}; | ||
exports.readSync = () => platform().pasteSync().stdout; |
{ | ||
"name": "clipboardy", | ||
"version": "0.1.2", | ||
"version": "1.0.0", | ||
"description": "Access the system clipboard (copy/paste)", | ||
@@ -20,3 +20,4 @@ "license": "MIT", | ||
"index.js", | ||
"fallbacks" | ||
"fallbacks", | ||
"vendor" | ||
], | ||
@@ -37,3 +38,3 @@ "keywords": [ | ||
"dependencies": { | ||
"execa": "^0.5.0" | ||
"execa": "^0.6.0" | ||
}, | ||
@@ -40,0 +41,0 @@ "devDependencies": { |
@@ -14,5 +14,3 @@ # 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) | ||
*Linux users will probably have to install [xsel](https://linux.die.net/man/1/xsel): `sudo apt install xsel`* | ||
## Usage | ||
@@ -19,0 +17,0 @@ |
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 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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
134807
6
78
1
64
1
+ Addedcross-spawn@5.1.0(transitive)
+ Addedexeca@0.6.3(transitive)
+ Addedget-stream@3.0.0(transitive)
+ Addedshebang-command@1.2.0(transitive)
+ Addedshebang-regex@1.0.0(transitive)
- Removedcross-spawn@4.0.2(transitive)
- Removedexeca@0.5.1(transitive)
- Removedget-stream@2.3.1(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
Updatedexeca@^0.6.0