qmwts 1.1.58 → 1.1.60
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/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/utils/axios-instance.d.ts +2 -0
- package/dist/utils/axios-instance.js +84 -0
- package/dist/utils/number-utils.d.ts +2 -0
- package/dist/utils/number-utils.js +6 -0
- package/dist/utils/request-data-generator.js +3 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { default as ArrayUtils } from './utils/array-utils';
|
|
2
2
|
export { default as FinanceUtils } from './utils/finance-utils';
|
|
3
3
|
export type { XIRREntity } from './utils/finance-utils';
|
|
4
|
-
import
|
|
4
|
+
import AxiosInstance from './utils/axios-instance';
|
|
5
5
|
import Downloader from './utils/downloader';
|
|
6
6
|
import Encryptor from './utils/encryptor';
|
|
7
7
|
import NumberUtils from './utils/number-utils';
|
|
@@ -13,4 +13,4 @@ import StringUtils from './utils/string-utils';
|
|
|
13
13
|
import LocalDate from './class/local-date';
|
|
14
14
|
import LocalDateTime from './class/local-date-time';
|
|
15
15
|
import YearMonth from './class/year-month';
|
|
16
|
-
export {
|
|
16
|
+
export { AxiosInstance, Downloader, Encryptor, NumberUtils, JsonUtils, PrototypeUtils, RequestDataGenerator, FileUtils, StringUtils, LocalDate, LocalDateTime, YearMonth, };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.YearMonth = exports.LocalDateTime = exports.LocalDate = exports.StringUtils = exports.FileUtils = exports.RequestDataGenerator = exports.PrototypeUtils = exports.JsonUtils = exports.NumberUtils = exports.Encryptor = exports.Downloader = exports.
|
|
3
|
+
exports.YearMonth = exports.LocalDateTime = exports.LocalDate = exports.StringUtils = exports.FileUtils = exports.RequestDataGenerator = exports.PrototypeUtils = exports.JsonUtils = exports.NumberUtils = exports.Encryptor = exports.Downloader = exports.AxiosInstance = exports.FinanceUtils = exports.ArrayUtils = void 0;
|
|
4
4
|
// https://www.jianshu.com/p/8fa2c50720e4
|
|
5
5
|
var array_utils_1 = require("./utils/array-utils");
|
|
6
6
|
Object.defineProperty(exports, "ArrayUtils", { enumerable: true, get: function () { return array_utils_1.default; } });
|
|
7
7
|
var finance_utils_1 = require("./utils/finance-utils");
|
|
8
8
|
Object.defineProperty(exports, "FinanceUtils", { enumerable: true, get: function () { return finance_utils_1.default; } });
|
|
9
|
-
var
|
|
10
|
-
exports.
|
|
9
|
+
var axios_instance_1 = require("./utils/axios-instance");
|
|
10
|
+
exports.AxiosInstance = axios_instance_1.default;
|
|
11
11
|
var downloader_1 = require("./utils/downloader");
|
|
12
12
|
exports.Downloader = downloader_1.default;
|
|
13
13
|
var encryptor_1 = require("./utils/encryptor");
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
var axios_1 = require("axios");
|
|
40
|
+
var index_1 = require("../index");
|
|
41
|
+
// post 默认application/json
|
|
42
|
+
// post 使用URLSearchParams自动变为application/x-www-form-urlencoded;charset=UTF-8
|
|
43
|
+
// post 使用FormData自动变为multipart/form-data
|
|
44
|
+
// get 默认无
|
|
45
|
+
// get 使用URLSearchParams默认无
|
|
46
|
+
// get 无法使用FormData
|
|
47
|
+
axios_1.default.interceptors.request.use(function (request) {
|
|
48
|
+
request.data = index_1.RequestDataGenerator.generate(request.data, new FormData());
|
|
49
|
+
request.params = index_1.RequestDataGenerator.generate(request.params, new URLSearchParams());
|
|
50
|
+
return request;
|
|
51
|
+
}, function (error) {
|
|
52
|
+
return Promise.reject(error);
|
|
53
|
+
});
|
|
54
|
+
axios_1.default.interceptors.response.use(function (response) { return __awaiter(void 0, void 0, void 0, function () {
|
|
55
|
+
var data, file, a, _a;
|
|
56
|
+
return __generator(this, function (_b) {
|
|
57
|
+
switch (_b.label) {
|
|
58
|
+
case 0:
|
|
59
|
+
if (!(response.config.responseType === 'blob')) return [3 /*break*/, 3];
|
|
60
|
+
data = response.data;
|
|
61
|
+
if (!(data.type === 'application/x-download')) return [3 /*break*/, 1];
|
|
62
|
+
file = new File([data], decodeURI(response.headers['content-disposition'].split('filename=')[1]));
|
|
63
|
+
a = document.createElement('a');
|
|
64
|
+
a.href = URL.createObjectURL(file);
|
|
65
|
+
a.download = file.name;
|
|
66
|
+
a.click();
|
|
67
|
+
// 释放
|
|
68
|
+
URL.revokeObjectURL(a.href);
|
|
69
|
+
a.remove();
|
|
70
|
+
return [2 /*return*/, Promise.resolve(response)];
|
|
71
|
+
case 1:
|
|
72
|
+
if (!(data.type === 'application/json')) return [3 /*break*/, 3];
|
|
73
|
+
_a = response;
|
|
74
|
+
return [4 /*yield*/, new Response(data).json()];
|
|
75
|
+
case 2:
|
|
76
|
+
_a.data = _b.sent();
|
|
77
|
+
_b.label = 3;
|
|
78
|
+
case 3: return [2 /*return*/, response];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}); }, function (error) {
|
|
82
|
+
return Promise.reject(error);
|
|
83
|
+
});
|
|
84
|
+
exports.default = axios_1.default;
|
|
@@ -3,5 +3,7 @@ declare const _default: {
|
|
|
3
3
|
isNumber(...number: any[]): boolean;
|
|
4
4
|
thousandths(number: any, fixed?: number): string;
|
|
5
5
|
summation(array?: any[]): number;
|
|
6
|
+
isBetween(a: number, min: number, max: number): boolean;
|
|
7
|
+
isInside(a: number, min: number, max: number): boolean;
|
|
6
8
|
};
|
|
7
9
|
export default _default;
|
|
@@ -40,4 +40,10 @@ exports.default = {
|
|
|
40
40
|
}
|
|
41
41
|
return sum;
|
|
42
42
|
},
|
|
43
|
+
isBetween: function (a, min, max) {
|
|
44
|
+
return a >= Math.min(min, max) && a <= Math.max(max, min);
|
|
45
|
+
},
|
|
46
|
+
isInside: function (a, min, max) {
|
|
47
|
+
return a > Math.min(min, max) && a < Math.max(max, min);
|
|
48
|
+
}
|
|
43
49
|
};
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var prototype_utils_1 = require("./prototype-utils");
|
|
4
3
|
exports.default = {
|
|
5
4
|
generate: function (data, params) {
|
|
6
5
|
if (data === void 0) { data = {}; }
|
|
7
6
|
for (var _i = 0, _a = Object.entries(data); _i < _a.length; _i++) {
|
|
8
7
|
var _b = _a[_i], key = _b[0], value = _b[1];
|
|
9
|
-
if (
|
|
10
|
-
for (var _c = 0,
|
|
11
|
-
var i =
|
|
8
|
+
if (Array.isArray(value))
|
|
9
|
+
for (var _c = 0, value_1 = value; _c < value_1.length; _c++) {
|
|
10
|
+
var i = value_1[_c];
|
|
12
11
|
params.append(key, i);
|
|
13
12
|
}
|
|
14
13
|
else if (isValidValue(value))
|