How to use the comb.isHash 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
'Expected "', expect[1], '" of "' + val, '", got "', headers[header], '"'
                                    ].join("") + "\n" + expect[3]);
                                }
                            } else if (!comb.deepEqual(headers[header.toLowerCase()], val)) {
                                throw new Error([
                                    'Expected "', expect[1], '" of "' + val, '", got "', headers[header], '"'
                                ].join("") + "\n" + expect[3]);
                            }
                        }
                    } else {
                        throw new Error('Expected "' + expect[1] + '" header field' + "\n" + expect[3]);
                    }
                    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]);
                        }
github doug-martin / super-request / index.js View on Github external
comb.async.array(this._expects).forEach(function (expect) {
                switch (expect[0]) {
                case "cookie":
                    //testing for cookies
                    var key = expect[1], val = expect[2], cookie = getCookie(key, this._jar, this._baseUrl);
                    if (comb.isUndefined(cookie)) {
                        throw new Error("expected cookie " + key + " to be present");
                    }
                    if (val) {
                        if (comb.isHash(val) && !comb.deepEqual(cookie, val)) {
                            throw new Error("expected cookie " + key + " to equal " + JSON.stringify(val) + "\n" + expect[3]);
                        } else if (cookie.value === val) {
                            throw new Error("expected cookie " + key + " value to equal " + val);
                        }
                    }
                    break;
                case "!cookie":
                    //testing for cookies
                    key = expect[1];
                    if (!comb.isUndefinedOrNull(getCookie(key, this._jar, this._baseUrl))) {
                        throw new Error("expected cookie " + key + " to be null or undefined " + "\n" + expect[2]);
                    }
                    break;
                case "header":
                    //it is a header test
                    var header = expect[1].toLowerCase();
github C2FO / hare / lib / exchange.js View on Github external
publish: function (routingKey, message, opts) {
            var argLength = arguments.length;
            if (argLength === 1) {
                message = routingKey;
                routingKey = this.queueName || this.get("routingKey") || '';
                opts = null;
            } else if (argLength === 2 && !comb.isString(routingKey) && comb.isHash(message)) {
                opts = message;
                message = routingKey;
                routingKey = this.queueName || this.get("routingKey") || '';
            }
            return this._exchange.exchange.chain(function (exchange) {
                LOGGER.debug("publishing to %s %4j", [routingKey, message]);
                var ret = new Promise();
                exchange.publish(routingKey, message, opts).addCallback(ret.callback.bind(ret)).addErrback(ret.errback.bind(ret));
                return ret;
            }.bind(this));
        }
    }
github C2FO / patio / lib / database / query.js View on Github external
this[n] = function (arg1, arg2) {
                    var ret;
                    try {
                        if (n === "transaction") {
                            if (comb.isHash(arg1) && arg1.isolated) {
                                return this.__enqueueTransaction(arg1, arg2);
                            } else {
                                //if its a transaction with no options then we just create a promise from what ever is returned
                                if (isFunction(arg1)) {
                                    ret = resolveOrPromisfyFunction(arg1, this, this);
                                } else {
                                    if (this.supportsSavepoints && arg1.savepoint) {
                                        //if we support save points there is a save point option then we
                                        //use __transaction again with the previous connection
                                        ret = this.__transaction(conn, arg1, arg2);
                                    } else {
                                        //other wise use the function passed in to get the returned promise
                                        ret = resolveOrPromisfyFunction(arg2, this, this);
                                    }
                                }
                            }
github C2FO / patio / lib / database / schema.js View on Github external
dropView: function (names, opts) {
            if (isArray(names)) {
                opts = opts || {};
                var self = this;
                return asyncArray(names).forEach(function (name) {
                    return self.executeDdl(self.__dropViewSql(name, opts)).chain(function () {
                        self.removeCachedSchema(name);
                    });
                }, null, 1).chain(function () {
                    return null;
                });
            } else {
                var args = argsToArray(arguments);
                if (comb.isHash(args[args.length - 1])) {
                    opts = args.pop();
                }
                return this.dropView(args.filter(function (t) {
                    return isString(t) || isInstanceOf(t, Identifier, QualifiedIdentifier);
                }), opts);

            }
        },