jordy 0.20.3 → 0.20.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,9 +2,10 @@ import { qs } from '../util';
|
|
|
2
2
|
import { AxiosHttpNetworkProvider } from './axios';
|
|
3
3
|
import { BasicHttpApi } from './BasicHttpApi';
|
|
4
4
|
import { defaultHeaderCreator } from './network.util';
|
|
5
|
+
var defSerialize = function (params) { return qs.serialize(params); };
|
|
5
6
|
export function createHttpApi(baseUrl, headerCreator, paramsSerializer, withCredentials) {
|
|
6
7
|
if (headerCreator === void 0) { headerCreator = defaultHeaderCreator; }
|
|
7
|
-
if (paramsSerializer === void 0) { paramsSerializer =
|
|
8
|
+
if (paramsSerializer === void 0) { paramsSerializer = defSerialize; }
|
|
8
9
|
if (withCredentials === void 0) { withCredentials = false; }
|
|
9
10
|
return new BasicHttpApi(new AxiosHttpNetworkProvider(), baseUrl, headerCreator, paramsSerializer, withCredentials);
|
|
10
11
|
}
|
package/esm5/util/queryString.js
CHANGED
|
@@ -1,43 +1,56 @@
|
|
|
1
1
|
import { __read } from "tslib";
|
|
2
2
|
import { isNullable, isObject } from './typeCheck';
|
|
3
|
+
function encodeFieldValue(key, value) {
|
|
4
|
+
return (key +
|
|
5
|
+
'=' +
|
|
6
|
+
encodeURIComponent(isNullable(value) || Number.isNaN(value) ? '' : value));
|
|
7
|
+
}
|
|
3
8
|
function _serialize(params, parentKey) {
|
|
4
9
|
if (parentKey === void 0) { parentKey = ''; }
|
|
5
|
-
return Object.entries(params)
|
|
10
|
+
return Object.entries(params)
|
|
11
|
+
.reduce(function (outerAcc, _a) {
|
|
6
12
|
var _b = __read(_a, 2), oriKey = _b[0], value = _b[1];
|
|
7
13
|
var key = parentKey ? "".concat(parentKey, "%5B").concat(oriKey, "%5D") : oriKey;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
value.reduce(function (acc, val) {
|
|
16
|
+
var subKey = "".concat(key, "%5B%5D");
|
|
17
|
+
if (isObject(val)) {
|
|
18
|
+
acc.push(_serialize(val, subKey));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
acc.push(encodeFieldValue(subKey, val));
|
|
22
|
+
}
|
|
23
|
+
return acc;
|
|
24
|
+
}, outerAcc);
|
|
25
|
+
}
|
|
26
|
+
else if (isObject(value)) {
|
|
27
|
+
outerAcc.push(_serialize(value, key));
|
|
11
28
|
}
|
|
12
29
|
else {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
return ret;
|
|
20
|
-
}, '');
|
|
30
|
+
outerAcc.push(encodeFieldValue(key, value));
|
|
31
|
+
}
|
|
32
|
+
return outerAcc;
|
|
33
|
+
}, [])
|
|
34
|
+
.join('&');
|
|
21
35
|
}
|
|
22
36
|
var cache = new Map();
|
|
23
37
|
export var qs = {
|
|
24
38
|
parse: function (url) {
|
|
25
|
-
var _a;
|
|
26
39
|
if (cache.has(url)) {
|
|
27
40
|
return cache.get(url);
|
|
28
41
|
}
|
|
29
|
-
cache.
|
|
42
|
+
if (cache.size > 100) {
|
|
43
|
+
cache.clear();
|
|
44
|
+
}
|
|
30
45
|
var result = {};
|
|
31
46
|
try {
|
|
32
47
|
var queryString = url.split('?')[1];
|
|
33
48
|
var splittedQueries = queryString.split('&');
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
result[key] = decodeURIComponent(value);
|
|
40
|
-
}
|
|
49
|
+
result = Object.fromEntries(splittedQueries.reduce(function (tmpMap, item) {
|
|
50
|
+
var _a = __read(item.split('='), 2), key = _a[0], value = _a[1];
|
|
51
|
+
tmpMap.set(key, decodeURIComponent(value));
|
|
52
|
+
return tmpMap;
|
|
53
|
+
}, new Map()));
|
|
41
54
|
}
|
|
42
55
|
catch (error) {
|
|
43
56
|
}
|
|
@@ -49,7 +62,7 @@ export var qs = {
|
|
|
49
62
|
if (!isObject(params)) {
|
|
50
63
|
throw new Error("serializeToQueryString: params is not object.\n".concat(params ? JSON.stringify(params) : params));
|
|
51
64
|
}
|
|
52
|
-
return (withQuestionMark ? '?' : '') + _serialize(params);
|
|
65
|
+
return (withQuestionMark === true ? '?' : '') + _serialize(params);
|
|
53
66
|
},
|
|
54
67
|
append: function (search, data) {
|
|
55
68
|
if (!search) {
|
|
@@ -15,7 +15,7 @@ interface QueryString {
|
|
|
15
15
|
* @param withQuestionMark
|
|
16
16
|
* @returns
|
|
17
17
|
*/
|
|
18
|
-
serialize<T = Record<string,
|
|
18
|
+
serialize<T = Record<string, any>>(params: T, withQuestionMark?: boolean): string;
|
|
19
19
|
/**
|
|
20
20
|
* 검색 문자열 (search string) 에 지정된 자료로 쿼리 파라미터를 덧붙인다.
|
|
21
21
|
* @param search "?"로 시작되는 search string
|
package/libs/util/typeCheck.d.ts
CHANGED