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

ambi

Package Overview
Dependencies
Maintainers
1
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ambi - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

54

out/lib/ambi.js

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.6.2
// Generated by CoffeeScript 1.6.3
var ambi, typeChecker,

@@ -8,8 +8,4 @@ __slice = [].slice;

ambi = function() {
var args, callback, caughtError, err, fireMethod, introspectMethod, method, result;
var args, completionCallback, err, fireMethod, introspectMethod, isAsynchronousMethod, method, result;
method = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
callback = args[args.length - 1];
result = null;
err = null;
if (typeChecker.isArray(method)) {

@@ -20,40 +16,22 @@ fireMethod = method[0], introspectMethod = method[1];

}
if (introspectMethod.length === args.length) {
try {
result = fireMethod.apply(null, args);
if (typeChecker.isError(result)) {
err = result;
}
} catch (_error) {
caughtError = _error;
err = caughtError;
}
if (err) {
if (typeof callback === "function") {
callback(err);
}
}
isAsynchronousMethod = introspectMethod.length === args.length;
completionCallback = args[args.length - 1];
if (!typeChecker.isFunction(completionCallback)) {
err = new Error('ambi was called without a completion callback');
throw err;
}
if (isAsynchronousMethod) {
fireMethod.apply(null, args);
} else {
try {
result = fireMethod.apply(null, args);
if (typeChecker.isError(result)) {
err = result;
}
} catch (_error) {
caughtError = _error;
err = caughtError;
}
if (err) {
if (typeof callback === "function") {
callback(err);
}
result = fireMethod.apply(null, args);
if (typeChecker.isError(result)) {
err = result;
completionCallback(err);
} else {
if (typeof callback === "function") {
callback(null, result);
}
completionCallback(null, result);
}
}
return err || result;
return null;
};
module.exports = ambi;
{
"name": "ambi",
"version": "2.0.0",
"version": "2.1.0",
"description": "Execute a function ambidextrously (normalizes the differences between synchronous and asynchronous functions). Useful for treating synchronous functions as asynchronous functions (like supporting both synchronous and asynchronous event definitions automatically).",

@@ -24,3 +24,3 @@ "homepage": "https://github.com/bevry/ambi",

"engines" : {
"node": ">=0.4"
"node": ">=0.8"
},

@@ -32,4 +32,5 @@ "dependencies": {

"coffee-script": "~1.6.2",
"joe": "~1.1.2",
"chai": "~1.5.0"
"joe": "~1.3.0",
"joe-reporter-console": "~1.2.0",
"chai": "~1.7.2"
},

@@ -36,0 +37,0 @@ "directories": {

@@ -1,2 +0,7 @@

# Ambi [![Build Status](https://secure.travis-ci.org/bevry/ambi.png?branch=master)](http://travis-ci.org/bevry/ambi)
# Ambi
[![Build Status](https://secure.travis-ci.org/bevry/ambi.png?branch=master)](http://travis-ci.org/bevry/ambi)
[![NPM version](https://badge.fury.io/js/ambi.png)](https://npmjs.org/package/ambi)
[![Flattr this project](https://raw.github.com/balupton/flattr-buttons/master/badge-89x18.gif)](http://flattr.com/thing/344188/balupton-on-Flattr)
Execute a function ambidextrously (normalizes the differences between synchronous and asynchronous functions).

@@ -22,28 +27,30 @@ Useful for treating synchronous functions as asynchronous functions (like supporting both synchronous and asynchronous event definitions automatically).

### Example
``` javascript
// Import
var ambi = require('ambi')
var result
var ambi = require('ambi');
var result;
// Sample methods
var syncMethod = function(x,y){
return x*y
}
return x*y;
};
var asyncMethod = function(x,y,next){
return setTimeout(function(){
next(null,x*y)
},0)
}
next(null,x*y);
},0);
};
// Call the synchronous function asynchronously
result = ambi(syncMethod, 5, 2, function(err,result){ // ambi adds support for this asynchronous callback automatically
console.log(err, result) // null, 10
})
console.log(result) // 10 - just like normal
console.log(err, result); // null, 10
});
console.log(result); // 10 - just like normal
// Call the asynchronous function asynchronously
result = ambi(asyncMethod, 5, 2, function(err,result){ // ambi doesn't do anything special here
console.log(err, result) // null, 10
})
console.log(result) // setTimeout - just like normal
console.log(err, result); // null, 10
});
console.log(result); // setTimeout - just like normal
```

@@ -53,3 +60,3 @@

## Process
### Notes

@@ -56,0 +63,0 @@ - Ambi accepts the arguments `(method, args...)`

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