@ch20026103/anysis 0.0.16-alpha → 0.0.16-beta1
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/demo/main.js +13 -18
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/stockSkills/gold.d.ts +8 -7
- package/dist/cjs/stockSkills/obv.d.ts +9 -7
- package/dist/cjs/stockSkills/types.d.ts +1 -1
- package/dist/cjs/stockSkills/utils/dateFormat.d.ts +3 -3
- package/dist/cjs/stockSkills/utils/dateFormat.js +10 -15
- package/dist/cjs/stockSkills/utils/getWeekLine.d.ts +7 -4
- package/dist/cjs/stockSkills/vma.d.ts +10 -8
- package/dist/cjs/stockSkills/week.d.ts +16 -0
- package/dist/cjs/stockSkills/week.js +56 -0
- package/dist/cjs/stockSkills/week.test.d.ts +1 -0
- package/dist/cjs/stockSkills/week.test.js +60 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/stockSkills/gold.d.ts +8 -7
- package/dist/esm/stockSkills/obv.d.ts +9 -7
- package/dist/esm/stockSkills/types.d.ts +1 -1
- package/dist/esm/stockSkills/utils/dateFormat.d.ts +3 -3
- package/dist/esm/stockSkills/utils/dateFormat.js +10 -15
- package/dist/esm/stockSkills/utils/getWeekLine.d.ts +7 -4
- package/dist/esm/stockSkills/vma.d.ts +10 -8
- package/dist/esm/stockSkills/week.d.ts +16 -0
- package/dist/esm/stockSkills/week.js +54 -0
- package/dist/esm/stockSkills/week.test.d.ts +1 -0
- package/dist/esm/stockSkills/week.test.js +58 -0
- package/dist/umd/index.js +67 -18
- package/package.json +15 -17
package/demo/main.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
/* eslint @typescript-eslint/no-var-requires: "off" */
|
|
2
2
|
const axios = require("axios");
|
|
3
|
-
const {
|
|
4
|
-
Obv,
|
|
5
|
-
findPeaksByGradient,
|
|
6
|
-
findTroughByGradient,
|
|
7
|
-
} = require("../dist/cjs/index.js");
|
|
3
|
+
const { Week, Kd } = require("../dist/cjs/index.js");
|
|
8
4
|
|
|
9
5
|
// 使用示例
|
|
10
|
-
const
|
|
6
|
+
const week = new Week();
|
|
7
|
+
const kd = new Kd();
|
|
11
8
|
function DemoDay(stockId) {
|
|
12
9
|
axios
|
|
13
10
|
.get(
|
|
@@ -17,19 +14,17 @@ function DemoDay(stockId) {
|
|
|
17
14
|
res = res.data.replace(/^\(|\);$/g, "");
|
|
18
15
|
let parse = JSON.parse(res);
|
|
19
16
|
let data = parse.ta;
|
|
20
|
-
let
|
|
21
|
-
obvData = obvData.map((item) => item.obv);
|
|
22
|
-
const peak = findPeaksByGradient(obvData, 1);
|
|
23
|
-
const peakIndex =peak[peak.length-1]
|
|
24
|
-
const peak2Index =peak[peak.length-2]
|
|
25
|
-
console.log(data[peakIndex].t, data[peakIndex].c);
|
|
26
|
-
console.log(data[peak2Index].t, data[peak2Index].c);
|
|
17
|
+
let weekData = week.init(data[0]);
|
|
27
18
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
19
|
+
for (let i = 1; i < data.length; i++) {
|
|
20
|
+
weekData = week.next(data[i], weekData);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let kdData = kd.init(weekData.week[0], 9);
|
|
24
|
+
for (let i = 0; i < weekData.week.length; i++) {
|
|
25
|
+
kdData = kd.next(weekData.week[i], kdData, 9);
|
|
26
|
+
}
|
|
27
|
+
console.log(kdData);
|
|
33
28
|
})
|
|
34
29
|
.catch((error) => {
|
|
35
30
|
console.error(error);
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export { default as Macd } from "./stockSkills/macd.js";
|
|
|
15
15
|
export { default as Obv } from "./stockSkills/obv.js";
|
|
16
16
|
export { default as Rsi } from "./stockSkills/rsi.js";
|
|
17
17
|
export { default as dateFormat } from "./stockSkills/utils/dateFormat.js";
|
|
18
|
-
export { default as
|
|
18
|
+
export { default as Week } from "./stockSkills/week.js";
|
|
19
19
|
export { default as Vma } from "./stockSkills/vma.js";
|
|
20
20
|
export { default as Williams } from "./stockSkills/williams.js";
|
|
21
21
|
export { add } from "./test/add.js";
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseLsusbOutput = exports.isJSON = exports.calculateDivisionFactor = exports.minus = exports.add = exports.Williams = exports.Vma = exports.
|
|
3
|
+
exports.parseLsusbOutput = exports.isJSON = exports.calculateDivisionFactor = exports.minus = exports.add = exports.Williams = exports.Vma = exports.Week = exports.dateFormat = exports.Rsi = exports.Obv = exports.Macd = exports.Ma = exports.Kd = exports.Gold = exports.Ema = exports.Boll = exports.calcSeasonalIndicesNoTrend = exports.weightMovingAverages = exports.movingAverages = exports.exponentialSmoothing = exports.findTroughByGradient = exports.findPeaksByGradient = exports.SwingExtremesType = exports.SwingExtremes = exports.slope = exports.simpleRegressionModel = exports.Angle = void 0;
|
|
4
4
|
/*
|
|
5
5
|
請注意,在 src/index.ts 中,我的導入包含文件擴展名(.js)。
|
|
6
6
|
如果需要支持 Node.js 和構建工具(ex: webpack),則不需要這樣做。 **因為commonJs默認js副檔名**
|
|
@@ -41,8 +41,8 @@ var rsi_js_1 = require("./stockSkills/rsi.js");
|
|
|
41
41
|
Object.defineProperty(exports, "Rsi", { enumerable: true, get: function () { return rsi_js_1.default; } });
|
|
42
42
|
var dateFormat_js_1 = require("./stockSkills/utils/dateFormat.js");
|
|
43
43
|
Object.defineProperty(exports, "dateFormat", { enumerable: true, get: function () { return dateFormat_js_1.default; } });
|
|
44
|
-
var
|
|
45
|
-
Object.defineProperty(exports, "
|
|
44
|
+
var week_js_1 = require("./stockSkills/week.js");
|
|
45
|
+
Object.defineProperty(exports, "Week", { enumerable: true, get: function () { return week_js_1.default; } });
|
|
46
46
|
var vma_js_1 = require("./stockSkills/vma.js");
|
|
47
47
|
Object.defineProperty(exports, "Vma", { enumerable: true, get: function () { return vma_js_1.default; } });
|
|
48
48
|
var williams_js_1 = require("./stockSkills/williams.js");
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { StockListType } from "./types";
|
|
2
1
|
import { StockType } from "./types";
|
|
2
|
+
type NewStockType = Required<Pick<StockType, 'v'>> & StockType;
|
|
3
|
+
type NewStockListType = NewStockType[];
|
|
3
4
|
export type GetGoldResType = {
|
|
4
5
|
lowestPoint: number;
|
|
5
6
|
highestPoint: number;
|
|
@@ -10,19 +11,19 @@ export type GetGoldResType = {
|
|
|
10
11
|
superWeak: number;
|
|
11
12
|
};
|
|
12
13
|
export type FindHightestResType = {
|
|
13
|
-
[key: string]:
|
|
14
|
+
[key: string]: NewStockType;
|
|
14
15
|
};
|
|
15
16
|
export type FindLowestResType = {
|
|
16
|
-
[key: string]:
|
|
17
|
+
[key: string]: NewStockType;
|
|
17
18
|
};
|
|
18
19
|
interface GoldClassType {
|
|
19
|
-
findHighPoint: (list:
|
|
20
|
-
findLowPoint: (list:
|
|
20
|
+
findHighPoint: (list: NewStockListType) => FindHightestResType;
|
|
21
|
+
findLowPoint: (list: NewStockListType) => FindLowestResType;
|
|
21
22
|
getGold: (highestPoint: number, lowestPoint: number) => GetGoldResType;
|
|
22
23
|
}
|
|
23
24
|
export default class Gold implements GoldClassType {
|
|
24
|
-
findHighPoint(list:
|
|
25
|
-
findLowPoint(list:
|
|
25
|
+
findHighPoint(list: NewStockListType): FindHightestResType;
|
|
26
|
+
findLowPoint(list: NewStockListType): FindLowestResType;
|
|
26
27
|
getGold(highestPoint: number, lowestPoint: number): GetGoldResType;
|
|
27
28
|
}
|
|
28
29
|
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { StockListType, StockType } from "./types";
|
|
2
|
+
type NewStockType = Required<Pick<StockType, 'v'>> & StockType;
|
|
3
|
+
type NewStockListType = NewStockType[];
|
|
2
4
|
type ResObv = {
|
|
3
5
|
obv: number;
|
|
4
|
-
} &
|
|
6
|
+
} & NewStockType;
|
|
5
7
|
export type ObvResType = {
|
|
6
8
|
dataset: StockListType;
|
|
7
9
|
obv: number;
|
|
@@ -11,13 +13,13 @@ export type ObvResType = {
|
|
|
11
13
|
type: number;
|
|
12
14
|
};
|
|
13
15
|
interface ObvType {
|
|
14
|
-
init: (data:
|
|
15
|
-
next: (data:
|
|
16
|
-
getObv: (list:
|
|
16
|
+
init: (data: NewStockType, type: number) => ObvResType;
|
|
17
|
+
next: (data: NewStockType, preList: ObvResType, type: number) => ObvResType;
|
|
18
|
+
getObv: (list: NewStockListType, period: number) => ResObv[];
|
|
17
19
|
}
|
|
18
20
|
export default class Obv implements ObvType {
|
|
19
|
-
init(data:
|
|
20
|
-
next(data:
|
|
21
|
-
getObv(list:
|
|
21
|
+
init(data: NewStockType, type: number): ObvResType;
|
|
22
|
+
next(data: NewStockType, preList: ObvResType, type: number): ObvResType;
|
|
23
|
+
getObv(list: NewStockListType): ResObv[];
|
|
22
24
|
}
|
|
23
25
|
export {};
|
|
@@ -6,7 +6,7 @@ export declare enum Mode {
|
|
|
6
6
|
TimeStampToNumber = 5,
|
|
7
7
|
StringToNumber = 6
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
declare function dateFormat(date:
|
|
9
|
+
type DateFormatInput<M extends Mode> = M extends Mode.NumberToString | Mode.NumberToTimeStamp | Mode.TimeStampToString | Mode.TimeStampToNumber ? number : M extends Mode.StringToTimeStamp | Mode.StringToNumber ? string : never;
|
|
10
|
+
type DateFormatOutput<M extends Mode> = M extends Mode.NumberToString | Mode.TimeStampToString ? string : M extends Mode.NumberToTimeStamp | Mode.StringToTimeStamp | Mode.TimeStampToNumber | Mode.StringToNumber ? number : never;
|
|
11
|
+
declare function dateFormat<M extends Mode>(date: DateFormatInput<M>, mode: M): DateFormatOutput<M>;
|
|
12
12
|
export default dateFormat;
|
|
@@ -13,15 +13,13 @@ var Mode;
|
|
|
13
13
|
function dateFormat(date, mode) {
|
|
14
14
|
switch (mode) {
|
|
15
15
|
case Mode.NumberToString: {
|
|
16
|
-
var input = date.
|
|
17
|
-
|
|
18
|
-
return res;
|
|
16
|
+
var input = String(date).padStart(8, "0");
|
|
17
|
+
return "".concat(input.slice(0, 4), "-").concat(input.slice(4, 6), "-").concat(input.slice(6, 8));
|
|
19
18
|
}
|
|
20
19
|
case Mode.NumberToTimeStamp: {
|
|
21
|
-
var input = date.
|
|
22
|
-
var stringDate = input.slice(0, 4)
|
|
23
|
-
|
|
24
|
-
return res;
|
|
20
|
+
var input = String(date).padStart(8, "0");
|
|
21
|
+
var stringDate = "".concat(input.slice(0, 4), "-").concat(input.slice(4, 6), "-").concat(input.slice(6, 8));
|
|
22
|
+
return new Date(stringDate).getTime();
|
|
25
23
|
}
|
|
26
24
|
case Mode.StringToTimeStamp: {
|
|
27
25
|
var res = Date.parse(date);
|
|
@@ -40,19 +38,16 @@ function dateFormat(date, mode) {
|
|
|
40
38
|
case Mode.TimeStampToNumber: {
|
|
41
39
|
var newDate = new Date(date);
|
|
42
40
|
var yy = newDate.getFullYear();
|
|
43
|
-
var mm = newDate.getMonth() + 1
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var dd = newDate.getDate() < 10 ? "0" + newDate.getDate() : newDate.getDate();
|
|
47
|
-
var res = "".concat(yy).concat(mm).concat(dd);
|
|
48
|
-
return parseInt(res);
|
|
41
|
+
var mm = String(newDate.getMonth() + 1).padStart(2, "0");
|
|
42
|
+
var dd = String(newDate.getDate()).padStart(2, "0");
|
|
43
|
+
return parseInt("".concat(yy).concat(mm).concat(dd), 10);
|
|
49
44
|
}
|
|
50
45
|
case Mode.StringToNumber: {
|
|
51
|
-
var res = date.
|
|
46
|
+
var res = date.replace(/-/g, "");
|
|
52
47
|
return parseInt(res);
|
|
53
48
|
}
|
|
54
49
|
default:
|
|
55
|
-
|
|
50
|
+
throw new Error("请设置正确的模式");
|
|
56
51
|
}
|
|
57
52
|
}
|
|
58
53
|
exports.default = dateFormat;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StockType } from "../types";
|
|
2
|
+
type NewStockType = Required<Pick<StockType, 'v'>> & StockType;
|
|
3
|
+
type NewStockListType = NewStockType[];
|
|
2
4
|
export type ResType = {
|
|
3
|
-
detail?:
|
|
4
|
-
} &
|
|
5
|
-
export default function getWeekLine(list:
|
|
5
|
+
detail?: NewStockListType;
|
|
6
|
+
} & NewStockType;
|
|
7
|
+
export default function getWeekLine(list: NewStockListType, detail: boolean): ResType[];
|
|
8
|
+
export {};
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StockType } from "./types";
|
|
2
|
+
type NewStockType = Required<Pick<StockType, 'v'>> & StockType;
|
|
3
|
+
type NewStockListType = NewStockType[];
|
|
2
4
|
export type VmaResType = {
|
|
3
|
-
dataset:
|
|
5
|
+
dataset: NewStockListType;
|
|
4
6
|
vma: number;
|
|
5
7
|
type: number;
|
|
6
8
|
};
|
|
7
9
|
interface VmaType {
|
|
8
|
-
init: (data:
|
|
9
|
-
next: (data:
|
|
10
|
+
init: (data: NewStockType, type: number) => VmaResType;
|
|
11
|
+
next: (data: NewStockType, preList: VmaResType, type: number) => VmaResType;
|
|
10
12
|
}
|
|
11
13
|
export default class Vma implements VmaType {
|
|
12
|
-
init(data:
|
|
13
|
-
dataset:
|
|
14
|
+
init(data: NewStockType, type: number): {
|
|
15
|
+
dataset: NewStockType[];
|
|
14
16
|
vma: number;
|
|
15
17
|
type: number;
|
|
16
18
|
};
|
|
17
|
-
next(data:
|
|
18
|
-
dataset:
|
|
19
|
+
next(data: NewStockType, preList: VmaResType, type: number): {
|
|
20
|
+
dataset: NewStockListType;
|
|
19
21
|
vma: number;
|
|
20
22
|
type: number;
|
|
21
23
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StockType } from "./types";
|
|
2
|
+
type NewStockType = Required<Pick<StockType, 'v'>> & StockType;
|
|
3
|
+
type NewStockListType = NewStockType[];
|
|
4
|
+
export type WeekResType = {
|
|
5
|
+
dataset: NewStockListType;
|
|
6
|
+
week: NewStockListType;
|
|
7
|
+
};
|
|
8
|
+
interface WeekType {
|
|
9
|
+
init: (data: NewStockType) => WeekResType;
|
|
10
|
+
next: (data: NewStockType, preList: WeekResType) => WeekResType;
|
|
11
|
+
}
|
|
12
|
+
export default class Week implements WeekType {
|
|
13
|
+
init(data: NewStockType): WeekResType;
|
|
14
|
+
next(data: NewStockType, preList: WeekResType): WeekResType;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
var Week = /** @class */ (function () {
|
|
13
|
+
function Week() {
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(Week.prototype, "init", {
|
|
16
|
+
enumerable: false,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: function (data) {
|
|
20
|
+
return { dataset: [data], week: [] };
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(Week.prototype, "next", {
|
|
24
|
+
enumerable: false,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: function (data, preList) {
|
|
28
|
+
var year = data.t
|
|
29
|
+
.toString()
|
|
30
|
+
.replace(/^(\d{4})(\d{2})(\d{2})$/, "$1-$2-$3");
|
|
31
|
+
var day = new Date(year).getDay();
|
|
32
|
+
if (day === 6 || day === 0)
|
|
33
|
+
return { dataset: preList.dataset, week: preList.week };
|
|
34
|
+
preList.dataset.push(data);
|
|
35
|
+
if (day === 5) {
|
|
36
|
+
var week = {
|
|
37
|
+
o: preList.dataset[0]["o"],
|
|
38
|
+
c: preList.dataset[preList.dataset.length - 1]["c"],
|
|
39
|
+
t: preList.dataset[preList.dataset.length - 1]["t"],
|
|
40
|
+
h: Math.max.apply(Math, preList.dataset.map(function (item) { return item.h; })),
|
|
41
|
+
l: Math.min.apply(Math, preList.dataset.map(function (item) { return item.l; })),
|
|
42
|
+
v: preList.dataset.reduce(function (pre, current) { return pre + current.v; }, 0),
|
|
43
|
+
};
|
|
44
|
+
return { dataset: preList.dataset, week: __spreadArray(__spreadArray([], preList.week, true), [week], false) };
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
if (day === 1) {
|
|
48
|
+
preList.dataset = [data];
|
|
49
|
+
}
|
|
50
|
+
return { dataset: preList.dataset, week: preList.week };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return Week;
|
|
55
|
+
}());
|
|
56
|
+
exports.default = Week;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var week_1 = require("./week");
|
|
4
|
+
describe('Week', function () {
|
|
5
|
+
var week;
|
|
6
|
+
beforeEach(function () {
|
|
7
|
+
week = new week_1.default();
|
|
8
|
+
});
|
|
9
|
+
describe('init', function () {
|
|
10
|
+
it('應該正確初始化數據', function () {
|
|
11
|
+
var data = { o: 100, c: 101, h: 102, l: 99, t: 20230501, v: 1000 };
|
|
12
|
+
var result = week.init(data);
|
|
13
|
+
expect(result).toEqual({ dataset: [data], week: [] });
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
describe('next', function () {
|
|
17
|
+
it('應該正確處理非週末的數據', function () {
|
|
18
|
+
var initialData = { o: 100, c: 101, h: 102, l: 99, t: 20230501, v: 1000 };
|
|
19
|
+
var nextData = { o: 101, c: 102, h: 103, l: 100, t: 20230502, v: 1100 };
|
|
20
|
+
var initialResult = week.init(initialData);
|
|
21
|
+
var result = week.next(nextData, initialResult);
|
|
22
|
+
expect(result.dataset).toHaveLength(2);
|
|
23
|
+
expect(result.week).toHaveLength(0);
|
|
24
|
+
});
|
|
25
|
+
it('應該在週五時生成週數據', function () {
|
|
26
|
+
var initialData = { o: 100, c: 101, h: 102, l: 99, t: 20230501, v: 1000 };
|
|
27
|
+
var result = week.init(initialData);
|
|
28
|
+
for (var i = 2; i <= 5; i++) {
|
|
29
|
+
var nextData = { o: 100 + i, c: 101 + i, h: 102 + i, l: 99 + i, t: 20230500 + i, v: 1000 + i * 100 };
|
|
30
|
+
result = week.next(nextData, result);
|
|
31
|
+
}
|
|
32
|
+
expect(result.dataset).toHaveLength(5);
|
|
33
|
+
expect(result.week).toHaveLength(1);
|
|
34
|
+
expect(result.week[0]).toEqual({
|
|
35
|
+
o: 100,
|
|
36
|
+
c: 106,
|
|
37
|
+
h: 107,
|
|
38
|
+
l: 99,
|
|
39
|
+
t: 20230505,
|
|
40
|
+
v: 6400
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
it('應該忽略週末數據', function () {
|
|
44
|
+
var initialData = { o: 100, c: 101, h: 102, l: 99, t: 20230505, v: 1000 };
|
|
45
|
+
var weekendData = { o: 101, c: 102, h: 103, l: 100, t: 20230506, v: 1100 };
|
|
46
|
+
var initialResult = week.init(initialData);
|
|
47
|
+
var result = week.next(weekendData, initialResult);
|
|
48
|
+
expect(result).toEqual(initialResult);
|
|
49
|
+
});
|
|
50
|
+
it('應該在新的一週開始時重置數據集', function () {
|
|
51
|
+
var fridayData = { o: 100, c: 101, h: 102, l: 99, t: 20230505, v: 1000 };
|
|
52
|
+
var mondayData = { o: 101, c: 102, h: 103, l: 100, t: 20230508, v: 1100 };
|
|
53
|
+
var result = week.init(fridayData);
|
|
54
|
+
result = week.next(fridayData, result);
|
|
55
|
+
result = week.next(mondayData, result);
|
|
56
|
+
expect(result.dataset).toHaveLength(1);
|
|
57
|
+
expect(result.dataset[0]).toEqual(mondayData);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export { default as Macd } from "./stockSkills/macd.js";
|
|
|
15
15
|
export { default as Obv } from "./stockSkills/obv.js";
|
|
16
16
|
export { default as Rsi } from "./stockSkills/rsi.js";
|
|
17
17
|
export { default as dateFormat } from "./stockSkills/utils/dateFormat.js";
|
|
18
|
-
export { default as
|
|
18
|
+
export { default as Week } from "./stockSkills/week.js";
|
|
19
19
|
export { default as Vma } from "./stockSkills/vma.js";
|
|
20
20
|
export { default as Williams } from "./stockSkills/williams.js";
|
|
21
21
|
export { add } from "./test/add.js";
|
package/dist/esm/index.js
CHANGED
|
@@ -18,7 +18,7 @@ export { default as Macd } from "./stockSkills/macd.js";
|
|
|
18
18
|
export { default as Obv } from "./stockSkills/obv.js";
|
|
19
19
|
export { default as Rsi } from "./stockSkills/rsi.js";
|
|
20
20
|
export { default as dateFormat } from "./stockSkills/utils/dateFormat.js";
|
|
21
|
-
export { default as
|
|
21
|
+
export { default as Week } from "./stockSkills/week.js";
|
|
22
22
|
export { default as Vma } from "./stockSkills/vma.js";
|
|
23
23
|
export { default as Williams } from "./stockSkills/williams.js";
|
|
24
24
|
export { add } from "./test/add.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { StockListType } from "./types";
|
|
2
1
|
import { StockType } from "./types";
|
|
2
|
+
type NewStockType = Required<Pick<StockType, 'v'>> & StockType;
|
|
3
|
+
type NewStockListType = NewStockType[];
|
|
3
4
|
export type GetGoldResType = {
|
|
4
5
|
lowestPoint: number;
|
|
5
6
|
highestPoint: number;
|
|
@@ -10,19 +11,19 @@ export type GetGoldResType = {
|
|
|
10
11
|
superWeak: number;
|
|
11
12
|
};
|
|
12
13
|
export type FindHightestResType = {
|
|
13
|
-
[key: string]:
|
|
14
|
+
[key: string]: NewStockType;
|
|
14
15
|
};
|
|
15
16
|
export type FindLowestResType = {
|
|
16
|
-
[key: string]:
|
|
17
|
+
[key: string]: NewStockType;
|
|
17
18
|
};
|
|
18
19
|
interface GoldClassType {
|
|
19
|
-
findHighPoint: (list:
|
|
20
|
-
findLowPoint: (list:
|
|
20
|
+
findHighPoint: (list: NewStockListType) => FindHightestResType;
|
|
21
|
+
findLowPoint: (list: NewStockListType) => FindLowestResType;
|
|
21
22
|
getGold: (highestPoint: number, lowestPoint: number) => GetGoldResType;
|
|
22
23
|
}
|
|
23
24
|
export default class Gold implements GoldClassType {
|
|
24
|
-
findHighPoint(list:
|
|
25
|
-
findLowPoint(list:
|
|
25
|
+
findHighPoint(list: NewStockListType): FindHightestResType;
|
|
26
|
+
findLowPoint(list: NewStockListType): FindLowestResType;
|
|
26
27
|
getGold(highestPoint: number, lowestPoint: number): GetGoldResType;
|
|
27
28
|
}
|
|
28
29
|
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { StockListType, StockType } from "./types";
|
|
2
|
+
type NewStockType = Required<Pick<StockType, 'v'>> & StockType;
|
|
3
|
+
type NewStockListType = NewStockType[];
|
|
2
4
|
type ResObv = {
|
|
3
5
|
obv: number;
|
|
4
|
-
} &
|
|
6
|
+
} & NewStockType;
|
|
5
7
|
export type ObvResType = {
|
|
6
8
|
dataset: StockListType;
|
|
7
9
|
obv: number;
|
|
@@ -11,13 +13,13 @@ export type ObvResType = {
|
|
|
11
13
|
type: number;
|
|
12
14
|
};
|
|
13
15
|
interface ObvType {
|
|
14
|
-
init: (data:
|
|
15
|
-
next: (data:
|
|
16
|
-
getObv: (list:
|
|
16
|
+
init: (data: NewStockType, type: number) => ObvResType;
|
|
17
|
+
next: (data: NewStockType, preList: ObvResType, type: number) => ObvResType;
|
|
18
|
+
getObv: (list: NewStockListType, period: number) => ResObv[];
|
|
17
19
|
}
|
|
18
20
|
export default class Obv implements ObvType {
|
|
19
|
-
init(data:
|
|
20
|
-
next(data:
|
|
21
|
-
getObv(list:
|
|
21
|
+
init(data: NewStockType, type: number): ObvResType;
|
|
22
|
+
next(data: NewStockType, preList: ObvResType, type: number): ObvResType;
|
|
23
|
+
getObv(list: NewStockListType): ResObv[];
|
|
22
24
|
}
|
|
23
25
|
export {};
|
|
@@ -6,7 +6,7 @@ export declare enum Mode {
|
|
|
6
6
|
TimeStampToNumber = 5,
|
|
7
7
|
StringToNumber = 6
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
declare function dateFormat(date:
|
|
9
|
+
type DateFormatInput<M extends Mode> = M extends Mode.NumberToString | Mode.NumberToTimeStamp | Mode.TimeStampToString | Mode.TimeStampToNumber ? number : M extends Mode.StringToTimeStamp | Mode.StringToNumber ? string : never;
|
|
10
|
+
type DateFormatOutput<M extends Mode> = M extends Mode.NumberToString | Mode.TimeStampToString ? string : M extends Mode.NumberToTimeStamp | Mode.StringToTimeStamp | Mode.TimeStampToNumber | Mode.StringToNumber ? number : never;
|
|
11
|
+
declare function dateFormat<M extends Mode>(date: DateFormatInput<M>, mode: M): DateFormatOutput<M>;
|
|
12
12
|
export default dateFormat;
|
|
@@ -10,15 +10,13 @@ export var Mode;
|
|
|
10
10
|
function dateFormat(date, mode) {
|
|
11
11
|
switch (mode) {
|
|
12
12
|
case Mode.NumberToString: {
|
|
13
|
-
var input = date.
|
|
14
|
-
|
|
15
|
-
return res;
|
|
13
|
+
var input = String(date).padStart(8, "0");
|
|
14
|
+
return "".concat(input.slice(0, 4), "-").concat(input.slice(4, 6), "-").concat(input.slice(6, 8));
|
|
16
15
|
}
|
|
17
16
|
case Mode.NumberToTimeStamp: {
|
|
18
|
-
var input = date.
|
|
19
|
-
var stringDate = input.slice(0, 4)
|
|
20
|
-
|
|
21
|
-
return res;
|
|
17
|
+
var input = String(date).padStart(8, "0");
|
|
18
|
+
var stringDate = "".concat(input.slice(0, 4), "-").concat(input.slice(4, 6), "-").concat(input.slice(6, 8));
|
|
19
|
+
return new Date(stringDate).getTime();
|
|
22
20
|
}
|
|
23
21
|
case Mode.StringToTimeStamp: {
|
|
24
22
|
var res = Date.parse(date);
|
|
@@ -37,19 +35,16 @@ function dateFormat(date, mode) {
|
|
|
37
35
|
case Mode.TimeStampToNumber: {
|
|
38
36
|
var newDate = new Date(date);
|
|
39
37
|
var yy = newDate.getFullYear();
|
|
40
|
-
var mm = newDate.getMonth() + 1
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var dd = newDate.getDate() < 10 ? "0" + newDate.getDate() : newDate.getDate();
|
|
44
|
-
var res = "".concat(yy).concat(mm).concat(dd);
|
|
45
|
-
return parseInt(res);
|
|
38
|
+
var mm = String(newDate.getMonth() + 1).padStart(2, "0");
|
|
39
|
+
var dd = String(newDate.getDate()).padStart(2, "0");
|
|
40
|
+
return parseInt("".concat(yy).concat(mm).concat(dd), 10);
|
|
46
41
|
}
|
|
47
42
|
case Mode.StringToNumber: {
|
|
48
|
-
var res = date.
|
|
43
|
+
var res = date.replace(/-/g, "");
|
|
49
44
|
return parseInt(res);
|
|
50
45
|
}
|
|
51
46
|
default:
|
|
52
|
-
|
|
47
|
+
throw new Error("请设置正确的模式");
|
|
53
48
|
}
|
|
54
49
|
}
|
|
55
50
|
export default dateFormat;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StockType } from "../types";
|
|
2
|
+
type NewStockType = Required<Pick<StockType, 'v'>> & StockType;
|
|
3
|
+
type NewStockListType = NewStockType[];
|
|
2
4
|
export type ResType = {
|
|
3
|
-
detail?:
|
|
4
|
-
} &
|
|
5
|
-
export default function getWeekLine(list:
|
|
5
|
+
detail?: NewStockListType;
|
|
6
|
+
} & NewStockType;
|
|
7
|
+
export default function getWeekLine(list: NewStockListType, detail: boolean): ResType[];
|
|
8
|
+
export {};
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StockType } from "./types";
|
|
2
|
+
type NewStockType = Required<Pick<StockType, 'v'>> & StockType;
|
|
3
|
+
type NewStockListType = NewStockType[];
|
|
2
4
|
export type VmaResType = {
|
|
3
|
-
dataset:
|
|
5
|
+
dataset: NewStockListType;
|
|
4
6
|
vma: number;
|
|
5
7
|
type: number;
|
|
6
8
|
};
|
|
7
9
|
interface VmaType {
|
|
8
|
-
init: (data:
|
|
9
|
-
next: (data:
|
|
10
|
+
init: (data: NewStockType, type: number) => VmaResType;
|
|
11
|
+
next: (data: NewStockType, preList: VmaResType, type: number) => VmaResType;
|
|
10
12
|
}
|
|
11
13
|
export default class Vma implements VmaType {
|
|
12
|
-
init(data:
|
|
13
|
-
dataset:
|
|
14
|
+
init(data: NewStockType, type: number): {
|
|
15
|
+
dataset: NewStockType[];
|
|
14
16
|
vma: number;
|
|
15
17
|
type: number;
|
|
16
18
|
};
|
|
17
|
-
next(data:
|
|
18
|
-
dataset:
|
|
19
|
+
next(data: NewStockType, preList: VmaResType, type: number): {
|
|
20
|
+
dataset: NewStockListType;
|
|
19
21
|
vma: number;
|
|
20
22
|
type: number;
|
|
21
23
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StockType } from "./types";
|
|
2
|
+
type NewStockType = Required<Pick<StockType, 'v'>> & StockType;
|
|
3
|
+
type NewStockListType = NewStockType[];
|
|
4
|
+
export type WeekResType = {
|
|
5
|
+
dataset: NewStockListType;
|
|
6
|
+
week: NewStockListType;
|
|
7
|
+
};
|
|
8
|
+
interface WeekType {
|
|
9
|
+
init: (data: NewStockType) => WeekResType;
|
|
10
|
+
next: (data: NewStockType, preList: WeekResType) => WeekResType;
|
|
11
|
+
}
|
|
12
|
+
export default class Week implements WeekType {
|
|
13
|
+
init(data: NewStockType): WeekResType;
|
|
14
|
+
next(data: NewStockType, preList: WeekResType): WeekResType;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
2
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3
|
+
if (ar || !(i in from)) {
|
|
4
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
5
|
+
ar[i] = from[i];
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
|
+
};
|
|
10
|
+
var Week = /** @class */ (function () {
|
|
11
|
+
function Week() {
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(Week.prototype, "init", {
|
|
14
|
+
enumerable: false,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: function (data) {
|
|
18
|
+
return { dataset: [data], week: [] };
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(Week.prototype, "next", {
|
|
22
|
+
enumerable: false,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: function (data, preList) {
|
|
26
|
+
var year = data.t
|
|
27
|
+
.toString()
|
|
28
|
+
.replace(/^(\d{4})(\d{2})(\d{2})$/, "$1-$2-$3");
|
|
29
|
+
var day = new Date(year).getDay();
|
|
30
|
+
if (day === 6 || day === 0)
|
|
31
|
+
return { dataset: preList.dataset, week: preList.week };
|
|
32
|
+
preList.dataset.push(data);
|
|
33
|
+
if (day === 5) {
|
|
34
|
+
var week = {
|
|
35
|
+
o: preList.dataset[0]["o"],
|
|
36
|
+
c: preList.dataset[preList.dataset.length - 1]["c"],
|
|
37
|
+
t: preList.dataset[preList.dataset.length - 1]["t"],
|
|
38
|
+
h: Math.max.apply(Math, preList.dataset.map(function (item) { return item.h; })),
|
|
39
|
+
l: Math.min.apply(Math, preList.dataset.map(function (item) { return item.l; })),
|
|
40
|
+
v: preList.dataset.reduce(function (pre, current) { return pre + current.v; }, 0),
|
|
41
|
+
};
|
|
42
|
+
return { dataset: preList.dataset, week: __spreadArray(__spreadArray([], preList.week, true), [week], false) };
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
if (day === 1) {
|
|
46
|
+
preList.dataset = [data];
|
|
47
|
+
}
|
|
48
|
+
return { dataset: preList.dataset, week: preList.week };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return Week;
|
|
53
|
+
}());
|
|
54
|
+
export default Week;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import Week from './week';
|
|
2
|
+
describe('Week', function () {
|
|
3
|
+
var week;
|
|
4
|
+
beforeEach(function () {
|
|
5
|
+
week = new Week();
|
|
6
|
+
});
|
|
7
|
+
describe('init', function () {
|
|
8
|
+
it('應該正確初始化數據', function () {
|
|
9
|
+
var data = { o: 100, c: 101, h: 102, l: 99, t: 20230501, v: 1000 };
|
|
10
|
+
var result = week.init(data);
|
|
11
|
+
expect(result).toEqual({ dataset: [data], week: [] });
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
describe('next', function () {
|
|
15
|
+
it('應該正確處理非週末的數據', function () {
|
|
16
|
+
var initialData = { o: 100, c: 101, h: 102, l: 99, t: 20230501, v: 1000 };
|
|
17
|
+
var nextData = { o: 101, c: 102, h: 103, l: 100, t: 20230502, v: 1100 };
|
|
18
|
+
var initialResult = week.init(initialData);
|
|
19
|
+
var result = week.next(nextData, initialResult);
|
|
20
|
+
expect(result.dataset).toHaveLength(2);
|
|
21
|
+
expect(result.week).toHaveLength(0);
|
|
22
|
+
});
|
|
23
|
+
it('應該在週五時生成週數據', function () {
|
|
24
|
+
var initialData = { o: 100, c: 101, h: 102, l: 99, t: 20230501, v: 1000 };
|
|
25
|
+
var result = week.init(initialData);
|
|
26
|
+
for (var i = 2; i <= 5; i++) {
|
|
27
|
+
var nextData = { o: 100 + i, c: 101 + i, h: 102 + i, l: 99 + i, t: 20230500 + i, v: 1000 + i * 100 };
|
|
28
|
+
result = week.next(nextData, result);
|
|
29
|
+
}
|
|
30
|
+
expect(result.dataset).toHaveLength(5);
|
|
31
|
+
expect(result.week).toHaveLength(1);
|
|
32
|
+
expect(result.week[0]).toEqual({
|
|
33
|
+
o: 100,
|
|
34
|
+
c: 106,
|
|
35
|
+
h: 107,
|
|
36
|
+
l: 99,
|
|
37
|
+
t: 20230505,
|
|
38
|
+
v: 6400
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
it('應該忽略週末數據', function () {
|
|
42
|
+
var initialData = { o: 100, c: 101, h: 102, l: 99, t: 20230505, v: 1000 };
|
|
43
|
+
var weekendData = { o: 101, c: 102, h: 103, l: 100, t: 20230506, v: 1100 };
|
|
44
|
+
var initialResult = week.init(initialData);
|
|
45
|
+
var result = week.next(weekendData, initialResult);
|
|
46
|
+
expect(result).toEqual(initialResult);
|
|
47
|
+
});
|
|
48
|
+
it('應該在新的一週開始時重置數據集', function () {
|
|
49
|
+
var fridayData = { o: 100, c: 101, h: 102, l: 99, t: 20230505, v: 1000 };
|
|
50
|
+
var mondayData = { o: 101, c: 102, h: 103, l: 100, t: 20230508, v: 1100 };
|
|
51
|
+
var result = week.init(fridayData);
|
|
52
|
+
result = week.next(fridayData, result);
|
|
53
|
+
result = week.next(mondayData, result);
|
|
54
|
+
expect(result.dataset).toHaveLength(1);
|
|
55
|
+
expect(result.dataset[0]).toEqual(mondayData);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
package/dist/umd/index.js
CHANGED
|
@@ -1295,7 +1295,7 @@
|
|
|
1295
1295
|
};
|
|
1296
1296
|
return __assign$2.apply(this, arguments);
|
|
1297
1297
|
};
|
|
1298
|
-
var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from, pack) {
|
|
1298
|
+
var __spreadArray$1 = (undefined && undefined.__spreadArray) || function (to, from, pack) {
|
|
1299
1299
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
1300
1300
|
if (ar || !(i in from)) {
|
|
1301
1301
|
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
@@ -1345,7 +1345,7 @@
|
|
|
1345
1345
|
var sum = obvList.reduce(function (pre, current) { return pre + current; }, 0);
|
|
1346
1346
|
var vma = Math.round((sum / type) * 100) / 100;
|
|
1347
1347
|
return {
|
|
1348
|
-
dataset: __spreadArray(__spreadArray([], preList.dataset, true), [data], false),
|
|
1348
|
+
dataset: __spreadArray$1(__spreadArray$1([], preList.dataset, true), [data], false),
|
|
1349
1349
|
obv: obv,
|
|
1350
1350
|
preClose: currentClose,
|
|
1351
1351
|
obvList: obvList,
|
|
@@ -1517,15 +1517,13 @@
|
|
|
1517
1517
|
function dateFormat(date, mode) {
|
|
1518
1518
|
switch (mode) {
|
|
1519
1519
|
case Mode.NumberToString: {
|
|
1520
|
-
var input = date.
|
|
1521
|
-
|
|
1522
|
-
return res;
|
|
1520
|
+
var input = String(date).padStart(8, "0");
|
|
1521
|
+
return "".concat(input.slice(0, 4), "-").concat(input.slice(4, 6), "-").concat(input.slice(6, 8));
|
|
1523
1522
|
}
|
|
1524
1523
|
case Mode.NumberToTimeStamp: {
|
|
1525
|
-
var input = date.
|
|
1526
|
-
var stringDate = input.slice(0, 4)
|
|
1527
|
-
|
|
1528
|
-
return res;
|
|
1524
|
+
var input = String(date).padStart(8, "0");
|
|
1525
|
+
var stringDate = "".concat(input.slice(0, 4), "-").concat(input.slice(4, 6), "-").concat(input.slice(6, 8));
|
|
1526
|
+
return new Date(stringDate).getTime();
|
|
1529
1527
|
}
|
|
1530
1528
|
case Mode.StringToTimeStamp: {
|
|
1531
1529
|
var res = Date.parse(date);
|
|
@@ -1544,22 +1542,73 @@
|
|
|
1544
1542
|
case Mode.TimeStampToNumber: {
|
|
1545
1543
|
var newDate = new Date(date);
|
|
1546
1544
|
var yy = newDate.getFullYear();
|
|
1547
|
-
var mm = newDate.getMonth() + 1
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
var dd = newDate.getDate() < 10 ? "0" + newDate.getDate() : newDate.getDate();
|
|
1551
|
-
var res = "".concat(yy).concat(mm).concat(dd);
|
|
1552
|
-
return parseInt(res);
|
|
1545
|
+
var mm = String(newDate.getMonth() + 1).padStart(2, "0");
|
|
1546
|
+
var dd = String(newDate.getDate()).padStart(2, "0");
|
|
1547
|
+
return parseInt("".concat(yy).concat(mm).concat(dd), 10);
|
|
1553
1548
|
}
|
|
1554
1549
|
case Mode.StringToNumber: {
|
|
1555
|
-
var res = date.
|
|
1550
|
+
var res = date.replace(/-/g, "");
|
|
1556
1551
|
return parseInt(res);
|
|
1557
1552
|
}
|
|
1558
1553
|
default:
|
|
1559
|
-
|
|
1554
|
+
throw new Error("请设置正确的模式");
|
|
1560
1555
|
}
|
|
1561
1556
|
}
|
|
1562
1557
|
|
|
1558
|
+
var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from, pack) {
|
|
1559
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
1560
|
+
if (ar || !(i in from)) {
|
|
1561
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
1562
|
+
ar[i] = from[i];
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
1566
|
+
};
|
|
1567
|
+
var Week = /** @class */ (function () {
|
|
1568
|
+
function Week() {
|
|
1569
|
+
}
|
|
1570
|
+
Object.defineProperty(Week.prototype, "init", {
|
|
1571
|
+
enumerable: false,
|
|
1572
|
+
configurable: true,
|
|
1573
|
+
writable: true,
|
|
1574
|
+
value: function (data) {
|
|
1575
|
+
return { dataset: [data], week: [] };
|
|
1576
|
+
}
|
|
1577
|
+
});
|
|
1578
|
+
Object.defineProperty(Week.prototype, "next", {
|
|
1579
|
+
enumerable: false,
|
|
1580
|
+
configurable: true,
|
|
1581
|
+
writable: true,
|
|
1582
|
+
value: function (data, preList) {
|
|
1583
|
+
var year = data.t
|
|
1584
|
+
.toString()
|
|
1585
|
+
.replace(/^(\d{4})(\d{2})(\d{2})$/, "$1-$2-$3");
|
|
1586
|
+
var day = new Date(year).getDay();
|
|
1587
|
+
if (day === 6 || day === 0)
|
|
1588
|
+
return { dataset: preList.dataset, week: preList.week };
|
|
1589
|
+
preList.dataset.push(data);
|
|
1590
|
+
if (day === 5) {
|
|
1591
|
+
var week = {
|
|
1592
|
+
o: preList.dataset[0]["o"],
|
|
1593
|
+
c: preList.dataset[preList.dataset.length - 1]["c"],
|
|
1594
|
+
t: preList.dataset[preList.dataset.length - 1]["t"],
|
|
1595
|
+
h: Math.max.apply(Math, preList.dataset.map(function (item) { return item.h; })),
|
|
1596
|
+
l: Math.min.apply(Math, preList.dataset.map(function (item) { return item.l; })),
|
|
1597
|
+
v: preList.dataset.reduce(function (pre, current) { return pre + current.v; }, 0),
|
|
1598
|
+
};
|
|
1599
|
+
return { dataset: preList.dataset, week: __spreadArray(__spreadArray([], preList.week, true), [week], false) };
|
|
1600
|
+
}
|
|
1601
|
+
else {
|
|
1602
|
+
if (day === 1) {
|
|
1603
|
+
preList.dataset = [data];
|
|
1604
|
+
}
|
|
1605
|
+
return { dataset: preList.dataset, week: preList.week };
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
});
|
|
1609
|
+
return Week;
|
|
1610
|
+
}());
|
|
1611
|
+
|
|
1563
1612
|
var Vma = /** @class */ (function () {
|
|
1564
1613
|
function Vma() {
|
|
1565
1614
|
}
|
|
@@ -1751,6 +1800,7 @@
|
|
|
1751
1800
|
exports.Rsi = Rsi;
|
|
1752
1801
|
exports.SwingExtremes = SwingExtremes;
|
|
1753
1802
|
exports.Vma = Vma;
|
|
1803
|
+
exports.Week = Week;
|
|
1754
1804
|
exports.Williams = Williams;
|
|
1755
1805
|
exports.add = add;
|
|
1756
1806
|
exports.calcSeasonalIndicesNoTrend = calcSeasonalIndicesNoTrend;
|
|
@@ -1759,7 +1809,6 @@
|
|
|
1759
1809
|
exports.exponentialSmoothing = exponentialSmoothing;
|
|
1760
1810
|
exports.findPeaksByGradient = findPeaksByGradient;
|
|
1761
1811
|
exports.findTroughByGradient = findTroughByGradient;
|
|
1762
|
-
exports.getWeekLine = getWeekLine;
|
|
1763
1812
|
exports.isJSON = isJSON;
|
|
1764
1813
|
exports.minus = minus;
|
|
1765
1814
|
exports.movingAverages = movingAverages;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ch20026103/anysis",
|
|
3
|
-
"version": "0.0.16-
|
|
3
|
+
"version": "0.0.16-beta1",
|
|
4
4
|
"description": "provide many analyze methods in the library.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"bugs": "git@github.com:cosmic1330/anysis/issues",
|
|
@@ -12,21 +12,6 @@
|
|
|
12
12
|
"module": "dist/esm/index.js",
|
|
13
13
|
"browser": "dist/umd/index.js",
|
|
14
14
|
"types": "dist/esm/index.d.ts",
|
|
15
|
-
"scripts": {
|
|
16
|
-
"build": "pnpm clean && pnpm build:esm && pnpm build:cjs && pnpm build:umd",
|
|
17
|
-
"build:cjs": "tsc --module commonjs --target es5 --outDir dist/cjs",
|
|
18
|
-
"build:esm": "tsc --module esnext --target es5 --outDir dist/esm",
|
|
19
|
-
"build:umd": "rollup dist/esm/index.js --file dist/umd/index.js --format umd --name anysis",
|
|
20
|
-
"clean": "rimraf dist",
|
|
21
|
-
"lint": "eslint --fix \"**/*.{js,jsx,ts,tsx,mjs}\"",
|
|
22
|
-
"prepare": "pnpm exec husky install",
|
|
23
|
-
"prettier": "pnpm exec prettier --write .",
|
|
24
|
-
"prepublishOnly": "pnpm build",
|
|
25
|
-
"published": "npm publish",
|
|
26
|
-
"unpublished": "npm unpublish --force --registry http://localhost:4873 ",
|
|
27
|
-
"test": "vitest",
|
|
28
|
-
"demo": "node demo/main.js"
|
|
29
|
-
},
|
|
30
15
|
"lint-staged": {
|
|
31
16
|
"*.{js,jsx,ts,tsx,mjs}": [
|
|
32
17
|
"pnpm lint"
|
|
@@ -57,5 +42,18 @@
|
|
|
57
42
|
},
|
|
58
43
|
"vota": {
|
|
59
44
|
"node": "16.11.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "pnpm clean && pnpm build:esm && pnpm build:cjs && pnpm build:umd",
|
|
48
|
+
"build:cjs": "tsc --module commonjs --target es5 --outDir dist/cjs",
|
|
49
|
+
"build:esm": "tsc --module esnext --target es5 --outDir dist/esm",
|
|
50
|
+
"build:umd": "rollup dist/esm/index.js --file dist/umd/index.js --format umd --name anysis",
|
|
51
|
+
"clean": "rimraf dist",
|
|
52
|
+
"lint": "eslint --fix \"**/*.{js,jsx,ts,tsx,mjs}\"",
|
|
53
|
+
"prettier": "pnpm exec prettier --write .",
|
|
54
|
+
"published": "npm publish",
|
|
55
|
+
"unpublished": "npm unpublish --force --registry http://localhost:4873 ",
|
|
56
|
+
"test": "vitest",
|
|
57
|
+
"demo": "node demo/main.js"
|
|
60
58
|
}
|
|
61
|
-
}
|
|
59
|
+
}
|