@vope/utils 1.4.14 → 1.4.16
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 +16 -14
- package/lib/memory/basic.js +5 -9
- package/lib/memory/simple.js +11 -5
- package/package.json +1 -1
- package/types/memory/basic.d.ts +10 -11
- package/types/memory/list.d.ts +2 -2
- package/types/memory/power.d.ts +2 -2
- package/types/memory/simple.d.ts +15 -3
package/cjs/index.js
CHANGED
|
@@ -332,15 +332,11 @@ var MemoryBasic = class {
|
|
|
332
332
|
push(...list) {
|
|
333
333
|
const { memorys } = this;
|
|
334
334
|
list.forEach((data) => {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
const index = this.list.push(data) - 1;
|
|
341
|
-
const result = this.#mount(index, memory);
|
|
342
|
-
memory === result || memorys.set(type, result);
|
|
343
|
-
}
|
|
335
|
+
const type = this.getType(data);
|
|
336
|
+
const memory = memorys.get(type);
|
|
337
|
+
const index = this.list.push(data) - 1;
|
|
338
|
+
const result = this.#mount(index, memory);
|
|
339
|
+
memory === result || memorys.set(type, result);
|
|
344
340
|
});
|
|
345
341
|
return this;
|
|
346
342
|
}
|
|
@@ -506,11 +502,7 @@ var MemorySimple = class {
|
|
|
506
502
|
push(...list) {
|
|
507
503
|
const memory = this.#memory;
|
|
508
504
|
list.forEach((data) => {
|
|
509
|
-
|
|
510
|
-
this.push(...data);
|
|
511
|
-
} else if (!memory.includes(this.#getType(data))) {
|
|
512
|
-
memory.push(data);
|
|
513
|
-
}
|
|
505
|
+
memory.includes(this.#getType(data)) || memory.push(data);
|
|
514
506
|
});
|
|
515
507
|
return this;
|
|
516
508
|
}
|
|
@@ -530,6 +522,16 @@ var MemorySimple = class {
|
|
|
530
522
|
this.#memory.forEach(callback);
|
|
531
523
|
return this;
|
|
532
524
|
}
|
|
525
|
+
/**
|
|
526
|
+
* map(按入栈顺序)
|
|
527
|
+
*/
|
|
528
|
+
map(callback) {
|
|
529
|
+
const list = [];
|
|
530
|
+
this.#memory.forEach((data, index) => {
|
|
531
|
+
list.push(callback(data, index));
|
|
532
|
+
});
|
|
533
|
+
return list;
|
|
534
|
+
}
|
|
533
535
|
/**
|
|
534
536
|
* 获取指定类型存储数据
|
|
535
537
|
*/
|
package/lib/memory/basic.js
CHANGED
|
@@ -26,15 +26,11 @@ class MemoryBasic {
|
|
|
26
26
|
push(...list) {
|
|
27
27
|
const { memorys } = this;
|
|
28
28
|
list.forEach((data) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const index = this.list.push(data) - 1;
|
|
35
|
-
const result = this.#mount(index, memory);
|
|
36
|
-
memory === result || memorys.set(type, result);
|
|
37
|
-
}
|
|
29
|
+
const type = this.getType(data);
|
|
30
|
+
const memory = memorys.get(type);
|
|
31
|
+
const index = this.list.push(data) - 1;
|
|
32
|
+
const result = this.#mount(index, memory);
|
|
33
|
+
memory === result || memorys.set(type, result);
|
|
38
34
|
});
|
|
39
35
|
return this;
|
|
40
36
|
}
|
package/lib/memory/simple.js
CHANGED
|
@@ -19,11 +19,7 @@ class MemorySimple {
|
|
|
19
19
|
push(...list) {
|
|
20
20
|
const memory = this.#memory;
|
|
21
21
|
list.forEach((data) => {
|
|
22
|
-
|
|
23
|
-
this.push(...data);
|
|
24
|
-
} else if (!memory.includes(this.#getType(data))) {
|
|
25
|
-
memory.push(data);
|
|
26
|
-
}
|
|
22
|
+
memory.includes(this.#getType(data)) || memory.push(data);
|
|
27
23
|
});
|
|
28
24
|
return this;
|
|
29
25
|
}
|
|
@@ -43,6 +39,16 @@ class MemorySimple {
|
|
|
43
39
|
this.#memory.forEach(callback);
|
|
44
40
|
return this;
|
|
45
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* map(按入栈顺序)
|
|
44
|
+
*/
|
|
45
|
+
map(callback) {
|
|
46
|
+
const list = [];
|
|
47
|
+
this.#memory.forEach((data, index) => {
|
|
48
|
+
list.push(callback(data, index));
|
|
49
|
+
});
|
|
50
|
+
return list;
|
|
51
|
+
}
|
|
46
52
|
/**
|
|
47
53
|
* 获取指定类型存储数据
|
|
48
54
|
*/
|
package/package.json
CHANGED
package/types/memory/basic.d.ts
CHANGED
|
@@ -12,14 +12,13 @@ interface Config<Reactor> {
|
|
|
12
12
|
*/
|
|
13
13
|
reflex(reactor: Reactor): number[];
|
|
14
14
|
}
|
|
15
|
-
export type _LV<T> = (T | _LV<T>)[];
|
|
16
15
|
/**
|
|
17
16
|
* 分类存储(通过继承,可用于拓展存储方式)
|
|
18
17
|
*/
|
|
19
|
-
export declare class MemoryBasic<
|
|
18
|
+
export declare class MemoryBasic<T, Reactor, Type extends Memory.Type> {
|
|
20
19
|
#private;
|
|
21
|
-
protected key: Memory.Pitch<
|
|
22
|
-
protected list:
|
|
20
|
+
protected key: Memory.Pitch<T, Type>;
|
|
21
|
+
protected list: T[];
|
|
23
22
|
protected memorys: Map<Type, Reactor>;
|
|
24
23
|
/**
|
|
25
24
|
* 返回存储长度
|
|
@@ -29,17 +28,17 @@ export declare class MemoryBasic<V, Reactor, Type extends Memory.Type> {
|
|
|
29
28
|
* @param key 用于对数据进行分类的key
|
|
30
29
|
* @param config
|
|
31
30
|
*/
|
|
32
|
-
constructor(key: Memory.Pitch<
|
|
33
|
-
protected getType(data:
|
|
34
|
-
push(...list:
|
|
31
|
+
constructor(key: Memory.Pitch<T, Type>, config: Config<Reactor>);
|
|
32
|
+
protected getType(data: T): Type;
|
|
33
|
+
push(...list: T[]): this;
|
|
35
34
|
/**
|
|
36
35
|
* 遍历所有存储数据(按入栈顺序)
|
|
37
36
|
*/
|
|
38
|
-
forEach(callback: (data:
|
|
37
|
+
forEach(callback: (data: T, index: number) => void): this;
|
|
39
38
|
/**
|
|
40
39
|
* 遍历所有存储类型
|
|
41
40
|
*/
|
|
42
|
-
forType(callback: (data:
|
|
41
|
+
forType(callback: (data: T[], type: Type) => void): this;
|
|
43
42
|
/**
|
|
44
43
|
* 检测存储是否包含某种类型
|
|
45
44
|
*/
|
|
@@ -47,11 +46,11 @@ export declare class MemoryBasic<V, Reactor, Type extends Memory.Type> {
|
|
|
47
46
|
/**
|
|
48
47
|
* 获取指定类型存储数据
|
|
49
48
|
*/
|
|
50
|
-
get(type: Type):
|
|
49
|
+
get(type: Type): T[] | null;
|
|
51
50
|
/**
|
|
52
51
|
* 删除指定存储数据
|
|
53
52
|
*/
|
|
54
|
-
delete(data:
|
|
53
|
+
delete(data: T): this;
|
|
55
54
|
/**
|
|
56
55
|
* 删除指定类型存储数据
|
|
57
56
|
*/
|
package/types/memory/list.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ import { Memory } from './type';
|
|
|
3
3
|
/**
|
|
4
4
|
* 分类存储(基于普通的键值存储)
|
|
5
5
|
*/
|
|
6
|
-
export declare class MemoryList<
|
|
7
|
-
constructor(key: Memory.Pitch<
|
|
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
|
}
|
package/types/memory/power.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ import { Memory } from './type';
|
|
|
3
3
|
/**
|
|
4
4
|
* 分类存储(基于2的n次幂之和构建唯一键进行存储)
|
|
5
5
|
*/
|
|
6
|
-
export declare class MemoryPower<
|
|
7
|
-
constructor(key: Memory.Pitch<
|
|
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
|
}
|
package/types/memory/simple.d.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Assign } from '@vope/types';
|
|
2
|
+
import { MemoryBasic } 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>);
|
|
10
|
-
push(...list:
|
|
17
|
+
push(...list: T[]): this;
|
|
11
18
|
/**
|
|
12
19
|
* 获取指定类型存储数据
|
|
13
20
|
*/
|
|
@@ -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 {};
|