@vope/utils 1.4.14 → 1.4.15

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/cjs/index.js CHANGED
@@ -530,6 +530,16 @@ var MemorySimple = class {
530
530
  this.#memory.forEach(callback);
531
531
  return this;
532
532
  }
533
+ /**
534
+ * map(按入栈顺序)
535
+ */
536
+ map(callback) {
537
+ const list = [];
538
+ this.#memory.forEach((data, index) => {
539
+ list.push(callback(data, index));
540
+ });
541
+ return list;
542
+ }
533
543
  /**
534
544
  * 获取指定类型存储数据
535
545
  */
@@ -43,6 +43,16 @@ class MemorySimple {
43
43
  this.#memory.forEach(callback);
44
44
  return this;
45
45
  }
46
+ /**
47
+ * map(按入栈顺序)
48
+ */
49
+ map(callback) {
50
+ const list = [];
51
+ this.#memory.forEach((data, index) => {
52
+ list.push(callback(data, index));
53
+ });
54
+ return list;
55
+ }
46
56
  /**
47
57
  * 获取指定类型存储数据
48
58
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vope/utils",
3
- "version": "1.4.14",
3
+ "version": "1.4.15",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -16,10 +16,10 @@ export type _LV<T> = (T | _LV<T>)[];
16
16
  /**
17
17
  * 分类存储(通过继承,可用于拓展存储方式)
18
18
  */
19
- export declare class MemoryBasic<V, Reactor, Type extends Memory.Type> {
19
+ export declare class MemoryBasic<T, Reactor, Type extends Memory.Type> {
20
20
  #private;
21
- protected key: Memory.Pitch<V, Type>;
22
- protected list: V[];
21
+ protected key: Memory.Pitch<T, Type>;
22
+ protected list: T[];
23
23
  protected memorys: Map<Type, Reactor>;
24
24
  /**
25
25
  * 返回存储长度
@@ -29,17 +29,17 @@ export declare class MemoryBasic<V, Reactor, Type extends Memory.Type> {
29
29
  * @param key 用于对数据进行分类的key
30
30
  * @param config
31
31
  */
32
- constructor(key: Memory.Pitch<V, Type>, config: Config<Reactor>);
33
- protected getType(data: V): Type;
34
- push(...list: _LV<V>): this;
32
+ constructor(key: Memory.Pitch<T, Type>, config: Config<Reactor>);
33
+ protected getType(data: T): Type;
34
+ push(...list: _LV<T>): this;
35
35
  /**
36
36
  * 遍历所有存储数据(按入栈顺序)
37
37
  */
38
- forEach(callback: (data: V, index: number) => void): this;
38
+ forEach(callback: (data: T, index: number) => void): this;
39
39
  /**
40
40
  * 遍历所有存储类型
41
41
  */
42
- forType(callback: (data: V[], type: Type) => void): this;
42
+ forType(callback: (data: T[], type: Type) => void): this;
43
43
  /**
44
44
  * 检测存储是否包含某种类型
45
45
  */
@@ -47,11 +47,11 @@ export declare class MemoryBasic<V, Reactor, Type extends Memory.Type> {
47
47
  /**
48
48
  * 获取指定类型存储数据
49
49
  */
50
- get(type: Type): V[] | null;
50
+ get(type: Type): T[] | null;
51
51
  /**
52
52
  * 删除指定存储数据
53
53
  */
54
- delete(data: V): this;
54
+ delete(data: T): this;
55
55
  /**
56
56
  * 删除指定类型存储数据
57
57
  */
@@ -3,6 +3,6 @@ import { Memory } from './type';
3
3
  /**
4
4
  * 分类存储(基于普通的键值存储)
5
5
  */
6
- export declare class MemoryList<V, Type extends Memory.Type = Memory.Type> extends MemoryBasic<V, number[], Type> {
7
- constructor(key: Memory.Pitch<V, Type>);
6
+ export declare class MemoryList<T, Type extends Memory.Type = Memory.Type> extends MemoryBasic<T, number[], Type> {
7
+ constructor(key: Memory.Pitch<T, Type>);
8
8
  }
@@ -3,6 +3,6 @@ import { Memory } from './type';
3
3
  /**
4
4
  * 分类存储(基于2的n次幂之和构建唯一键进行存储)
5
5
  */
6
- export declare class MemoryPower<V, Type extends Memory.Type = Memory.Type> extends MemoryBasic<V, number, Type> {
7
- constructor(key: Memory.Pitch<V, Type>);
6
+ export declare class MemoryPower<T, Type extends Memory.Type = Memory.Type> extends MemoryBasic<T, number, Type> {
7
+ constructor(key: Memory.Pitch<T, Type>);
8
8
  }
@@ -1,9 +1,16 @@
1
- import { _LV } from './basic';
1
+ import { Assign } from '@vope/types';
2
+ import { MemoryBasic, _LV } from './basic';
2
3
  import { Memory } from './type';
4
+ type Transform<T, V> = {
5
+ [P in keyof T]: T[P] extends (...args: any) => any ? (...args: Parameters<T[P]>) => ReturnType<T[P]> extends T ? V : ReturnType<T[P]> : T[P];
6
+ };
7
+ type Basic<T, V, Type extends Memory.Type> = Assign<Transform<Omit<MemoryBasic<T, V, Type>, 'forType'>, MemorySimple<T, Type>>, {
8
+ get(type: Type): T | null;
9
+ }>;
3
10
  /**
4
11
  * 简易存储(不分类)
5
12
  */
6
- export declare class MemorySimple<T, Type extends Memory.Type> {
13
+ export declare class MemorySimple<T, Type extends Memory.Type> implements Basic<T, number, Type> {
7
14
  #private;
8
15
  get size(): number;
9
16
  constructor(key: Memory.Pitch<T, Type>);
@@ -16,6 +23,10 @@ export declare class MemorySimple<T, Type extends Memory.Type> {
16
23
  * 遍历所有存储数据(按入栈顺序)
17
24
  */
18
25
  forEach(callback: (data: T, index: number) => void): this;
26
+ /**
27
+ * map(按入栈顺序)
28
+ */
29
+ map<V>(callback: (data: T, index: number) => V): V[];
19
30
  /**
20
31
  * 获取指定类型存储数据
21
32
  */
@@ -33,3 +44,4 @@ export declare class MemorySimple<T, Type extends Memory.Type> {
33
44
  */
34
45
  clear(): void;
35
46
  }
47
+ export {};