commit | author | age
|
f9c38e
|
1 |
const responseBody = { |
I |
2 |
message: '', |
|
3 |
timestamp: 0, |
|
4 |
result: null, |
|
5 |
code: 0 |
|
6 |
} |
|
7 |
|
|
8 |
export const builder = (data, message, code = 0, headers = {}) => { |
|
9 |
responseBody.result = data |
|
10 |
if (message !== undefined && message !== null) { |
|
11 |
responseBody.message = message |
|
12 |
} |
|
13 |
if (code !== undefined && code !== 0) { |
|
14 |
responseBody.code = code |
|
15 |
responseBody._status = code |
|
16 |
} |
|
17 |
if (headers !== null && typeof headers === 'object' && Object.keys(headers).length > 0) { |
|
18 |
responseBody._headers = headers |
|
19 |
} |
|
20 |
responseBody.timestamp = new Date().getTime() |
|
21 |
return responseBody |
|
22 |
} |
|
23 |
|
|
24 |
export const getQueryParameters = (options) => { |
|
25 |
const url = options.url |
|
26 |
const search = url.split('?')[1] |
|
27 |
if (!search) { |
|
28 |
return {} |
|
29 |
} |
|
30 |
return JSON.parse('{"' + decodeURIComponent(search) |
|
31 |
.replace(/"/g, '\\"') |
|
32 |
.replace(/&/g, '","') |
|
33 |
.replace(/=/g, '":"') + '"}') |
|
34 |
} |
|
35 |
|
|
36 |
export const getBody = (options) => { |
|
37 |
return options.body && JSON.parse(options.body) |
|
38 |
} |