utils-lib-js 1.1.0 → 1.2.1
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.
- package/dist/common/request.d.ts +7 -0
- package/dist/common/request.js +22 -1
- package/dist/common/types.d.ts +1 -0
- package/dist/esm/request.d.ts +7 -0
- package/dist/esm/request.js +23 -2
- package/dist/esm/types.d.ts +1 -0
- package/package.json +1 -1
package/dist/common/request.d.ts
CHANGED
|
@@ -21,6 +21,13 @@ declare abstract class RequestBase extends Interceptors implements IRequestBase
|
|
|
21
21
|
initAbort: (params: any) => any;
|
|
22
22
|
requestType: () => (url: any, opts: any) => Promise<void>;
|
|
23
23
|
getDataByType: (type: any, response: any) => any;
|
|
24
|
+
formatBodyString: (bodyString: any) => {
|
|
25
|
+
text: () => any;
|
|
26
|
+
json: () => any;
|
|
27
|
+
blob: () => IObject<any>;
|
|
28
|
+
formData: () => IObject<any>;
|
|
29
|
+
arrayBuffer: () => IObject<any>;
|
|
30
|
+
};
|
|
24
31
|
}
|
|
25
32
|
declare abstract class RequestInit extends RequestBase implements IRequestInit {
|
|
26
33
|
constructor(origin: any);
|
package/dist/common/request.js
CHANGED
|
@@ -134,6 +134,25 @@ var RequestBase = function (_super) {
|
|
|
134
134
|
return response['json']();
|
|
135
135
|
}
|
|
136
136
|
};
|
|
137
|
+
_this.formatBodyString = function (bodyString) {
|
|
138
|
+
return {
|
|
139
|
+
text: function () {
|
|
140
|
+
return bodyString;
|
|
141
|
+
},
|
|
142
|
+
json: function () {
|
|
143
|
+
var _a;return (_a = (0, index_js_1.stringToJson)(bodyString)) !== null && _a !== void 0 ? _a : bodyString;
|
|
144
|
+
},
|
|
145
|
+
blob: function () {
|
|
146
|
+
return (0, index_js_1.stringToJson)(bodyString);
|
|
147
|
+
},
|
|
148
|
+
formData: function () {
|
|
149
|
+
return (0, index_js_1.stringToJson)(bodyString);
|
|
150
|
+
},
|
|
151
|
+
arrayBuffer: function () {
|
|
152
|
+
return (0, index_js_1.stringToJson)(bodyString);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
};
|
|
137
156
|
_this.origin = origin !== null && origin !== void 0 ? origin : '';
|
|
138
157
|
return _this;
|
|
139
158
|
}
|
|
@@ -223,7 +242,9 @@ var Request = function (_super) {
|
|
|
223
242
|
return data_1 += chunk;
|
|
224
243
|
});
|
|
225
244
|
return response.on("end", function () {
|
|
226
|
-
var _a, _b;
|
|
245
|
+
var _a, _b;
|
|
246
|
+
var result = _this.getDataByType(params.type, _this.formatBodyString(data_1));
|
|
247
|
+
resolve((_b = (_a = _this.resFn) === null || _a === void 0 ? void 0 : _a.call(_this, result)) !== null && _b !== void 0 ? _b : result);
|
|
227
248
|
});
|
|
228
249
|
}
|
|
229
250
|
return _this.errorFn(reject)(response === null || response === void 0 ? void 0 : response.statusMessage);
|
package/dist/common/types.d.ts
CHANGED
|
@@ -84,6 +84,7 @@ export declare type IRequestBase = {
|
|
|
84
84
|
fetch: IRequestBaseFn;
|
|
85
85
|
http: IRequestBaseFn;
|
|
86
86
|
getDataByType: (type: IDataType, response: Response) => Promise<any>;
|
|
87
|
+
formatBodyString: (bodyString: string) => IObject<Function>;
|
|
87
88
|
};
|
|
88
89
|
export declare type IRequestInit = {
|
|
89
90
|
initDefaultParams: (url: IUrl, opts: IRequestOptions) => any;
|
package/dist/esm/request.d.ts
CHANGED
|
@@ -21,6 +21,13 @@ declare abstract class RequestBase extends Interceptors implements IRequestBase
|
|
|
21
21
|
initAbort: (params: any) => any;
|
|
22
22
|
requestType: () => (url: any, opts: any) => Promise<void>;
|
|
23
23
|
getDataByType: (type: any, response: any) => any;
|
|
24
|
+
formatBodyString: (bodyString: any) => {
|
|
25
|
+
text: () => any;
|
|
26
|
+
json: () => any;
|
|
27
|
+
blob: () => IObject<any>;
|
|
28
|
+
formData: () => IObject<any>;
|
|
29
|
+
arrayBuffer: () => IObject<any>;
|
|
30
|
+
};
|
|
24
31
|
}
|
|
25
32
|
declare abstract class RequestInit extends RequestBase implements IRequestInit {
|
|
26
33
|
constructor(origin: any);
|
package/dist/esm/request.js
CHANGED
|
@@ -34,7 +34,7 @@ var __rest = this && this.__rest || function (s, e) {
|
|
|
34
34
|
}
|
|
35
35
|
return t;
|
|
36
36
|
};
|
|
37
|
-
import { urlJoin, defer, jsonToString } from "./index.js";
|
|
37
|
+
import { urlJoin, defer, jsonToString, stringToJson } from "./index.js";
|
|
38
38
|
import { request } from "http";
|
|
39
39
|
import { parse } from "url";
|
|
40
40
|
var Interceptors = function () {
|
|
@@ -130,6 +130,25 @@ var RequestBase = function (_super) {
|
|
|
130
130
|
return response['json']();
|
|
131
131
|
}
|
|
132
132
|
};
|
|
133
|
+
_this.formatBodyString = function (bodyString) {
|
|
134
|
+
return {
|
|
135
|
+
text: function () {
|
|
136
|
+
return bodyString;
|
|
137
|
+
},
|
|
138
|
+
json: function () {
|
|
139
|
+
var _a;return (_a = stringToJson(bodyString)) !== null && _a !== void 0 ? _a : bodyString;
|
|
140
|
+
},
|
|
141
|
+
blob: function () {
|
|
142
|
+
return stringToJson(bodyString);
|
|
143
|
+
},
|
|
144
|
+
formData: function () {
|
|
145
|
+
return stringToJson(bodyString);
|
|
146
|
+
},
|
|
147
|
+
arrayBuffer: function () {
|
|
148
|
+
return stringToJson(bodyString);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
};
|
|
133
152
|
_this.origin = origin !== null && origin !== void 0 ? origin : '';
|
|
134
153
|
return _this;
|
|
135
154
|
}
|
|
@@ -219,7 +238,9 @@ var Request = function (_super) {
|
|
|
219
238
|
return data_1 += chunk;
|
|
220
239
|
});
|
|
221
240
|
return response.on("end", function () {
|
|
222
|
-
var _a, _b;
|
|
241
|
+
var _a, _b;
|
|
242
|
+
var result = _this.getDataByType(params.type, _this.formatBodyString(data_1));
|
|
243
|
+
resolve((_b = (_a = _this.resFn) === null || _a === void 0 ? void 0 : _a.call(_this, result)) !== null && _b !== void 0 ? _b : result);
|
|
223
244
|
});
|
|
224
245
|
}
|
|
225
246
|
return _this.errorFn(reject)(response === null || response === void 0 ? void 0 : response.statusMessage);
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -84,6 +84,7 @@ export declare type IRequestBase = {
|
|
|
84
84
|
fetch: IRequestBaseFn;
|
|
85
85
|
http: IRequestBaseFn;
|
|
86
86
|
getDataByType: (type: IDataType, response: Response) => Promise<any>;
|
|
87
|
+
formatBodyString: (bodyString: string) => IObject<Function>;
|
|
87
88
|
};
|
|
88
89
|
export declare type IRequestInit = {
|
|
89
90
|
initDefaultParams: (url: IUrl, opts: IRequestOptions) => any;
|