Comparing version 0.0.1 to 0.0.2
@@ -1,6 +0,7 @@ | ||
try { | ||
var platform = require('./'+process.arch+'/'+process.platform); | ||
} catch (e){ | ||
var path = require('path'); | ||
var exists = require('fs').existsSync || path.existsSync; | ||
if (!exists(path.resolve(__dirname, process.platform+'.js'))) { | ||
throw new Error("This platform isn't supported yet."); | ||
} | ||
var platform = require('./'+process.platform); | ||
@@ -10,2 +11,7 @@ | ||
var clipboard = module.exports = { | ||
/** | ||
* Iterate through the formats in the clipboard raising a callback for each | ||
* @param {Function} callback callback(format, formatName, isCustom) | ||
* @return {Array} the collected return values from the callbacks | ||
*/ | ||
iterate: function iterate(callback){ | ||
@@ -26,2 +32,5 @@ var iterator = platform.formatIterator(); | ||
/** | ||
* Clear the clipboard of all data | ||
*/ | ||
clear: function clear(){ | ||
@@ -31,5 +40,10 @@ platform.ref(); | ||
platform.unref(); | ||
return result; | ||
}, | ||
/** | ||
* Write a value or values to the clipboard. | ||
* @param {Array} values Organized as [{ format: formatName, value: valueToWrite }, ...] | ||
* or [[formatName, valueToWrite], ...] | ||
* @param {String} values A single string will be written to the primary plaintext clipboard field | ||
*/ | ||
write: function write(values){ | ||
@@ -40,10 +54,18 @@ if (typeof values === 'string') { | ||
values = Array.isArray(values) ? values : [values]; | ||
platform.ref(); | ||
platform.clear(); | ||
values.forEach(function(item){ | ||
platform.write(item.format || item[0], item.value || item[1]); | ||
}); | ||
platform.unref(); | ||
}, | ||
/** | ||
* Read a value from the clipboard based on format type | ||
* @param {String} format Specific clipboard format field to read from | ||
* @return {Buffer|String} Resolved clipboard value | ||
*/ | ||
read: function read(format){ | ||
@@ -71,2 +93,6 @@ format = format || 'ascii'; | ||
/** | ||
* Read all fields from the clipboard | ||
* @return {Object[]} [{format: formatName, value: stringOrBuffer, custom: booleanIsCustomFieldType }] | ||
*/ | ||
readAll: function readAll(){ | ||
@@ -82,2 +108,6 @@ return clipboard.iterate(function(format, formatName, isCustom){ | ||
/** | ||
* Get an array of the format names for the data currently in the clipboard | ||
* @return {String[]} | ||
*/ | ||
formats: function formats(){ | ||
@@ -84,0 +114,0 @@ return clipboard.iterate(function(format, formatName, isCustom){ |
@@ -6,3 +6,3 @@ var ffi = require('node-ffi'); | ||
Pointer: ffi.Pointer, | ||
Constants: Constants, | ||
constants: constants, | ||
errno: ffi.errno, | ||
@@ -16,3 +16,3 @@ NULL: ffi.Pointer.NULL, | ||
this._lib = new ffi.DynamicLibrary(name ? name + Library.extension : null, ffi.DynamicLibrary.FLAGS.RTLD_NOW); | ||
if (functions) this.createFunction(functions); | ||
functions && this.createFunction(functions); | ||
} | ||
@@ -23,4 +23,6 @@ Library.extension = ffi.PLATFORM_LIBRARY_EXTENSIONS[process.platform]; | ||
constructor: Library, | ||
createFunction: function createFunction(name, ret, params){ | ||
if (typeof name === 'object') { | ||
// multiple functions were provided | ||
var self = this; | ||
@@ -32,13 +34,23 @@ return Object.keys(name).reduce(function(fns, name){ | ||
} | ||
var names = params ? Object.keys(params) : []; | ||
var types = names.map(function(param){ return params[param] }); | ||
var func = this[name] = new ffi.ForeignFunction(this._lib.get(name), ret, types); | ||
var paramNames = params ? Object.keys(params) : []; | ||
var paramTypes = paramNames.map(function(param){ return params[param] }); | ||
var func = this[name] = new ffi.ForeignFunction(this._lib.get(name), ret, paramTypes); | ||
// getFunction is a useless artifact from an older node-ffi version | ||
delete func.getFunction; | ||
names.forEach(function(name,i){ Object.defineProperty(func, i, { value: name }) }); | ||
paramNames.forEach(function(name,i){ | ||
// put the param names on the function for potential usage for debugging/introspection | ||
Object.defineProperty(func, i, { value: name, configurable: true }) | ||
}); | ||
return func; | ||
}, | ||
set _lib(v){ Object.defineProperty(this, '_lib', { value: v }) }, | ||
}; | ||
function Constants(name, map){ | ||
// convenience wrapper around sets of constants for translating back and forth | ||
function constants(name, map){ | ||
map = Object.keys(map).reduce(function(ret, key){ | ||
@@ -45,0 +57,0 @@ var val = map[key]; |
@@ -5,3 +5,3 @@ { | ||
"description": "Easy to use utility for reading and writing to the system clipboard.", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -12,3 +12,3 @@ # node-clipboard | ||
```javascript | ||
var clipboard = require('node-clipboard'); | ||
var clipboard = require('clipboard'); | ||
@@ -15,0 +15,0 @@ // _Read_ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
14496
381
2
1