Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

piggie

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

piggie - npm Package Compare versions

Comparing version 0.0.2 to 0.0.4

Makefile

4

index.js

@@ -1,1 +0,3 @@

module.exports = exports = require( './lib/bridge' );
module.exports = process.env.PIGGIE_COVERAGE
? require( './lib-cov/bridge' )
: require( './lib/bridge' );

@@ -1,40 +0,56 @@

var _ = require( 'lodash' ),
Response = require( './response' );
// Dependencies
var Response = require( './response' );
var paths = [];
// Handlers hash
var handlers = {};
var handle = function handle( path, handler ) {
// TODO: Error if a handler for that path already exists
paths.push( {
path: path,
handler: handler
} );
/**
* Resets the handlers hash
*/
var reset = function reset () {
handlers = {};
};
var send = function send( key, path, data ) {
var res = new Response( key );
/**
* Register handler
*/
var register = function register ( path, handler ) {
path = unescape(path);
if (data && data.trim() !== "") {
data = unescape(data);
if ( handlers.hasOwnProperty( path ) ) {
throw new Error( 'Handler already exists for path: ' + path );
} else {
handlers[ path ] = handler;
}
};
/**
* Execute handler
*/
var execute = function execute ( key, path, data ) {
var response = ( key instanceof Response ? key : new Response( key ) );
path = unescape( path );
if ( data && data.trim() !== "" ) {
data = unescape( data );
try {
data = JSON.parse(data);
} catch (e) {
return res.error( 'JSON parse error: ' + e );
data = JSON.parse( data );
} catch ( error ) {
return response.fail( error );
}
}
var pathHandler = _.find( paths, {path: path} );
if ( !pathHandler ) {
return res.error( 'No handler defined for path: ' + path );
if ( handlers[ path ] ) {
handlers[ path ]( data, response );
return response;
} else {
return response.fail( new Error( 'No handler defined for path: ' + path ) );
}
pathHandler.handler( data, res );
};
// TODO: Events
module.exports.handle = handle;
module.exports.send = send;
// Exports
module.exports.register = register;
module.exports.execute = execute;
module.exports.reset = reset;

@@ -1,17 +0,32 @@

module.exports = function Response( key ) {
this.error = function error( error ) {
/**
* Response constructor
*/
var Response = function Response ( key ) {
this.key = key;
return this;
};
Response.prototype = {
/**
* Native party failure callback
*/
fail: function fail ( error, code ) {
if ( typeof window != "undefined" && window.android ) {
window.android.reply( key, error, null );
} else {
console.log( 'Error %d: %s', key, error );
window.android.fail( this.key, ( code || null ), error.name, error.message );
}
};
},
this.send = function send( response ) {
/**
* Native party success callback
*/
success: function success ( data ) {
if ( typeof window != "undefined" && window.android ) {
window.android.reply( key, null, response );
} else {
console.log( 'Send %d: %s', key, response );
window.android.success( this.key, data );
}
};
}
};
// Exports
module.exports = Response;
{
"name": "piggie",
"version": "0.0.2",
"version": "0.0.4",
"main": "app.js",
"dependencies": {
"lodash": "~2.4.1"
"dependencies": {},
"devDependencies": {
"mocha": "~1.18.2",
"sinon": "~1.9.1"
},
"devDependencies": {},
"scripts": {
"start": "node app.js"
"start": "node app.js",
"test": "make test"
},

@@ -17,2 +19,6 @@ "author": "ribot",

"email": "matt@ribot.co.uk"
},
{
"name": "Stefan Pearson",
"email": "stefan@ribot.co.uk"
}

@@ -19,0 +25,0 @@ ],

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc