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 = qs.serialize; }
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
  }
@@ -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).reduce(function (acc, _a) {
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
- var ret = acc + (acc.length > 1 ? '&' : '');
9
- if (isObject(value)) {
10
- ret += _serialize(value, key);
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
- ret =
14
- ret +
15
- key +
16
- '=' +
17
- encodeURIComponent(isNullable(value) || Number.isNaN(value) ? '' : value);
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.clear();
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
- var len = splittedQueries.length;
35
- var key = '';
36
- var value = '';
37
- for (var i = 0; i < len; i++) {
38
- _a = __read(splittedQueries[i].split('='), 2), key = _a[0], value = _a[1];
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, unknown>>(params: T, withQuestionMark?: boolean): string;
18
+ serialize<T = Record<string, any>>(params: T, withQuestionMark?: boolean): string;
19
19
  /**
20
20
  * 검색 문자열 (search string) 에 지정된 자료로 쿼리 파라미터를 덧붙인다.
21
21
  * @param search "?"로 시작되는 search string
@@ -41,4 +41,4 @@ export declare function isFunction(val: unknown): val is CallableFunction;
41
41
  * @param val
42
42
  * @returns
43
43
  */
44
- export declare function isObject(val: unknown): val is Object;
44
+ export declare function isObject(val: unknown): val is Record<string, any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jordy",
3
- "version": "0.20.3",
3
+ "version": "0.20.5",
4
4
  "description": "typescript based frontend toolkit",
5
5
  "repository": {
6
6
  "type": "git",