@watsonserve/stock-base 0.0.21 → 0.0.23

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/close-time.js CHANGED
@@ -2,6 +2,7 @@ import { EnMarket } from './stock.js';
2
2
  export const A_MIN_MS = 60000;
3
3
  export const A_HOUR_MS = 3600000;
4
4
  export const A_DAY_MS = 86400000;
5
+ export const A_DAY_S = 86400;
5
6
  // 夏令时:3月最后一个周日凌晨1AM开始夏令时,10月最后一个周日凌晨2AM结束夏令时
6
7
  function isDST_ByUK(timestamp) {
7
8
  const date = new Date(timestamp);
package/helper.js CHANGED
@@ -11,6 +11,17 @@ export function splitFullNc(fullNc) {
11
11
  }[fullNc.substring(fullNc.length - 2)];
12
12
  return { nc, market };
13
13
  }
14
+ export function groupBy(key, list, delKey = false) {
15
+ return list.reduce((pre, item) => {
16
+ const foo = item[key];
17
+ const fooList = pre[foo] || [];
18
+ pre[foo] = fooList;
19
+ if (delKey)
20
+ delete item[key];
21
+ fooList.push(item);
22
+ return pre;
23
+ }, {});
24
+ }
14
25
  export function ttm(by, list) {
15
26
  if (!Array.isArray(list) || !list.length)
16
27
  return [];
package/index.js CHANGED
@@ -1,8 +1,8 @@
1
+ import { A_DAY_S } from './close-time.js';
1
2
  import { DividendLoader } from './dividend-loader.js';
2
3
  export * from './stock.js';
3
4
  export * from './log.js';
4
- export { ttm, sleep, splitFullNc } from './helper.js';
5
- const A_DAY_S = 86400;
5
+ export * from './helper.js';
6
6
  function parseUTCDate(str) {
7
7
  return ~~(Date.UTC(+str.slice(0, 4), +str.slice(4, 6) - 1, +str.slice(6, 8)) / 1000);
8
8
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@watsonserve/stock-base",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
7
  "types": "./types/index.d.ts",
8
8
  "scripts": {
9
- "build": "tsc && node ./build.mjs"
9
+ "build": "rm -rf ./dist && tsc && node ./build.mjs"
10
10
  },
11
11
  "keywords": [],
12
12
  "author": "",
@@ -2,6 +2,7 @@ import { EnMarket } from './stock.js';
2
2
  export declare const A_MIN_MS = 60000;
3
3
  export declare const A_HOUR_MS = 3600000;
4
4
  export declare const A_DAY_MS = 86400000;
5
+ export declare const A_DAY_S = 86400;
5
6
  /**
6
7
  * 获取市场收盘时间戳,单位秒
7
8
  * @param market 市场
@@ -1,5 +1,5 @@
1
1
  import PriceLoader from './price-loader.js';
2
- import { type IDiv } from './helper.js';
2
+ import { type IDiv } from './stock.js';
3
3
  export declare class DividendLoader extends PriceLoader {
4
4
  private __laodIbmCode;
5
5
  private __loadHKDividend;
package/types/helper.d.ts CHANGED
@@ -4,12 +4,5 @@ export declare function splitFullNc(fullNc: string): {
4
4
  nc: string;
5
5
  market: EnMarket | undefined;
6
6
  };
7
- export interface IDiv {
8
- nc: string;
9
- annc: number;
10
- ex: number;
11
- paid: number;
12
- currency: string;
13
- amount: number;
14
- }
7
+ export declare function groupBy<T extends Record<string, any>>(key: string, list: T[], delKey?: boolean): Record<string, T[]>;
15
8
  export declare function ttm<T>(by: string, list: any[]): T[];
package/types/index.d.ts CHANGED
@@ -1,13 +1,8 @@
1
1
  import { DividendLoader } from './dividend-loader.js';
2
+ import { IHoliday } from './stock.js';
2
3
  export * from './stock.js';
3
4
  export * from './log.js';
4
- export { type IDiv, ttm, sleep, splitFullNc } from './helper.js';
5
- export interface IHoliday {
6
- market: string;
7
- title: string;
8
- start: number;
9
- end: number;
10
- }
5
+ export * from './helper.js';
11
6
  export declare class StockLoader extends DividendLoader {
12
7
  loadHolidaysSG(year: number): Promise<IHoliday[]>;
13
8
  loadHolidaysHK(): Promise<IHoliday[]>;
package/types/stock.d.ts CHANGED
@@ -38,7 +38,7 @@ export interface StockPoint {
38
38
  st: IStock;
39
39
  }
40
40
  export interface IDividend {
41
- curr: string;
41
+ currency: string;
42
42
  amount?: number;
43
43
  ratio?: number;
44
44
  annc: Date;
@@ -46,6 +46,20 @@ export interface IDividend {
46
46
  paid: Date;
47
47
  announcement_URL?: string;
48
48
  }
49
+ export interface IDiv {
50
+ nc: string;
51
+ annc: number;
52
+ ex: number;
53
+ paid: number;
54
+ currency: string;
55
+ amount: number;
56
+ }
57
+ export interface IHoliday {
58
+ market: string;
59
+ title: string;
60
+ start: number;
61
+ end: number;
62
+ }
49
63
  export declare class Stock {
50
64
  nc: string;
51
65
  name: string;