node-wget-fetch
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "node-wget-fetch", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Ultra simple async retrieval of resources or remote files over http or https, an cli tool, and convenience wrapper of node-fetch.", | ||
@@ -5,0 +5,0 @@ "main": "wget-fetch.js", |
@@ -37,2 +37,13 @@ # node-wget-fetch | ||
- The **response type** will set _Fetch/Request_ **header** `'Content-Type'` as: | ||
- '`json`' = 'application/json; charset=utf-8' | ||
- '`text`' = 'application/x-www-form-urlencoded' | ||
- '`blob`' = 'application/octet' | ||
- '`buffer`' = 'application/octet' | ||
- '`header`' = 'text/plain' | ||
- '`object`' = 'application/json; charset=utf-8' | ||
- '`stream`' = 'application/octet' | ||
- '`array`' = 'application/octet' | ||
- '`converted`' = 'application/x-www-form-urlencoded' | ||
## Convenience Request Methods | ||
@@ -39,0 +50,0 @@ |
@@ -6,2 +6,13 @@ 'use strict'; | ||
let content_types = {}; | ||
content_types['json'] = 'application/json; charset=utf-8'; | ||
content_types['text'] = 'application/x-www-form-urlencoded'; | ||
content_types['blob'] = 'application/octet'; | ||
content_types['buffer'] = 'application/octet'; | ||
content_types['header'] = 'text/plain'; | ||
content_types['object'] = 'application/json; charset=utf-8'; | ||
content_types['stream'] = 'application/octet'; | ||
content_types['array'] = 'application/octet'; | ||
content_types['converted'] = 'application/x-www-form-urlencoded'; | ||
/** | ||
@@ -26,3 +37,3 @@ * Retrieval of resources or remote files over http or https by way of `node-fetch` | ||
* @param {Object} options Fetch/Request options | ||
* @return {Promise} Promise of `response body` of above **type** | ||
* @return {Promise} Promise of `response body` of above **type**, only if **status text** is `OK` | ||
*/ | ||
@@ -269,10 +280,12 @@ function fetching(url, action = '', options = {}) { | ||
* @param options optional `Fetch` options. | ||
* @returns A promise response body of given response action type. | ||
* @returns A promise response body of given response action type, only if **status text** is `OK` | ||
*/ | ||
function verbFuncBody(verb) { | ||
let method = verb.toUpperCase(); | ||
return function (uri, body, responseType = 'text', options = {}) { | ||
var params = options; | ||
return function (uri, body = null, responseType = 'text', options = {}) { | ||
let params = { headers: { 'Content-Type': null}}; | ||
params = Object.assign(params, options); | ||
params.method = method; | ||
params.action = responseType; | ||
params.headers['Content-Type'] = content_types[responseType] || 'application/x-www-form-urlencoded'; | ||
params.body = body; | ||
@@ -298,3 +311,3 @@ return fetching(uri, params); | ||
* @param options optional `Fetch` options. | ||
* @returns A promise response of headers. | ||
* @returns A promise response of headers, only if **status text** is `OK` | ||
*/ | ||
@@ -318,4 +331,4 @@ function verbFunc(verb) { | ||
* | ||
* @return {Promise} `Promise` info of completed file transfer: | ||
* - { filepath: string, fileSize: number, retrievedSizeMatch: boolean, headers: object} | ||
* @return {Promise} `Promise` **info** of completed file transfer: | ||
* - { filepath: string, fileSize: number, fileSizeMatch: boolean, headers: object}, only if **status text** is `OK` | ||
*/ | ||
@@ -340,3 +353,3 @@ function wget(url, folderFilename = './', options = {}) { | ||
* @return {Promise} `Promise` info of completed file transfer: | ||
* - { filepath: string, fileSize: number, retrievedSizeMatch: boolean, headers: object} | ||
* - { filepath: string, fileSize: number, retrievedSizeMatch: boolean, headers: object}, only if **status text** is `OK` | ||
*/ | ||
@@ -360,3 +373,3 @@ fetching.wget = wget; | ||
* @param options optional `Fetch` options. | ||
* @returns A promise response of headers. | ||
* @returns A promise response of headers, only if **status text** is `OK` | ||
*/ | ||
@@ -380,3 +393,3 @@ fetching.get = verbFunc('get'); | ||
* @param options optional `Fetch` options. | ||
* @returns A promise response of headers. | ||
* @returns A promise response of headers, only if **status text** is `OK` | ||
*/ | ||
@@ -400,3 +413,3 @@ fetching.head = verbFunc('head'); | ||
* @param options optional `Fetch` options. | ||
* @returns A promise response of headers. | ||
* @returns A promise response of headers, only if **status text** is `OK` | ||
*/ | ||
@@ -421,3 +434,3 @@ fetching.options = verbFunc('options'); | ||
* @param options optional `Fetch` options. | ||
* @returns A promise response body of given response action type. | ||
* @returns A promise response body of given response action type, only if **status text** is `OK` | ||
*/ | ||
@@ -442,3 +455,3 @@ fetching.post = verbFuncBody('post'); | ||
* @param options optional `Fetch` options. | ||
* @returns A promise response body of given response action type. | ||
* @returns A promise response body of given response action type, only if **status text** is `OK` | ||
*/ | ||
@@ -463,3 +476,3 @@ fetching.put = verbFuncBody('put'); | ||
* @param options optional `Fetch` options. | ||
* @returns A promise response body of given response action type. | ||
* @returns A promise response body of given response action type, only if **status text** is `OK` | ||
*/ | ||
@@ -484,3 +497,3 @@ fetching.patch = verbFuncBody('patch'); | ||
* @param options optional `Fetch` options. | ||
* @returns A promise response body of given response action type. | ||
* @returns A promise response body of given response action type, only if **status text** is `OK` | ||
*/ | ||
@@ -505,3 +518,3 @@ fetching.del = verbFuncBody('delete'); | ||
* @param options optional `Fetch` options. | ||
* @returns A promise response body of given response action type. | ||
* @returns A promise response body of given response action type, only if **status text** is `OK` | ||
*/ | ||
@@ -508,0 +521,0 @@ fetching['delete'] = verbFuncBody('delete'); |
27579
582
182