Comparing version 0.3.4 to 0.4.0
@@ -61,3 +61,10 @@ 'use strict'; | ||
reqOptions.controller.abort = function () { | ||
req.abort(); | ||
var err = new Error('Aborted'); | ||
err.name = 'aborted'; | ||
deferred.reject(err); | ||
}; | ||
return deferred.promise; | ||
} |
@@ -13,4 +13,5 @@ 'use strict' | ||
* - Returns a promise, resolving to an object containing the data, node response and original request. | ||
* - If data was supplied, sets a `content-length` header if not already present | ||
* - Automatically selects `http` or `https` transport depending on the input URL | ||
* - If data was supplied, sets a `content-length` header if not already present. | ||
* - Automatically selects `http` or `https` transport depending on the input URL. | ||
* - Cancellable (which `fetch` is not). | ||
* | ||
@@ -31,10 +32,11 @@ * @module req-then | ||
/** | ||
* Returns a promise for the response. | ||
* @param {string|object} - Target url string or a standard node.js http request options object. | ||
* @param [data] {*} - Data to send with the request. | ||
* @returns {external:Promise} | ||
* @resolve {object} - `res` will be the node response object, `data` will be the data, `req` the original request. | ||
* @reject {Error} | ||
* @alias module:req-then | ||
*/ | ||
* Returns a promise for the response. | ||
* @param {string|object} - Target url string or a standard node.js http request options object. | ||
* @param [reqOptions.controller] {object} - If supplied, an `.abort()` method will be created on it which, if invoked, will cancel the request. Cancelling will cause the returned promise to reject with an `'aborted'` error. | ||
* @param [data] {*} - Data to send with the request. | ||
* @returns {external:Promise} | ||
* @resolve {object} - `res` will be the node response object, `data` will be the data, `req` the original request. | ||
* @reject {Error} - If aborted, the `name` property of the error will be `aborted`. | ||
* @alias module:req-then | ||
*/ | ||
function request (reqOptions, data) { | ||
@@ -91,3 +93,10 @@ if (!reqOptions) return Promise.reject(Error('need a URL or request options object')) | ||
reqOptions.controller.abort = function () { | ||
req.abort() | ||
const err = new Error('Aborted') | ||
err.name = 'aborted' | ||
deferred.reject(err) | ||
} | ||
return deferred.promise | ||
} |
{ | ||
"name": "req-then", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "0.3.4", | ||
"version": "0.4.0", | ||
"description": "Simple http(s) request function, returning a promise. ", | ||
@@ -35,9 +35,9 @@ "repository": "https://github.com/75lb/req-then", | ||
"feature-detect-es6": "^1.3.1", | ||
"lodash.pick": "^4.2.1", | ||
"typical": "^2.4.2" | ||
"lodash.pick": "^4.4.0", | ||
"typical": "^2.5.0" | ||
}, | ||
"devDependencies": { | ||
"babel-preset-es2015": "^6.13.2", | ||
"jsdoc-to-markdown": "^1.3.6" | ||
"jsdoc-to-markdown": "^2.0.0-alpha.11" | ||
} | ||
} |
@@ -9,7 +9,8 @@ [![view on npm](http://img.shields.io/npm/v/req-then.svg)](https://www.npmjs.org/package/req-then) | ||
## req-then | ||
Wraps the built-in node `request` function with a few extras: | ||
Wraps node's built-in http(s) `request` function with a few extras: | ||
- Returns a promise, resolving to an object containing the data, node response and original request. | ||
- If data was supplied, sets a `content-length` header if not already present | ||
- Automatically selects `http` or `https` transport depending on the input URL | ||
- If data was supplied, sets a `content-length` header if not already present. | ||
- Automatically selects `http` or `https` transport depending on the input URL. | ||
- Cancellable (which `fetch` is not). | ||
@@ -34,3 +35,3 @@ **Example** | ||
**Resolve**: <code>object</code> - `res` will be the node response object, `data` will be the data, `req` the original request. | ||
**Reject**: <code>Error</code> | ||
**Reject**: <code>Error</code> - If aborted, the `name` property of the error will be `aborted`. | ||
@@ -40,2 +41,3 @@ | Param | Type | Description | | ||
| reqOptions | <code>string</code> | <code>object</code> | Target url string or a standard node.js http request options object. | | ||
| [reqOptions.controller] | <code>object</code> | If supplied, an `.abort()` method will be created on it which, if invoked, will cancel the request. Cancelling will cause the returned promise to reject with an `'aborted'` error. | | ||
| [data] | <code>\*</code> | Data to send with the request. | | ||
@@ -42,0 +44,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11663
205
46
Updatedlodash.pick@^4.4.0
Updatedtypical@^2.5.0