qmwts 1.1.45 → 1.1.47
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/class/local-date.d.ts +7 -0
- package/dist/class/local-date.js +21 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/utils/finance-utils.d.ts +8 -0
- package/dist/utils/finance-utils.js +44 -0
- package/package.json +1 -1
- package/dist/utils/date-utils.d.ts +0 -6
- package/dist/utils/date-utils.js +0 -16
- package/dist/utils/html-utils.d.ts +0 -0
- package/dist/utils/html-utils.js +0 -17
|
@@ -4,5 +4,12 @@ export default class LocalDate {
|
|
|
4
4
|
constructor(date: Date);
|
|
5
5
|
static now(): LocalDate;
|
|
6
6
|
static of(year: number, month: number, date: number): LocalDate;
|
|
7
|
+
getYear(): number;
|
|
8
|
+
getMonth(): number;
|
|
9
|
+
getDayOfMonth(): number;
|
|
10
|
+
getDayOfWeek(): number;
|
|
11
|
+
plusDays(days: number): LocalDate;
|
|
12
|
+
minusDays(days: number): LocalDate;
|
|
13
|
+
format(): string;
|
|
7
14
|
toString(): string;
|
|
8
15
|
}
|
package/dist/class/local-date.js
CHANGED
|
@@ -14,6 +14,27 @@ var LocalDate = /** @class */ (function () {
|
|
|
14
14
|
LocalDate.of = function (year, month, date) {
|
|
15
15
|
return new LocalDate(new Date(year, month - 1, date));
|
|
16
16
|
};
|
|
17
|
+
LocalDate.prototype.getYear = function () {
|
|
18
|
+
return this.date.getFullYear();
|
|
19
|
+
};
|
|
20
|
+
LocalDate.prototype.getMonth = function () {
|
|
21
|
+
return this.date.getMonth() + 1;
|
|
22
|
+
};
|
|
23
|
+
LocalDate.prototype.getDayOfMonth = function () {
|
|
24
|
+
return this.date.getDate();
|
|
25
|
+
};
|
|
26
|
+
LocalDate.prototype.getDayOfWeek = function () {
|
|
27
|
+
return this.date.getDay() || 7;
|
|
28
|
+
};
|
|
29
|
+
LocalDate.prototype.plusDays = function (days) {
|
|
30
|
+
return LocalDate.of(this.getYear(), this.getMonth(), this.getDayOfMonth() + days);
|
|
31
|
+
};
|
|
32
|
+
LocalDate.prototype.minusDays = function (days) {
|
|
33
|
+
return this.plusDays(-days);
|
|
34
|
+
};
|
|
35
|
+
LocalDate.prototype.format = function () {
|
|
36
|
+
return this.toString();
|
|
37
|
+
};
|
|
17
38
|
LocalDate.prototype.toString = function () {
|
|
18
39
|
return [
|
|
19
40
|
this.date.getFullYear().toString(),
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
export { default as ArrayUtils } from './utils/array-utils';
|
|
2
|
+
export { default as FinanceUtils } from './utils/finance-utils';
|
|
3
|
+
export type { XIRREntity } from './utils/finance-utils';
|
|
2
4
|
import Downloader from './utils/downloader';
|
|
3
5
|
import NumberUtils from './utils/number-utils';
|
|
4
6
|
import JsonUtils from './utils/json-utils';
|
|
@@ -9,4 +11,4 @@ import FileUtils from './utils/file-utils';
|
|
|
9
11
|
import LocalDate from './class/local-date';
|
|
10
12
|
import LocalDateTime from './class/local-date-time';
|
|
11
13
|
import YearMonth from './class/year-month';
|
|
12
|
-
export {
|
|
14
|
+
export { Downloader, NumberUtils, JsonUtils, UUIDUtils, PrototypeUtils, RequestDataGenerator, FileUtils, LocalDate, LocalDateTime, YearMonth, };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.YearMonth = exports.LocalDateTime = exports.LocalDate = exports.FileUtils = exports.RequestDataGenerator = exports.PrototypeUtils = exports.UUIDUtils = exports.JsonUtils = exports.NumberUtils = exports.Downloader = exports.ArrayUtils = void 0;
|
|
3
|
+
exports.YearMonth = exports.LocalDateTime = exports.LocalDate = exports.FileUtils = exports.RequestDataGenerator = exports.PrototypeUtils = exports.UUIDUtils = exports.JsonUtils = exports.NumberUtils = exports.Downloader = 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
|
-
exports
|
|
6
|
+
Object.defineProperty(exports, "ArrayUtils", { enumerable: true, get: function () { return array_utils_1.default; } });
|
|
7
|
+
var finance_utils_1 = require("./utils/finance-utils");
|
|
8
|
+
Object.defineProperty(exports, "FinanceUtils", { enumerable: true, get: function () { return finance_utils_1.default; } });
|
|
7
9
|
var downloader_1 = require("./utils/downloader");
|
|
8
10
|
exports.Downloader = downloader_1.default;
|
|
9
11
|
var number_utils_1 = require("./utils/number-utils");
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
+
if (ar || !(i in from)) {
|
|
5
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
+
ar[i] = from[i];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
// 货币相关工具类
|
|
13
|
+
exports.default = {
|
|
14
|
+
// https://support.microsoft.com/zh-cn/office/xirr-%E5%87%BD%E6%95%B0-de1242ec-6477-445b-b11b-a303ad9adc9d
|
|
15
|
+
// 不定期投资收益率
|
|
16
|
+
XIRR: function (entities, guess) {
|
|
17
|
+
if (guess === void 0) { guess = 0.1; }
|
|
18
|
+
// 按照日期从小到大排列
|
|
19
|
+
var list = __spreadArray([], entities, true).sort(function (a, b) { return a.date.getTime() - b.date.getTime(); });
|
|
20
|
+
var d0 = list[0].date.getTime();
|
|
21
|
+
var npv = function (rate) {
|
|
22
|
+
var total = 0;
|
|
23
|
+
for (var i = list.length - 1; i >= 0; i--) {
|
|
24
|
+
var daysDiff = (list[i].date.getTime() - d0) / (1000 * 3600 * 24);
|
|
25
|
+
total += list[i].amount / Math.pow(1 + rate, daysDiff / 365);
|
|
26
|
+
}
|
|
27
|
+
return total;
|
|
28
|
+
};
|
|
29
|
+
var epsilon = 1e-6; // 精度
|
|
30
|
+
var x0 = guess;
|
|
31
|
+
var x1;
|
|
32
|
+
var iteration = 0;
|
|
33
|
+
while (iteration < 100) {
|
|
34
|
+
var f0 = npv(x0);
|
|
35
|
+
var fPrime = (npv(x0 + epsilon) - f0) / epsilon;
|
|
36
|
+
x1 = x0 - f0 / fPrime;
|
|
37
|
+
if (Math.abs(x1 - x0) < epsilon)
|
|
38
|
+
return x1;
|
|
39
|
+
x0 = x1;
|
|
40
|
+
iteration++;
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
},
|
|
44
|
+
};
|
package/package.json
CHANGED
package/dist/utils/date-utils.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = {
|
|
4
|
-
isToday: function (date) {
|
|
5
|
-
var today = new Date();
|
|
6
|
-
return today.getFullYear() === date.getFullYear()
|
|
7
|
-
&& today.getMonth() === date.getMonth()
|
|
8
|
-
&& today.getDate() === date.getDate();
|
|
9
|
-
},
|
|
10
|
-
toDateString: function (date) {
|
|
11
|
-
return '';
|
|
12
|
-
},
|
|
13
|
-
toDateTimeString: function (date) {
|
|
14
|
-
return '';
|
|
15
|
-
}
|
|
16
|
-
};
|
|
File without changes
|
package/dist/utils/html-utils.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Promise.resolve().then(function () {
|
|
3
|
-
console.log(0);
|
|
4
|
-
return Promise.resolve(4);
|
|
5
|
-
}).then(function (res) {
|
|
6
|
-
console.log(res);
|
|
7
|
-
});
|
|
8
|
-
Promise.resolve().then(function () {
|
|
9
|
-
console.log(1);
|
|
10
|
-
}).then(function () {
|
|
11
|
-
console.log(2);
|
|
12
|
-
}).then(function () {
|
|
13
|
-
console.log(3);
|
|
14
|
-
}).then(function () {
|
|
15
|
-
console.log(5);
|
|
16
|
-
console.log(6);
|
|
17
|
-
});
|