goferito / node-bing-api

Node.js module for the Bing Search API (Cognitive Services)
MIT License
56 stars 28 forks source link

Making callbacks the last parameter + jsbeautifer #10

Closed jemartti closed 9 years ago

jemartti commented 9 years ago

Standard node.js best practices are to have the callback be the last parameter. This is especially important when using modified control flow (as is used by co or koa).

When using koa, having the final parameter be the callback allows us to promisify the library:

global.Promise = require('bluebird').Promise;
var Bing = Promise.promisifyAll(require('node-bing-api')({
    'accKey': config.bingAccKey
}));

This then lets us yield the function call:

var results = yield Bing.imagesAsync(args.query, {'adult': 'Moderate'});
var body = results[1];

As this is a fairly significant breaking change, this will likely have to go out as a 2.0.0 release.

I also added a jsbeautify grunt task to help with code readability and consistency.

goferito commented 9 years ago

Thanks a lot. Sorry for the delay merging it.