@watsonserve/stock-base 0.0.21 → 0.0.22

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/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/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@watsonserve/stock-base",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
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": "",
package/types/helper.d.ts CHANGED
@@ -1,9 +1,4 @@
1
1
  import { EnMarket } from './stock.js';
2
- export declare function sleep(t?: number): Promise<unknown>;
3
- export declare function splitFullNc(fullNc: string): {
4
- nc: string;
5
- market: EnMarket | undefined;
6
- };
7
2
  export interface IDiv {
8
3
  nc: string;
9
4
  annc: number;
@@ -12,4 +7,10 @@ export interface IDiv {
12
7
  currency: string;
13
8
  amount: number;
14
9
  }
10
+ export declare function sleep(t?: number): Promise<unknown>;
11
+ export declare function splitFullNc(fullNc: string): {
12
+ nc: string;
13
+ market: EnMarket | undefined;
14
+ };
15
+ export declare function groupBy<T extends Record<string, any>>(key: string, list: T[], delKey?: boolean): Record<string, T[]>;
15
16
  export declare function ttm<T>(by: string, list: any[]): T[];