Comparing version 3.5.1 to 3.6.0
@@ -10,7 +10,7 @@ const {URL} = require('url') | ||
* @property {string} [method=GET] - Request method ('GET', 'POST', etc.) | ||
* @property {string} [data] - Data to send as request body (phin may attempt to convert this data to a string if it isn't already) | ||
* @property {string|Buffer|object} [data] - Data to send as request body (phin may attempt to convert this data to a string if it isn't already) | ||
* @property {Object} [form] - Object to send as form data (sets 'Content-Type' and 'Content-Length' headers, as well as request body) (overwrites 'data' option if present) | ||
* @property {Object} [headers={}] - Request headers | ||
* @property {Object} [core={}] - Custom core HTTP options | ||
* @property {string} [parse=none] - Response parsing. Errors will be given if the response can't be parsed. ('none', 'json') | ||
* @property {string} [parse=none] - Response parsing. Errors will be given if the response can't be parsed. 'none' returns body as a `Buffer`, 'json' attempts to parse the body as JSON, and 'string' attempts to parse the body as a string | ||
* @property {boolean} [followRedirects=false] - Enable HTTP redirect following | ||
@@ -75,8 +75,16 @@ * @property {boolean} [stream=false] - Enable streaming of response. (Removes body property) | ||
if (opts.parse && opts.parse === 'json') { | ||
res.coreRes.body = await res.json() | ||
if (opts.parse) { | ||
if (opts.parse === 'json') { | ||
res.coreRes.body = await res.json() | ||
return res.coreRes | ||
} | ||
else if (opts.parse === 'string') { | ||
res.coreRes.body = res.coreRes.body.toString() | ||
return res.coreRes | ||
return res.coreRes | ||
} | ||
} | ||
else return res.coreRes | ||
return res.coreRes | ||
} | ||
@@ -83,0 +91,0 @@ } |
{ | ||
"name": "phin", | ||
"version": "3.5.1", | ||
"version": "3.6.0", | ||
"description": "The ultra-lightweight Node.js HTTP client", | ||
@@ -5,0 +5,0 @@ "main": "lib/phin.js", |
// Default Options feature is not supported because it's basically impossible to write strongly-typed definitions for it. | ||
import * as http from 'http' | ||
import { URL } from 'url'; | ||
@@ -19,32 +20,35 @@ interface IOptionsBase { | ||
// Form and data property has been written this way so they're mutually exclusive. | ||
type IWithData<T extends {}> = T & { | ||
data: { | ||
toString(): string | ||
} | ||
} | ||
type IWithForm<T extends {}> = T & { | ||
form: { | ||
[index: string]: string | ||
} | ||
} | ||
declare function phin<T>(options: | ||
phin.IJSONResponseOptions | | ||
IWithData<phin.IJSONResponseOptions> | | ||
IWithForm<phin.IJSONResponseOptions>): Promise<phin.IJSONResponse<T>> | ||
phin.IWithData<phin.IJSONResponseOptions> | | ||
phin.IWithForm<phin.IJSONResponseOptions>): Promise<phin.IJSONResponse<T>> | ||
declare function phin(options: | ||
phin.IStringResponseOptions | | ||
IWithData<phin.IStringResponseOptions> | | ||
IWithForm<phin.IStringResponseOptions>): Promise<phin.IStringResponse> | ||
declare function phin(options: | ||
phin.IStreamResponseOptions | | ||
IWithData<phin.IStreamResponseOptions> | | ||
IWithForm<phin.IStreamResponseOptions>): Promise<phin.IStreamResponse> | ||
phin.IWithData<phin.IStreamResponseOptions> | | ||
phin.IWithForm<phin.IStreamResponseOptions>): Promise<phin.IStreamResponse> | ||
declare function phin(options: | ||
phin.IOptions | | ||
IWithData<phin.IOptions> | | ||
IWithForm<phin.IOptions> | | ||
phin.IWithData<phin.IOptions> | | ||
phin.IWithForm<phin.IOptions> | | ||
string): Promise<phin.IResponse> | ||
declare namespace phin { | ||
// Form and data property has been written this way so they're mutually exclusive. | ||
export type IWithData<T extends IOptionsBase> = T & { | ||
data: string | Buffer | object; | ||
} | ||
export type IWithForm<T extends IOptionsBase> = T & { | ||
form: { | ||
[index: string]: string | ||
} | ||
} | ||
export interface IJSONResponseOptions extends IOptionsBase { | ||
@@ -54,2 +58,6 @@ parse: 'json' | ||
export interface IStringResponseOptions extends IOptionsBase { | ||
parse: 'string'; | ||
} | ||
export interface IStreamResponseOptions extends IOptionsBase { | ||
@@ -67,2 +75,6 @@ stream: true | ||
export interface IStringResponse extends http.IncomingMessage { | ||
body: string; | ||
} | ||
export interface IStreamResponse extends http.IncomingMessage { | ||
@@ -73,3 +85,3 @@ stream: http.IncomingMessage | ||
export interface IResponse extends http.IncomingMessage { | ||
body: string | ||
body: Buffer; | ||
} | ||
@@ -93,2 +105,9 @@ | ||
options: | ||
IStringResponseOptions | | ||
IWithData<IStringResponseOptions> | | ||
IWithForm<IStringResponseOptions>, | ||
callback: IErrorCallback | ICallback<IStringResponse>): void | ||
export function unpromisified( | ||
options: | ||
IStreamResponseOptions | | ||
@@ -95,0 +114,0 @@ IWithData<IStreamResponseOptions> | |
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
13052
193