react-hooks-library
Advanced tools
Comparing version 0.1.2 to 0.1.4
@@ -1,11 +0,10 @@ | ||
import { axiosRequest, axios } from '../src/request' | ||
import { axiosRequest } from '../src/request' | ||
// tslint:disable-next-line: export-name | ||
export const request = axiosRequest<[]>({ | ||
handleResponse: res => { | ||
return res.data | ||
export const request = axiosRequest({ | ||
handleResponse: response => { | ||
return response.data | ||
}, | ||
catchErrors: err => { | ||
throw err | ||
catchErrors: error => { | ||
throw error | ||
}, | ||
}) |
import axios, { AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios'; | ||
export interface IAaxiosHandles<Response> { | ||
handleResponse?<Data>(res: AxiosResponse<Response>, ...rest: any[]): Data | Response; | ||
export declare type IHandleResponse<P, Data = P> = (res: AxiosResponse<Data>, ...rest: any[]) => Data; | ||
export interface IAaxiosHandles<ResponseData> { | ||
handleResponse: IHandleResponse<ResponseData>; | ||
catchErrors?(err: AxiosError): void; | ||
} | ||
export declare function axiosRequest<IResponse>(handles: IAaxiosHandles<IResponse>): { | ||
request: (method: string) => (userConfig: AxiosRequestConfig, ...rest: any[]) => (config: AxiosRequestConfig) => Promise<void | {} | IResponse>; | ||
get: (userConfig: AxiosRequestConfig, ...rest: any[]) => (config: AxiosRequestConfig) => Promise<void | {} | IResponse>; | ||
post: (userConfig: AxiosRequestConfig, ...rest: any[]) => (config: AxiosRequestConfig) => Promise<void | {} | IResponse>; | ||
put: (userConfig: AxiosRequestConfig, ...rest: any[]) => (config: AxiosRequestConfig) => Promise<void | {} | IResponse>; | ||
patch: (userConfig: AxiosRequestConfig, ...rest: any[]) => (config: AxiosRequestConfig) => Promise<void | {} | IResponse>; | ||
delete: (userConfig: AxiosRequestConfig, ...rest: any[]) => (config: AxiosRequestConfig) => Promise<void | {} | IResponse>; | ||
export declare function axiosRequest<ResponseData>(handles: IAaxiosHandles<ResponseData>): { | ||
request: (method: string) => <Data>(userConfig: AxiosRequestConfig, ...rest: any[]) => (config: AxiosRequestConfig) => Promise<void | Data>; | ||
get: <Data>(userConfig: AxiosRequestConfig, ...rest: any[]) => (config: AxiosRequestConfig) => Promise<void | Data>; | ||
post: <Data>(userConfig: AxiosRequestConfig, ...rest: any[]) => (config: AxiosRequestConfig) => Promise<void | Data>; | ||
put: <Data>(userConfig: AxiosRequestConfig, ...rest: any[]) => (config: AxiosRequestConfig) => Promise<void | Data>; | ||
patch: <Data>(userConfig: AxiosRequestConfig, ...rest: any[]) => (config: AxiosRequestConfig) => Promise<void | Data>; | ||
delete: <Data>(userConfig: AxiosRequestConfig, ...rest: any[]) => (config: AxiosRequestConfig) => Promise<void | Data>; | ||
}; | ||
export { axios }; |
@@ -10,3 +10,5 @@ import * as tslib_1 from "tslib"; | ||
return handles.handleResponse | ||
? handles.handleResponse.apply(undefined, [response].concat(rest)) | ||
? handles.handleResponse.apply(undefined, [ | ||
response | ||
].concat(rest)) | ||
: response.data; | ||
@@ -28,3 +30,5 @@ } | ||
.request(tslib_1.__assign({}, userConfig, config, { method: method })) | ||
.then(function (response) { return handleResponse.apply(undefined, [response].concat(rest)); }) | ||
.then(function (response) { | ||
return handleResponse.apply(undefined, [response].concat(rest)); | ||
}) | ||
.catch(catchErrors)]; | ||
@@ -31,0 +35,0 @@ }); |
{ | ||
"name": "react-hooks-library", | ||
"version": "0.1.2", | ||
"version": "0.1.4", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "scripts": { |
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
19865
491