request-options
Advanced tools
Comparing version 1.0.0 to 2.0.0
21
index.js
@@ -7,21 +7,16 @@ 'use strict'; | ||
* @param {Object} [options] | ||
* @param {Object} [defaults] | ||
* @returns {*|{}} | ||
*/ | ||
module.exports = (options = {}, { | ||
json = true, | ||
gzip = true, | ||
timeout = 10000 | ||
} = {}) => { | ||
module.exports = (options = {}) => { | ||
if(!options || typeof options !== 'object') | ||
throw new Error('Additional options must be provided as JSON'); | ||
Object.assign( | ||
options, | ||
return Object.assign( | ||
{}, | ||
{ | ||
json: json, | ||
gzip: gzip, | ||
timeout: timeout | ||
} | ||
json: true, | ||
gzip: true, | ||
timeout: 10000 | ||
}, | ||
options | ||
); | ||
return options; | ||
}; |
{ | ||
"name": "request-options", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Default options object generator for the popular NodeJS package Request", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -6,3 +6,3 @@ # request-options | ||
Default options object generator written in ES6 for the popular NodeJS package Request, providing a generic set of request options | ||
for the [request](https://www.npmjs.com/package/request) package that can be augmented by providing [`options`](#options) or [`defaults`](#defaults) to overwrite. | ||
for the [request](https://www.npmjs.com/package/request) package that can be augmented or overwritten by providing [`options`](#options). | ||
@@ -16,6 +16,5 @@ ## Install | ||
## Usage | ||
### requestOptions( [options][, defaults] ) | ||
### requestOptions( [options] ) | ||
```js | ||
@param {Object} [options] | ||
@param {Object} [defaults] | ||
@returns {Object} | ||
@@ -34,3 +33,3 @@ ``` | ||
The defaults can be overwritten by providing your own `defaults` parameter object with the new values. Any additional values will be ignored, use the `options` object for your extended options. | ||
The defaults can be overwritten by providing your own properties in `options` with the new values. Any additional values will be ignored, use the `options` object for your extended options. | ||
@@ -89,4 +88,2 @@ ### Examples | ||
url: 'https://api.yoursite.com/endpoint' | ||
}; | ||
const defaults = { | ||
gzip: false, | ||
@@ -100,3 +97,3 @@ timeout: 20000 | ||
request(requestOptions(options, defaults), responseHandler); | ||
request(requestOptions(options), responseHandler); | ||
@@ -112,3 +109,3 @@ // requestOptions => { | ||
Notice how the default json value is still present and left unchanged | ||
Notice how the default property `json` is still present and the value left unchanged | ||
@@ -115,0 +112,0 @@ ## Tests |
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
38305
12
20
120