qmwts 1.1.44 → 1.1.46
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 +6 -5
- package/dist/class/local-date.js +13 -25
- package/dist/class/year-month.d.ts +6 -5
- package/dist/class/year-month.js +12 -22
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -4
- package/dist/utils/finance-utils.d.ts +8 -0
- package/dist/utils/finance-utils.js +44 -0
- package/dist/utils/number-utils.d.ts +0 -1
- package/dist/utils/number-utils.js +0 -3
- package/dist/utils/prototype-utils.d.ts +1 -0
- package/dist/utils/prototype-utils.js +11 -8
- 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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export default class LocalDate {
|
|
2
|
-
private date;
|
|
3
|
-
constructor(
|
|
4
|
-
|
|
5
|
-
static
|
|
6
|
-
|
|
2
|
+
private readonly date;
|
|
3
|
+
constructor();
|
|
4
|
+
constructor(date: Date);
|
|
5
|
+
static now(): LocalDate;
|
|
6
|
+
static of(year: number, month: number, date: number): LocalDate;
|
|
7
|
+
toString(): string;
|
|
7
8
|
}
|
package/dist/class/local-date.js
CHANGED
|
@@ -1,37 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var number_utils_1 = require("../utils/number-utils");
|
|
4
|
-
var prototype_utils_1 = require("../utils/prototype-utils");
|
|
5
3
|
// https://juejin.cn/post/7098891689955164168
|
|
6
4
|
var LocalDate = /** @class */ (function () {
|
|
7
|
-
function LocalDate() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var _this = this;
|
|
13
|
-
this.toString = function () {
|
|
14
|
-
return [
|
|
15
|
-
_this.date.getFullYear(),
|
|
16
|
-
number_utils_1.default.leftPadZero(_this.date.getMonth() + 1, 2),
|
|
17
|
-
number_utils_1.default.leftPadZero(_this.date.getDate(), 2)
|
|
18
|
-
].join('-');
|
|
19
|
-
};
|
|
20
|
-
this.date = new Date();
|
|
21
|
-
if (number_utils_1.default.isNumber(args[0]))
|
|
22
|
-
this.date.setFullYear(+args[0]);
|
|
23
|
-
if (number_utils_1.default.isNumber(args[1]))
|
|
24
|
-
this.date.setMonth(+args[1] - 1);
|
|
25
|
-
if (number_utils_1.default.isNumber(args[2]))
|
|
26
|
-
this.date.setDate(args[2]);
|
|
27
|
-
if (prototype_utils_1.default.isDate(args[0]))
|
|
28
|
-
this.date = args[0];
|
|
5
|
+
function LocalDate(date) {
|
|
6
|
+
if (date == void 0)
|
|
7
|
+
this.date = new Date();
|
|
8
|
+
else
|
|
9
|
+
this.date = date;
|
|
29
10
|
}
|
|
30
11
|
LocalDate.now = function () {
|
|
31
12
|
return new LocalDate();
|
|
32
13
|
};
|
|
33
14
|
LocalDate.of = function (year, month, date) {
|
|
34
|
-
return new LocalDate(year, month, date);
|
|
15
|
+
return new LocalDate(new Date(year, month - 1, date));
|
|
16
|
+
};
|
|
17
|
+
LocalDate.prototype.toString = function () {
|
|
18
|
+
return [
|
|
19
|
+
this.date.getFullYear().toString(),
|
|
20
|
+
(this.date.getMonth() + 1).toString().padStart(2, '0'),
|
|
21
|
+
this.date.getDate().toString().padStart(2, '0')
|
|
22
|
+
].join('-');
|
|
35
23
|
};
|
|
36
24
|
return LocalDate;
|
|
37
25
|
}());
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export default class YearMonth {
|
|
2
|
-
private date;
|
|
3
|
-
constructor(
|
|
4
|
-
|
|
5
|
-
static
|
|
6
|
-
|
|
2
|
+
private readonly date;
|
|
3
|
+
constructor();
|
|
4
|
+
constructor(date: Date);
|
|
5
|
+
static now(): YearMonth;
|
|
6
|
+
static of(year: number, month: number): YearMonth;
|
|
7
|
+
toString(): string;
|
|
7
8
|
}
|
package/dist/class/year-month.js
CHANGED
|
@@ -1,33 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var number_utils_1 = require("../utils/number-utils");
|
|
4
|
-
var prototype_utils_1 = require("../utils/prototype-utils");
|
|
5
3
|
var YearMonth = /** @class */ (function () {
|
|
6
|
-
function YearMonth() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var _this = this;
|
|
12
|
-
this.toString = function () {
|
|
13
|
-
return [
|
|
14
|
-
_this.date.getFullYear(),
|
|
15
|
-
number_utils_1.default.leftPadZero(_this.date.getMonth() + 1, 2)
|
|
16
|
-
].join('-');
|
|
17
|
-
};
|
|
18
|
-
this.date = new Date();
|
|
19
|
-
if (number_utils_1.default.isNumber(args[0]))
|
|
20
|
-
this.date.setFullYear(+args[0]);
|
|
21
|
-
if (number_utils_1.default.isNumber(args[1]))
|
|
22
|
-
this.date.setMonth(+args[1] - 1);
|
|
23
|
-
if (prototype_utils_1.default.isDate(args[0]))
|
|
24
|
-
this.date = args[0];
|
|
4
|
+
function YearMonth(date) {
|
|
5
|
+
if (date == void 0)
|
|
6
|
+
this.date = new Date();
|
|
7
|
+
else
|
|
8
|
+
this.date = date;
|
|
25
9
|
}
|
|
26
10
|
YearMonth.now = function () {
|
|
27
11
|
return new YearMonth();
|
|
28
12
|
};
|
|
29
13
|
YearMonth.of = function (year, month) {
|
|
30
|
-
return new YearMonth(year, month);
|
|
14
|
+
return new YearMonth(new Date(year, month - 1));
|
|
15
|
+
};
|
|
16
|
+
YearMonth.prototype.toString = function () {
|
|
17
|
+
return [
|
|
18
|
+
this.date.getFullYear().toString(),
|
|
19
|
+
(this.date.getMonth() + 1).toString().padStart(2, '0')
|
|
20
|
+
].join('-');
|
|
31
21
|
};
|
|
32
22
|
return YearMonth;
|
|
33
23
|
}());
|
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';
|
|
@@ -6,8 +8,7 @@ import UUIDUtils from './utils/uuid-utils';
|
|
|
6
8
|
import PrototypeUtils from './utils/prototype-utils';
|
|
7
9
|
import RequestDataGenerator from './utils/request-data-generator';
|
|
8
10
|
import FileUtils from './utils/file-utils';
|
|
9
|
-
import DateUtils from './utils/date-utils';
|
|
10
11
|
import LocalDate from './class/local-date';
|
|
11
12
|
import LocalDateTime from './class/local-date-time';
|
|
12
13
|
import YearMonth from './class/year-month';
|
|
13
|
-
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.
|
|
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");
|
|
@@ -18,8 +20,6 @@ var request_data_generator_1 = require("./utils/request-data-generator");
|
|
|
18
20
|
exports.RequestDataGenerator = request_data_generator_1.default;
|
|
19
21
|
var file_utils_1 = require("./utils/file-utils");
|
|
20
22
|
exports.FileUtils = file_utils_1.default;
|
|
21
|
-
var date_utils_1 = require("./utils/date-utils");
|
|
22
|
-
exports.DateUtils = date_utils_1.default;
|
|
23
23
|
var local_date_1 = require("./class/local-date");
|
|
24
24
|
exports.LocalDate = local_date_1.default;
|
|
25
25
|
var local_date_time_1 = require("./class/local-date-time");
|
|
@@ -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
|
+
};
|
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = {
|
|
4
|
+
is: function (o, type) {
|
|
5
|
+
return Object.prototype.toString.call(o) === "[object ".concat(type, "]");
|
|
6
|
+
},
|
|
4
7
|
isObject: function (o) {
|
|
5
|
-
return
|
|
8
|
+
return this.is(o, 'Object');
|
|
6
9
|
},
|
|
7
10
|
isArray: function (o) {
|
|
8
|
-
return
|
|
11
|
+
return this.is(o, 'Array');
|
|
9
12
|
},
|
|
10
13
|
isFile: function (o) {
|
|
11
|
-
return
|
|
14
|
+
return this.is(o, 'File');
|
|
12
15
|
},
|
|
13
16
|
isNumber: function (o) {
|
|
14
|
-
return
|
|
17
|
+
return this.is(o, 'Number');
|
|
15
18
|
},
|
|
16
19
|
isDate: function (o) {
|
|
17
|
-
return
|
|
20
|
+
return this.is(o, 'Date');
|
|
18
21
|
},
|
|
19
22
|
isFunction: function (o) {
|
|
20
|
-
return
|
|
23
|
+
return this.is(o, 'Function');
|
|
21
24
|
},
|
|
22
25
|
isBoolean: function (o) {
|
|
23
|
-
return
|
|
26
|
+
return this.is(o, 'Boolean');
|
|
24
27
|
},
|
|
25
28
|
isString: function (o) {
|
|
26
|
-
return
|
|
29
|
+
return this.is(o, 'String');
|
|
27
30
|
},
|
|
28
31
|
};
|
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
|
-
});
|