fetch-sveltekit
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -19,3 +19,3 @@ export declare const methodeFetch: () => { | ||
*/ | ||
export declare const configRequest: (method: string, header: HeadersInit, data?: any) => RequestInit; | ||
export declare const configRequest: (method: string, header: HeadersInit, data?: any, credit?: boolean, cors?: boolean, stringify?: boolean) => RequestInit; | ||
/** | ||
@@ -29,3 +29,3 @@ * fonction qui créer un request universel qui sera déterminé par les parametre | ||
*/ | ||
export declare const callApiJson: <T>(url: string, method: string, data?: any, header?: HeadersInit) => Promise<T>; | ||
export declare const callApiJson: <T>(url: string, method: string, data?: any, header?: HeadersInit, credit?: boolean, cors?: boolean, stringify?: boolean) => Promise<T>; | ||
/** | ||
@@ -39,2 +39,2 @@ * fonction qui créer un request universel qui sera déterminé par les parametre | ||
*/ | ||
export declare const callApi: (url: string, method: string, data?: any, header?: HeadersInit) => Promise<any>; | ||
export declare const callApi: (url: string, method: string, data?: any, header?: HeadersInit, credit?: boolean, cors?: boolean, stringify?: boolean) => Promise<any>; |
@@ -31,18 +31,117 @@ "use strict"; | ||
*/ | ||
const configRequest = (method, header, data) => { | ||
const configNotBody = { | ||
method: method, | ||
credentials: 'include', | ||
withCredentials: true, | ||
headers: header, | ||
mode: 'cors', | ||
}; | ||
const configBody = { | ||
method: method, | ||
credentials: 'include', | ||
withCredentials: true, | ||
headers: header, | ||
mode: 'cors', | ||
body: JSON.stringify(data), | ||
}; | ||
const configRequest = (method, header, data, credit = true, cors = true, stringify = true) => { | ||
let configNotBody = {}; | ||
let configBody = {}; | ||
if (credit && cors && stringify) { | ||
configNotBody = { | ||
method: method, | ||
credentials: 'include', | ||
withCredentials: true, | ||
headers: header, | ||
mode: 'cors', | ||
}; | ||
configBody = { | ||
method: method, | ||
credentials: 'include', | ||
withCredentials: true, | ||
headers: header, | ||
mode: 'cors', | ||
body: JSON.stringify(data), | ||
}; | ||
} | ||
else if (credit && cors) { | ||
configNotBody = { | ||
method: method, | ||
headers: header, | ||
credentials: 'include', | ||
withCredentials: true, | ||
mode: 'cors', | ||
}; | ||
configBody = { | ||
method: method, | ||
headers: header, | ||
mode: 'cors', | ||
credentials: 'include', | ||
withCredentials: true, | ||
body: data, | ||
}; | ||
} | ||
else if (credit && stringify) { | ||
configNotBody = { | ||
method: method, | ||
headers: header, | ||
credentials: 'include', | ||
withCredentials: true, | ||
}; | ||
configBody = { | ||
method: method, | ||
headers: header, | ||
credentials: 'include', | ||
withCredentials: true, | ||
body: JSON.stringify(data), | ||
}; | ||
} | ||
else if (cors && stringify) { | ||
configNotBody = { | ||
method: method, | ||
headers: header, | ||
mode: 'cors', | ||
}; | ||
configBody = { | ||
method: method, | ||
headers: header, | ||
mode: 'cors', | ||
body: JSON.stringify(data), | ||
}; | ||
} | ||
else if (credit) { | ||
configNotBody = { | ||
method: method, | ||
headers: header, | ||
credentials: 'include', | ||
withCredentials: true, | ||
}; | ||
configBody = { | ||
method: method, | ||
headers: header, | ||
credentials: 'include', | ||
withCredentials: true, | ||
body: data, | ||
}; | ||
} | ||
else if (cors) { | ||
configNotBody = { | ||
method: method, | ||
headers: header, | ||
mode: 'cors', | ||
}; | ||
configBody = { | ||
method: method, | ||
headers: header, | ||
mode: 'cors', | ||
body: data, | ||
}; | ||
} | ||
else if (stringify) { | ||
configNotBody = { | ||
method: method, | ||
headers: header, | ||
}; | ||
configBody = { | ||
method: method, | ||
headers: header, | ||
body: JSON.stringify(data), | ||
}; | ||
} | ||
else { | ||
configNotBody = { | ||
method: method, | ||
headers: header, | ||
}; | ||
configBody = { | ||
method: method, | ||
headers: header, | ||
body: data, | ||
}; | ||
} | ||
const config = { | ||
@@ -66,4 +165,4 @@ POST: configBody, | ||
*/ | ||
const callApiJson = async (url, method, data, header = {}) => { | ||
const response = await (await fetch(url, (0, exports.configRequest)(method, header, data))).json(); | ||
const callApiJson = async (url, method, data, header = {}, credit = true, cors = true, stringify = true) => { | ||
const response = await (await fetch(url, (0, exports.configRequest)(method, header, data, credit, cors, stringify))).json(); | ||
return response; | ||
@@ -80,6 +179,6 @@ }; | ||
*/ | ||
const callApi = async (url, method, data, header = {}) => { | ||
const response = await fetch(url, { method, headers: header, body: data }); | ||
const callApi = async (url, method, data, header = {}, credit = true, cors = true, stringify = true) => { | ||
const response = await fetch(url, (0, exports.configRequest)(method, header, data, credit, cors, stringify)); | ||
return response; | ||
}; | ||
exports.callApi = callApi; |
@@ -19,3 +19,3 @@ export declare const methodeFetch: () => { | ||
*/ | ||
export declare const configRequest: (method: string, header: HeadersInit, data?: any) => RequestInit; | ||
export declare const configRequest: (method: string, header: HeadersInit, data?: any, credit?: boolean, cors?: boolean, stringify?: boolean) => RequestInit; | ||
/** | ||
@@ -29,3 +29,3 @@ * fonction qui créer un request universel qui sera déterminé par les parametre | ||
*/ | ||
export declare const callApiJson: <T>(url: string, method: string, data?: any, header?: HeadersInit) => Promise<T>; | ||
export declare const callApiJson: <T>(url: string, method: string, data?: any, header?: HeadersInit, credit?: boolean, cors?: boolean, stringify?: boolean) => Promise<T>; | ||
/** | ||
@@ -39,2 +39,2 @@ * fonction qui créer un request universel qui sera déterminé par les parametre | ||
*/ | ||
export declare const callApi: (url: string, method: string, data?: any, header?: HeadersInit) => Promise<any>; | ||
export declare const callApi: (url: string, method: string, data?: any, header?: HeadersInit, credit?: boolean, cors?: boolean, stringify?: boolean) => Promise<any>; |
@@ -26,18 +26,117 @@ export const methodeFetch = () => { | ||
*/ | ||
export const configRequest = (method, header, data) => { | ||
const configNotBody = { | ||
method: method, | ||
credentials: 'include', | ||
withCredentials: true, | ||
headers: header, | ||
mode: 'cors', | ||
}; | ||
const configBody = { | ||
method: method, | ||
credentials: 'include', | ||
withCredentials: true, | ||
headers: header, | ||
mode: 'cors', | ||
body: JSON.stringify(data), | ||
}; | ||
export const configRequest = (method, header, data, credit = true, cors = true, stringify = true) => { | ||
let configNotBody = {}; | ||
let configBody = {}; | ||
if (credit && cors && stringify) { | ||
configNotBody = { | ||
method: method, | ||
credentials: 'include', | ||
withCredentials: true, | ||
headers: header, | ||
mode: 'cors', | ||
}; | ||
configBody = { | ||
method: method, | ||
credentials: 'include', | ||
withCredentials: true, | ||
headers: header, | ||
mode: 'cors', | ||
body: JSON.stringify(data), | ||
}; | ||
} | ||
else if (credit && cors) { | ||
configNotBody = { | ||
method: method, | ||
headers: header, | ||
credentials: 'include', | ||
withCredentials: true, | ||
mode: 'cors', | ||
}; | ||
configBody = { | ||
method: method, | ||
headers: header, | ||
mode: 'cors', | ||
credentials: 'include', | ||
withCredentials: true, | ||
body: data, | ||
}; | ||
} | ||
else if (credit && stringify) { | ||
configNotBody = { | ||
method: method, | ||
headers: header, | ||
credentials: 'include', | ||
withCredentials: true, | ||
}; | ||
configBody = { | ||
method: method, | ||
headers: header, | ||
credentials: 'include', | ||
withCredentials: true, | ||
body: JSON.stringify(data), | ||
}; | ||
} | ||
else if (cors && stringify) { | ||
configNotBody = { | ||
method: method, | ||
headers: header, | ||
mode: 'cors', | ||
}; | ||
configBody = { | ||
method: method, | ||
headers: header, | ||
mode: 'cors', | ||
body: JSON.stringify(data), | ||
}; | ||
} | ||
else if (credit) { | ||
configNotBody = { | ||
method: method, | ||
headers: header, | ||
credentials: 'include', | ||
withCredentials: true, | ||
}; | ||
configBody = { | ||
method: method, | ||
headers: header, | ||
credentials: 'include', | ||
withCredentials: true, | ||
body: data, | ||
}; | ||
} | ||
else if (cors) { | ||
configNotBody = { | ||
method: method, | ||
headers: header, | ||
mode: 'cors', | ||
}; | ||
configBody = { | ||
method: method, | ||
headers: header, | ||
mode: 'cors', | ||
body: data, | ||
}; | ||
} | ||
else if (stringify) { | ||
configNotBody = { | ||
method: method, | ||
headers: header, | ||
}; | ||
configBody = { | ||
method: method, | ||
headers: header, | ||
body: JSON.stringify(data), | ||
}; | ||
} | ||
else { | ||
configNotBody = { | ||
method: method, | ||
headers: header, | ||
}; | ||
configBody = { | ||
method: method, | ||
headers: header, | ||
body: data, | ||
}; | ||
} | ||
const config = { | ||
@@ -60,4 +159,4 @@ POST: configBody, | ||
*/ | ||
export const callApiJson = async (url, method, data, header = {}) => { | ||
const response = await (await fetch(url, configRequest(method, header, data))).json(); | ||
export const callApiJson = async (url, method, data, header = {}, credit = true, cors = true, stringify = true) => { | ||
const response = await (await fetch(url, configRequest(method, header, data, credit, cors, stringify))).json(); | ||
return response; | ||
@@ -73,5 +172,5 @@ }; | ||
*/ | ||
export const callApi = async (url, method, data, header = {}) => { | ||
const response = await fetch(url, { method, headers: header, body: data }); | ||
export const callApi = async (url, method, data, header = {}, credit = true, cors = true, stringify = true) => { | ||
const response = await fetch(url, configRequest(method, header, data, credit, cors, stringify)); | ||
return response; | ||
}; |
{ | ||
"name": "fetch-sveltekit", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "fonction de requête API", | ||
@@ -5,0 +5,0 @@ "repository": { |
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
34976
599