How to use the underscore.isObject function in underscore

To help you get started, we’ve selected a few underscore 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 ethereum / web3.js / packages / web3-utils / src / utils.js View on Github external
var toHex = function (value, returnType) {
    /*jshint maxcomplexity: false */

    if (isAddress(value)) {
        return returnType ? 'address' : '0x'+ value.toLowerCase().replace(/^0x/i,'');
    }

    if (_.isBoolean(value)) {
        return returnType ? 'bool' : value ? '0x01' : '0x00';
    }

    if (Buffer.isBuffer(value)) {
        return '0x' + value.toString('hex');
    }

    if (_.isObject(value) && !isBigNumber(value) && !isBN(value)) {
        return returnType ? 'string' : utf8ToHex(JSON.stringify(value));
    }

    // if its a negative number, pass it through numberToHex
    if (_.isString(value)) {
        if (value.indexOf('-0x') === 0 || value.indexOf('-0X') === 0) {
            return returnType ? 'int256' : numberToHex(value);
        } else if(value.indexOf('0x') === 0 || value.indexOf('0X') === 0) {
            return returnType ? 'bytes' : value;
        } else if (!isFinite(value)) {
            return returnType ? 'string' : utf8ToHex(value);
        }
    }

    return returnType ? (value < 0 ? 'int256' : 'uint256') : numberToHex(value);
};
github shiki / kaiseki / lib / kaiseki.js View on Github external
request(this.serverUrl + this.mountPath + opts.url, reqOpts, function(err, res, body) {
      var isCountRequest = opts.params && !_.isUndefined(opts.params['count']) && !!opts.params.count;
      var success = !err && (res.statusCode === 200 || res.statusCode === 201);
      if (body !== '' && res && res.headers['content-type'] &&
        res.headers['content-type'].toLowerCase().indexOf('application/json') >= 0) {
        if (!_.isObject(body) && !_.isArray(body)) // just in case it's been parsed already
          body = JSON.parse(body);
        if (body.error) {
          success = false;
        } else if (body.results && _.isArray(body.results) && !isCountRequest) {
          // If this is a "count" request. Don't touch the body/result.
          body = body.results;
        }
      }
      opts.callback(err, res, body, success);
    });
  }
github Azure / azure-sdk-for-node / lib / services / serviceBus / lib / wnsservice.js View on Github external
self[sendName] = function () {
      // signature is (tags, [payload, ]+, [options], callback)
      var tags = Array.prototype.shift.apply(arguments);

      // Get arguments without the final callback to build payload
      var args = Array.prototype.slice.call(arguments, 0, arguments.length - 1);

      var options = {};
      if (arguments.length >= 3 && _.isObject(arguments[arguments.length - 2])) {
        options = arguments[arguments.length - 2];
      }

      var callback = arguments[arguments.length - 1];

      if (!_.isFunction(callback)) {
        throw new Error('The callback parameter must be the callback function.');
      }

      var type =  templateName.indexOf('Tile') === 0 ? 'tile' : 'toast';
      var payload = wns[createFunctionName].apply(wns, args);
      self.send(tags, payload, 'wns/' + type, options, callback);
    };
  };
github Foundry376 / Mailspring / app / src / registries / extension-registry.es6 View on Github external
validateExtension(extension, method) {
    if (!extension || Array.isArray(extension) || !_.isObject(extension)) {
      throw new Error(
        `ExtensionRegistry.${
          this.name
        }.${method} requires a valid extension object that implements one of the functions defined by ${
          this.name
        }Extension`
      );
    }
    if (!extension.name) {
      throw new Error(
        `ExtensionRegistry.${
          this.name
        }.${method} requires a \`name\` property defined on the extension object`
      );
    }
  }
github maryrosecook / code-lauren / src / copy-program-state.js View on Github external
return copyValue(o, []);
  } else if (visited.indexOf(o) !== -1) {
    return visited[visited.indexOf(o)];
  } else if (_.isString(o) || _.isNumber(o) || _.isBoolean(o) ||
             (_.isFunction(o) && !langUtil.isInternalStateBuiltin(o))) {
    return o;
  } else {
    visited.push(o);

    if (langUtil.isInternalStateBuiltin(o)) {
      return copyInternalStateBuiltin(o);
    } else if (langUtil.isLambda(o)) {
      return { bc: o.bc, parameters: o.parameters, closureEnv: copyEnv(o.closureEnv, visited) };
    } else if (_.isArray(o)) {
      return o.map(function() { return copyValue(o, visited); });
    } else if (_.isObject(o)) {
      return Object.keys(o)
        .reduce(function(c, k) {
          c[k] = copyValue(o[k], visited);
          return c;
        }, {});
    } else if (o !== undefined) {
      throw "Got value to copy that didn't match any cases: " + o;
    }
  }
};
github mulesoft / api-notebook / src / scripts / bootstrap / plugins / authentication / oauth1.js View on Github external
var contentType = _.find(_.pairs(data.headers), function (header) {
    return header[0].toLowerCase() === 'content-type';
  });

  if (!contentType) {
    contentType = data.headers['Content-Type'] = URL_ENCODED;
  } else {
    contentType = contentType[1];
  }

  if (contentType === URL_ENCODED) {
    if (_.isString(data.data)) {
      data.data = qs.parse(data.data);
    }

    if (_.isObject(data.data)) {
      var body = paramsToArray(data.data);
      data.data = arrayToParams(body);
      params.push.apply(params, body);
    }
  }

  var sortedParams = sortRequestParams(params);

  sortedParams.push(
    ['oauth_signature', encodeData(getSignature(sortedParams, data))]
  );

  return sortedParams;
};
github silentbalanceyh / vertx-ui / src / ux / value / Ux.Value.Safe.js View on Github external
const safeList = (data) => {
    if (U.isArray(data)) {
        return data;
    } else {
        if (data && U.isObject(data)) {
            const result = data.list;
            if (U.isArray(result)) {
                return result;
            }
        }
        return [];
    }
};
github node-opcua / node-opcua / packages / node-opcua-server / src / opcua_server.js View on Github external
const Factory = function Factory(engine) {
    assert(_.isObject(engine));
    this.engine = engine;
};
github SilentCicero / ethereumjs-accounts / index.js View on Github external
var isBigNumber = function(value){
    if(_.isUndefined(value) || !_.isObject(value))
        return false;

    return (value instanceof BigNumber) ? true : false;
};