From 9c9918b1108d7dc84bcfa5a13fd111148431d36c Mon Sep 17 00:00:00 2001 From: Kremlin Date: Sun, 24 May 2015 01:01:33 +0100 Subject: [PATCH 1/2] fix the way http verbs are defined I changed the way they are defined so that they are more IDE-friendly. The way they were defined, an IDE wouldn't easily recognize them and would often show 'request.get' or 'request.post' etc as a possible error. Ctrl+clicking on the 'get' function wouldn't take you to where it was defined. Now it will! --- index.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 8bc39545c..6296fea27 100755 --- a/index.js +++ b/index.js @@ -56,16 +56,23 @@ function request (uri, options, callback) { return new request.Request(params) } -var verbs = ['get', 'head', 'post', 'put', 'patch', 'del'] - -verbs.forEach(function(verb) { - var method = verb === 'del' ? 'DELETE' : verb.toUpperCase() - request[verb] = function (uri, options, callback) { - var params = initParams(uri, options, callback) - params.method = method - return request(params, params.callback) +(function() { + var verbFunc = function(verb) { + var method = verb === 'del' ? 'DELETE' : verb.toUpperCase() + return function (uri, options, callback) { + var params = initParams(uri, options, callback) + params.method = method + return request(params, params.callback) + } } -}) + + request.get = verbFunc('get') + request.head = verbFunc('head') + request.post = verbFunc('post') + request.put = verbFunc('put') + request.patch = verbFunc('patch') + request.del = verbFunc('del') +})() request.jar = function (store) { return cookies.jar(store) From 20e9b578de0fe92195606d1be6307048bf157af0 Mon Sep 17 00:00:00 2001 From: simov Date: Mon, 25 May 2015 18:22:36 +0300 Subject: [PATCH 2/2] Add comment about pleasing intellisense IDEs --- index.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 6296fea27..5872824c8 100755 --- a/index.js +++ b/index.js @@ -56,23 +56,22 @@ function request (uri, options, callback) { return new request.Request(params) } -(function() { - var verbFunc = function(verb) { - var method = verb === 'del' ? 'DELETE' : verb.toUpperCase() - return function (uri, options, callback) { - var params = initParams(uri, options, callback) - params.method = method - return request(params, params.callback) - } +function verbFunc (verb) { + var method = verb === 'del' ? 'DELETE' : verb.toUpperCase() + return function (uri, options, callback) { + var params = initParams(uri, options, callback) + params.method = method + return request(params, params.callback) } +} - request.get = verbFunc('get') - request.head = verbFunc('head') - request.post = verbFunc('post') - request.put = verbFunc('put') - request.patch = verbFunc('patch') - request.del = verbFunc('del') -})() +// define like this to please codeintel/intellisense IDEs +request.get = verbFunc('get') +request.head = verbFunc('head') +request.post = verbFunc('post') +request.put = verbFunc('put') +request.patch = verbFunc('patch') +request.del = verbFunc('del') request.jar = function (store) { return cookies.jar(store)