clipboardy
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -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" | ||
} | ||
} |
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
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
927266
173