copy-paste
Advanced tools
Comparing version 1.0.4 to 1.1.0
18
index.js
@@ -7,3 +7,3 @@ var child_process = require("child_process"); | ||
if(child_process.execSync) { // Use native execSync if avaiable | ||
return function(cmd) { return child_process.execSync(cmd).toString(); } | ||
return function(cmd) { return child_process.execSync(cmd); }; | ||
} else { | ||
@@ -47,5 +47,2 @@ try { // Try using fallback package if available | ||
child.stdin.setEncoding(config.encoding); | ||
child.stderr.setEncoding(config.encoding); | ||
child.stdin.on("error", function (err) { done(err); }); | ||
@@ -59,3 +56,3 @@ child | ||
if(err.length === 0) { return; } | ||
done(new Error(err.join(""))); | ||
done(new Error(config.decode(err))); | ||
}) | ||
@@ -73,3 +70,3 @@ ; | ||
child.stdin.end(new Buffer(output, config.encoding)); | ||
child.stdin.end(config.encode(output)); | ||
} | ||
@@ -82,3 +79,3 @@ | ||
exports.paste = function(callback) { | ||
if(execSync && !callback) { return execSync(pasteCommand); } | ||
if(execSync && !callback) { return config.decode(execSync(pasteCommand)); } | ||
else if(callback) { | ||
@@ -91,9 +88,6 @@ var child = spawn(config.paste.command, config.paste.args); | ||
child.stdin.setEncoding("utf8"); | ||
child.stderr.setEncoding("utf8"); | ||
child.on("error", function(err) { done(err); }); | ||
child.stdout | ||
.on("data", function(chunk) { data.push(chunk); }) | ||
.on("end", function() { done(null, data.join("")); }) | ||
.on("end", function() { done(null, config.decode(data)); }) | ||
; | ||
@@ -105,3 +99,3 @@ child.stderr | ||
done(new Error(err.join(""))); | ||
done(new Error(config.decode(err))); | ||
}) | ||
@@ -108,0 +102,0 @@ ; |
{ "name": "copy-paste" | ||
, "version": "1.0.4" | ||
, "version": "1.1.0" | ||
, "description": "A command line utility that allows read/write (i.e copy/paste) access to the system clipboard." | ||
@@ -16,4 +16,6 @@ , "keywords": [ "copy", "paste", "copy and paste", "clipboard" ] | ||
} | ||
, "dependencies": | ||
{ "iconv-lite": "^0.4.8" } | ||
, "optionalDependencies": | ||
{ "execSync": "~1.0.0" } | ||
} |
exports.copy = { command: "pbcopy", args: [] }; | ||
exports.paste = { command: "pbpaste", args: [] }; | ||
exports.encoding = "utf8"; | ||
exports.encode = function(str) { return new Buffer(str, "utf8"); }; | ||
exports.decode = function(chunks) { | ||
if(!Array.isArray(chunks)) { chunks = [ chunks ]; } | ||
return Buffer.concat(chunks).toString("utf8"); | ||
}; |
exports.copy = { command: "xclip", args: [ "-selection", "clipboard" ] }; | ||
exports.paste = { command: "xclip", args: [ "-selection", "clipboard", "-o" ] }; | ||
exports.encoding = "utf8"; | ||
exports.encode = function(str) { return new Buffer(str, "utf8"); }; | ||
exports.decode = function(chunks) { | ||
if(!Array.isArray(chunks)) { chunks = [ chunks ]; } | ||
return Buffer.concat(chunks).toString("utf8"); | ||
}; |
@@ -0,3 +1,11 @@ | ||
var iconv = require("iconv-lite"); | ||
exports.copy = { command: "clip", args: [] }; | ||
exports.paste = { command: "cscript", args: [ "/Nologo", __dirname + ".\\fallbacks\\paste.vbs" ] }; | ||
exports.encoding = "utf16le"; | ||
exports.encode = function(str) { return iconv.encode(str, "utf16le"); }; | ||
exports.decode = function(chunks) { | ||
if(!Array.isArray(chunks)) { chunks = [ chunks ]; } | ||
var str = iconv.decode(Buffer.concat(chunks), "cp437"); | ||
return str.substr(0, str.length - 2); // Chops off extra "\r\n" | ||
}; |
7349
117
2
+ Addediconv-lite@^0.4.8
+ Addediconv-lite@0.4.24(transitive)
+ Addedsafer-buffer@2.1.2(transitive)