How to use the comb.isFunction function in comb

To help you get started, we’ve selected a few comb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github doug-martin / super-request / index.js View on Github external
}
                    break;
                case "body":
                    val = expect[1];
                    if (comb.isHash(val)) {
                        //the body should be json
                        var json;
                        try {
                            json = comb.isString(body) ? JSON.parse(body.replace(/\\n/g, "")) : body;
                        } catch (e) {
                            throw new Error("Unable to parse " + body + " to json");
                        }
                        if (!comb.deepEqual(json, val)) {
                            throw new Error(['Expected', util.inspect(val), 'response body, got', util.inspect(json)].join(" ") + "\n" + expect[2]);
                        }
                    } else if (comb.isFunction(val)) {
                        return val(body);
                    } else if (comb.isRegExp(val)) {
                        if (!val.test(body)) {
                            throw new Error(['Expected body', util.inspect(body), 'to match', util.inspect(val)].join(" ") + "\n" + expect[2]);
                        }
                    } else if (!comb.deepEqual(body, val)) {
                        //just assert the body
                        throw new Error(['Expected', util.inspect(val), 'response body, got', util.inspect(body)].join(" ") + "\n" + expect[2]);
                    }

                    break;
                case "status":
                    if (res.statusCode !== expect[1])
                        throw new Error(["Expected response status code to be", expect[1], "got", res.statusCode].join(" ") + "\n" + expect[2]);
                    break;
github C2FO / patio / lib / plugins / association.js View on Github external
associate: function (type, name, options, filter) {
            if (comb.isFunction(options)) {
                filter = options;
                options = {};
            }
            this.__associations = this.__associations || {manyToMany: {}, oneToMany: {}, manyToOne: {}, oneToOne: {}};
            var assoc = new associations[type](comb.merge({model: name}, options), this.patio, filter);
            assoc.inject(this, name);
            this.__associations[type][name] = assoc;
            this.emit("associate", type, this);
            return this;
        },
github C2FO / hare / lib / rpc.js View on Github external
call: function (msg, opts, cb) {
            var queue = this.recieveQueue, rpcQueue = this.rpcQueue, requests = this.__requests;
            if (comb.isFunction(opts)) {
                cb = opts;
                opts = null;
            }
            opts = opts || {};
            return when(queue.queue, this.__subscribeHandler(), rpcQueue.queue).chain(function (q) {
                q = q[0];
                var ret = new Promise(),
                    correlationId = uuid.v4();
                requests[correlationId] = ret;
                rpcQueue.publish(msg, comb.merge({replyTo: q.name, correlationId: correlationId}, opts)).addErrback(ret.errback);
                return ret.promise();
            }).classic(cb);
        },
github doug-martin / super-request / index.js View on Github external
comb.hash.forEach(opts, function(val, key) {
                    if (comb.isFunction(val)) {
                        opts[key] = val();
                    }
                }, this);
github doug-martin / super-request / index.js View on Github external
module.exports = function (app) {
    if (comb.isFunction(app)) {
        app = http.createServer(app);
    }
    var ret = {};
    methods.forEach(function (method) {
        var name = 'delete' === method ? 'del' : method;
        method = method.toUpperCase();
        ret[name] = function (url) {
            return new Test(app, method, url);
        };
    });
    return ret;

};
github doug-martin / ssrs / lib / report.js View on Github external
["rs", "rc"].forEach(function (type) {
                var typeOpts = opts[type];
                for (var i in typeOpts) {
                    var properName = i.charAt(0).toUpperCase() + i.substr(1);
                    var funcName = "_get" + properName + "Query", f = this[funcName];
                    if (comb.isFunction(f, typeOpts[i])) {
                        f(queryOpts);
                    } else {
                        queryOpts[type + ":" + properName] = typeOpts[i];
                    }
                }
            }, this);
            for (var i in query) {
github C2FO / hare / lib / queue.js View on Github external
publish: function publish(message, options) {
            var queueName = this.queueName,
                defaultOptions = this.get("publishOptions"),
                ret;
            defaultOptions = comb.isFunction(defaultOptions) ? defaultOptions(options) : (defaultOptions || {});
            if (!this._defaultExchange) {
                if (this.__defaultExchangeP) {
                    return this.__defaultExchangeP.chain(function (exchange) {
                        exchange.publish(queueName, message, merge(defaultOptions, options));
                    });
                } else {
                    ret = this.__getDefaultExchange().chain(function (exchange) {
                        exchange.publish(queueName, message, merge(defaultOptions, options));
                    });
                }
            } else {
                ret = new Promise().callback();
                this._defaultExchange.publish(queueName, message, merge(defaultOptions, options));
            }
            return ret;
        },
github doug-martin / super-request / index.js View on Github external
expect: function (field, val, cb) {
            var self = this;
            var dummyObject = {};
            var v8Handler = Error.prepareStackTrace;
            Error.prepareStackTrace = function (dummyObject, v8StackTrace) {
                return v8StackTrace;
            };
            Error.captureStackTrace(dummyObject, self.expect);

            var stack = dummyObject.stack;
            Error.prepareStackTrace = v8Handler;
            var stack = "at (" + stack[0].getFileName() + ":" + stack[0].getLineNumber() + ":" + stack[0].getColumnNumber() + ")";

            var args = comb.argsToArray(arguments);
            cb = comb.isFunction(args[args.length - 1]) ? args.pop() : null;
            if (field === cb) {
                cb = null;
                args.push(cb);
            }
            if (args.length === 2 && ["cookie", "!cookie"].indexOf(field) === -1) {
                if (comb.isNumber(field)) {
                    this._expects.push(["status", field, stack]);
                    this._expects.push(["body", val, stack]);
                } else {
                    this._expects.push(["header", field, val, stack]);
                }
            } else if (args.length === 1) {
                this._expects.push([comb.isNumber(field) ? "status" : "body", field, stack]);
            } else {
                args.push(stack);
                this._expects.push(args);