// Generated by CoffeeScript 1.6.3
var extractOpts, typeChecker;

typeChecker = require('typechecker');

extractOpts = {
  extractOpts: function(opts, next, config) {
    return extractOpts.extractOptsAndCallback(opts, next, config);
  },
  extractOptsAndCallback: function(opts, next, config) {
    var completionCallbackName, _i, _len, _ref;
    if (config == null) {
      config = {};
    }
    if ((config.completionCallbackNames != null) === false) {
      config.completionCallbackNames = ['next'];
    } else if (typeChecker.isArray(config.completionCallbackNames) === false) {
      config.completionCallbackNames = [config.completionCallbackNames];
    }
    if (typeChecker.isFunction(opts) && (next != null) === false) {
      next = opts;
      opts = {};
    } else {
      opts || (opts = {});
    }
    if (!next) {
      _ref = config.completionCallbackNames;
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        completionCallbackName = _ref[_i];
        next = opts[completionCallbackName];
        delete opts[completionCallbackName];
        if (next) {
          break;
        }
      }
    }
    next || (next = null);
    return [opts, next];
  }
};

module.exports = extractOpts;
