How to use the methods.push function in methods

To help you get started, we’ve selected a few methods 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 concur / skipper / node_modules / superagent / lib / node / index.js View on Github external
if ('0' === res.headers['content-length']) {
    // We know that the body is empty (unfortunately, this check does not cover chunked encoding)
    return false;
  }

  // console.log(res);
  return /^\s*(?:deflate|gzip)\s*$/.test(res.headers['content-encoding']);
};

// generate HTTP verb methods
if (methods.indexOf('del') == -1) {
  // create a copy so we don't cause conflicts with
  // other packages using the methods package and
  // npm 3.x
  methods = methods.slice(0);
  methods.push('del');
}
methods.forEach(method => {
  const name = method;
  method = 'del' == method ? 'delete' : method;

  method = method.toUpperCase();
  request[name] = (url, data, fn) => {
    const req = request(method, url);
    if ('function' == typeof data) (fn = data), (data = null);
    if (data) {
      if (method === 'GET' || method === 'HEAD') {
        req.query(data);
      } else {
        req.send(data);
      }
    }
github mendersoftware / gui / node_modules / superagent / lib / node / index.js View on Github external
if ('0' === res.headers['content-length']) {
    // We know that the body is empty (unfortunately, this check does not cover chunked encoding)
    return false;
  }

  // console.log(res);
  return /^\s*(?:deflate|gzip)\s*$/.test(res.headers['content-encoding']);
};

// generate HTTP verb methods
if (methods.indexOf('del') == -1) {
  // create a copy so we don't cause conflicts with
  // other packages using the methods package and
  // npm 3.x
  methods = methods.slice(0);
  methods.push('del');
}
methods.forEach(method => {
  const name = method;
  method = 'del' == method ? 'delete' : method;

  method = method.toUpperCase();
  request[name] = (url, data, fn) => {
    const req = request(method, url);
    if ('function' == typeof data) (fn = data), (data = null);
    if (data) {
      if (method === 'GET' || method === 'HEAD') {
        req.query(data);
      } else {
        req.send(data);
      }
    }
github AntSwordProject / antSword / node_modules / superagent / lib / node / index.js View on Github external
if ('0' === res.headers['content-length']) {
    // We know that the body is empty (unfortunately, this check does not cover chunked encoding)
    return false;
  }

  // console.log(res);
  return /^\s*(?:deflate|gzip)\s*$/.test(res.headers['content-encoding']);
};

// generate HTTP verb methods
if (methods.indexOf('del') == -1) {
  // create a copy so we don't cause conflicts with
  // other packages using the methods package and
  // npm 3.x
  methods = methods.slice(0);
  methods.push('del');
}
methods.forEach(method => {
  const name = method;
  method = 'del' == method ? 'delete' : method;

  method = method.toUpperCase();
  request[name] = (url, data, fn) => {
    const req = request(method, url);
    if ('function' == typeof data) (fn = data), (data = null);
    if (data) {
      if (method === 'GET' || method === 'HEAD') {
        req.query(data);
      } else {
        req.send(data);
      }
    }
github MindFreakers / cdn / node_modules / superagent / lib / node / index.js View on Github external
return /^\s*(?:deflate|gzip)\s*$/.test(res.headers['content-encoding']);
};

/**
 * Expose `Request`.
 */

exports.Request = Request;

// generate HTTP verb methods
if (methods.indexOf('del') == -1) {
  // create a copy so we don't cause conflicts with
  // other packages using the methods package and
  // npm 3.x
  methods = methods.slice(0);
  methods.push('del');
}
methods.forEach(function(method){
  var name = method;
  method = 'del' == method ? 'delete' : method;

  method = method.toUpperCase();
  request[name] = function(url, data, fn){
    var req = request(method, url);
    if ('function' == typeof data) fn = data, data = null;
    if (data) req.send(data);
    fn && req.end(fn);
    return req;
  };
});

/**
github visionmedia / superagent / lib / node / index.js View on Github external
}
  return this;
};

Request.prototype.trustLocalhost = function(toggle) {
    this._trustLocalhost = toggle === undefined ? true : toggle;
    return this;
};

// generate HTTP verb methods
if (methods.indexOf('del') == -1) {
  // create a copy so we don't cause conflicts with
  // other packages using the methods package and
  // npm 3.x
  methods = methods.slice(0);
  methods.push('del');
}
methods.forEach(method => {
  const name = method;
  method = 'del' == method ? 'delete' : method;

  method = method.toUpperCase();
  request[name] = (url, data, fn) => {
    const req = request(method, url);
    if ('function' == typeof data) (fn = data), (data = null);
    if (data) {
      if (method === 'GET' || method === 'HEAD') {
        req.query(data);
      } else {
        req.send(data);
      }
    }
github ivpusic / koa-routing / lib / route.js View on Github external
if ((ret = this._nesteds[j].match(request))) {
        return ret;
      }
    }
  }

  // route is not matched
  return null;
};

/**
 * Define supported HTTP methods for Route object
 * and all failback method
 */
if (methods[methods.length - 1] !== 'all') {
  methods.push('all');
}

methods.forEach(function (METHOD) {
  Route.prototype[METHOD] = function () {
    var cbs = Array.prototype.slice.apply(arguments),
      that = this;

    cbs.forEach(function (cb) {
      util.isGenerator(cb, that);
    });

    this.handlers[METHOD.toUpperCase()] = cbs;
    return this;
  };
});
github visionmedia / superagent / src / node / index.js View on Github external
return this;
};

Request.prototype.trustLocalhost = function(toggle) {
  this._trustLocalhost = toggle === undefined ? true : toggle;
  return this;
};

// generate HTTP verb methods
if (!methods.includes('del')) {
  // create a copy so we don't cause conflicts with
  // other packages using the methods package and
  // npm 3.x
  methods = methods.slice(0);
  methods.push('del');
}

methods.forEach(method => {
  const name = method;
  method = method === 'del' ? 'delete' : method;

  method = method.toUpperCase();
  request[name] = (url, data, fn) => {
    const req = request(method, url);
    if (typeof data === 'function') {
      fn = data;
      data = null;
    }

    if (data) {
      if (method === 'GET' || method === 'HEAD') {
github hsiW / WishBot / node_modules / discord.js / node_modules / superagent / lib / node / index.js View on Github external
// url first
  if (1 == arguments.length) {
    return new Request('GET', method);
  }

  return new Request(method, url);
}

// generate HTTP verb methods
if (methods.indexOf('del') == -1) {
  // create a copy so we don't cause conflicts with
  // other packages using the methods package and
  // npm 3.x
  methods = methods.slice(0);
  methods.push('del');
}
methods.forEach(function(method){
  var name = method;
  method = 'del' == method ? 'delete' : method;

  method = method.toUpperCase();
  request[name] = function(url, data, fn){
    var req = request(method, url);
    if ('function' == typeof data) fn = data, data = null;
    if (data) req.send(data);
    fn && req.end(fn);
    return req;
  };
});

/**
github googleapis / cloud-trace-nodejs / test / test-unpatch.ts View on Github external
it('should wrap/unwrap express on start/stop', function() {
    var express = require('./plugins/fixtures/express4');
    var patchedMethods = require('methods');
    patchedMethods.push('use', 'route', 'param', 'all');
    patchedMethods.forEach(function(method) {
      wrapTest(express.application, method);
    });
  });
github koenpunt / superagent-use / index.js View on Github external
var _superagent = require('superagent');
var methods = require('methods');
var assign = require('object-assign');

var uses = [];

var superagent = assign({}, _superagent);

superagent.use = function(fn) {
  uses.push(fn);
  return this;
};

methods.indexOf('del') == -1 && methods.push('del');
methods.forEach(function(method) {
  superagent[method] = function() {
    var request = _superagent[method].apply(superagent, arguments);
    uses.forEach(function(use) {
      request = request.use(use);
    });
    return request;
  };
});

module.exports = superagent;