@vope/utils 1.4.13 → 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 +93 -5
- package/lib/index.js +2 -0
- package/lib/memory/basic.js +9 -5
- package/lib/memory/simple.js +85 -0
- package/package.json +1 -1
- package/types/index.d.ts +1 -0
- package/types/memory/basic.d.ts +11 -10
- package/types/memory/list.d.ts +2 -2
- package/types/memory/power.d.ts +2 -2
- package/types/memory/simple.d.ts +47 -0
- package/types/memory/type.d.ts +1 -1
package/cjs/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(src_exports, {
|
|
|
24
24
|
MemoryBasic: () => MemoryBasic,
|
|
25
25
|
MemoryList: () => MemoryList,
|
|
26
26
|
MemoryPower: () => MemoryPower,
|
|
27
|
+
MemorySimple: () => MemorySimple,
|
|
27
28
|
Subscriber: () => Subscriber,
|
|
28
29
|
Union: () => Union,
|
|
29
30
|
clamp: () => clamp,
|
|
@@ -331,11 +332,15 @@ var MemoryBasic = class {
|
|
|
331
332
|
push(...list) {
|
|
332
333
|
const { memorys } = this;
|
|
333
334
|
list.forEach((data) => {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
335
|
+
if (Array.isArray(data)) {
|
|
336
|
+
this.push(...data);
|
|
337
|
+
} else {
|
|
338
|
+
const type = this.getType(data);
|
|
339
|
+
const memory = memorys.get(type);
|
|
340
|
+
const index = this.list.push(data) - 1;
|
|
341
|
+
const result = this.#mount(index, memory);
|
|
342
|
+
memory === result || memorys.set(type, result);
|
|
343
|
+
}
|
|
339
344
|
});
|
|
340
345
|
return this;
|
|
341
346
|
}
|
|
@@ -480,6 +485,89 @@ var MemoryPower = class extends MemoryBasic {
|
|
|
480
485
|
}
|
|
481
486
|
};
|
|
482
487
|
|
|
488
|
+
// src/memory/simple.ts
|
|
489
|
+
var MemorySimple = class {
|
|
490
|
+
#memory;
|
|
491
|
+
#key;
|
|
492
|
+
get size() {
|
|
493
|
+
return this.#memory.size;
|
|
494
|
+
}
|
|
495
|
+
constructor(key) {
|
|
496
|
+
this.#key = key;
|
|
497
|
+
this.#memory = new MemoryBasic(key, {
|
|
498
|
+
mount: (index) => index,
|
|
499
|
+
reflex: (reactor) => [reactor]
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
#getType(data) {
|
|
503
|
+
const key = this.#key;
|
|
504
|
+
return typeof key === "function" ? key(data) : data[key];
|
|
505
|
+
}
|
|
506
|
+
push(...list) {
|
|
507
|
+
const memory = this.#memory;
|
|
508
|
+
list.forEach((data) => {
|
|
509
|
+
if (Array.isArray(data)) {
|
|
510
|
+
this.push(...data);
|
|
511
|
+
} else if (!memory.includes(this.#getType(data))) {
|
|
512
|
+
memory.push(data);
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
return this;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* 获取指定类型存储数据
|
|
519
|
+
*/
|
|
520
|
+
get(type) {
|
|
521
|
+
const value = this.#memory.get(type);
|
|
522
|
+
if (value === null)
|
|
523
|
+
return value;
|
|
524
|
+
return value.length ? value[0] : null;
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* 遍历所有存储数据(按入栈顺序)
|
|
528
|
+
*/
|
|
529
|
+
forEach(callback) {
|
|
530
|
+
this.#memory.forEach(callback);
|
|
531
|
+
return this;
|
|
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
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* 获取指定类型存储数据
|
|
545
|
+
*/
|
|
546
|
+
includes(type) {
|
|
547
|
+
return this.#memory.includes(type);
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* 删除指定存储数据
|
|
551
|
+
*/
|
|
552
|
+
delete(data) {
|
|
553
|
+
this.#memory.delete(data);
|
|
554
|
+
return this;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* 删除指定类型存储数据
|
|
558
|
+
*/
|
|
559
|
+
deleteType(type) {
|
|
560
|
+
this.#memory.deleteType(type);
|
|
561
|
+
return this;
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* 清理存储
|
|
565
|
+
*/
|
|
566
|
+
clear() {
|
|
567
|
+
this.#memory.clear();
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
|
|
483
571
|
// src/once.ts
|
|
484
572
|
var once = (func, thisArg) => {
|
|
485
573
|
let local;
|
package/lib/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import { loadImage } from "./load/image";
|
|
|
16
16
|
import { MemoryBasic } from "./memory/basic";
|
|
17
17
|
import { MemoryList } from "./memory/list";
|
|
18
18
|
import { MemoryPower } from "./memory/power";
|
|
19
|
+
import { MemorySimple } from "./memory/simple";
|
|
19
20
|
import { once } from "./once";
|
|
20
21
|
import { deconPowersSum } from "./power/decon";
|
|
21
22
|
import { rotateAngle } from "./rotate/angle";
|
|
@@ -32,6 +33,7 @@ export {
|
|
|
32
33
|
MemoryBasic,
|
|
33
34
|
MemoryList,
|
|
34
35
|
MemoryPower,
|
|
36
|
+
MemorySimple,
|
|
35
37
|
default2 as Subscriber,
|
|
36
38
|
Union,
|
|
37
39
|
clamp,
|
package/lib/memory/basic.js
CHANGED
|
@@ -26,11 +26,15 @@ class MemoryBasic {
|
|
|
26
26
|
push(...list) {
|
|
27
27
|
const { memorys } = this;
|
|
28
28
|
list.forEach((data) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
if (Array.isArray(data)) {
|
|
30
|
+
this.push(...data);
|
|
31
|
+
} else {
|
|
32
|
+
const type = this.getType(data);
|
|
33
|
+
const memory = memorys.get(type);
|
|
34
|
+
const index = this.list.push(data) - 1;
|
|
35
|
+
const result = this.#mount(index, memory);
|
|
36
|
+
memory === result || memorys.set(type, result);
|
|
37
|
+
}
|
|
34
38
|
});
|
|
35
39
|
return this;
|
|
36
40
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { MemoryBasic } from "./basic";
|
|
2
|
+
class MemorySimple {
|
|
3
|
+
#memory;
|
|
4
|
+
#key;
|
|
5
|
+
get size() {
|
|
6
|
+
return this.#memory.size;
|
|
7
|
+
}
|
|
8
|
+
constructor(key) {
|
|
9
|
+
this.#key = key;
|
|
10
|
+
this.#memory = new MemoryBasic(key, {
|
|
11
|
+
mount: (index) => index,
|
|
12
|
+
reflex: (reactor) => [reactor]
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
#getType(data) {
|
|
16
|
+
const key = this.#key;
|
|
17
|
+
return typeof key === "function" ? key(data) : data[key];
|
|
18
|
+
}
|
|
19
|
+
push(...list) {
|
|
20
|
+
const memory = this.#memory;
|
|
21
|
+
list.forEach((data) => {
|
|
22
|
+
if (Array.isArray(data)) {
|
|
23
|
+
this.push(...data);
|
|
24
|
+
} else if (!memory.includes(this.#getType(data))) {
|
|
25
|
+
memory.push(data);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 获取指定类型存储数据
|
|
32
|
+
*/
|
|
33
|
+
get(type) {
|
|
34
|
+
const value = this.#memory.get(type);
|
|
35
|
+
if (value === null)
|
|
36
|
+
return value;
|
|
37
|
+
return value.length ? value[0] : null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 遍历所有存储数据(按入栈顺序)
|
|
41
|
+
*/
|
|
42
|
+
forEach(callback) {
|
|
43
|
+
this.#memory.forEach(callback);
|
|
44
|
+
return this;
|
|
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
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 获取指定类型存储数据
|
|
58
|
+
*/
|
|
59
|
+
includes(type) {
|
|
60
|
+
return this.#memory.includes(type);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 删除指定存储数据
|
|
64
|
+
*/
|
|
65
|
+
delete(data) {
|
|
66
|
+
this.#memory.delete(data);
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 删除指定类型存储数据
|
|
71
|
+
*/
|
|
72
|
+
deleteType(type) {
|
|
73
|
+
this.#memory.deleteType(type);
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 清理存储
|
|
78
|
+
*/
|
|
79
|
+
clear() {
|
|
80
|
+
this.#memory.clear();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export {
|
|
84
|
+
MemorySimple
|
|
85
|
+
};
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export { loadImage } from './load/image';
|
|
|
16
16
|
export { MemoryBasic } from './memory/basic';
|
|
17
17
|
export { MemoryList } from './memory/list';
|
|
18
18
|
export { MemoryPower } from './memory/power';
|
|
19
|
+
export { MemorySimple } from './memory/simple';
|
|
19
20
|
export { once } from './once';
|
|
20
21
|
export { deconPowersSum } from './power/decon';
|
|
21
22
|
export { rotateAngle } from './rotate/angle';
|
package/types/memory/basic.d.ts
CHANGED
|
@@ -12,13 +12,14 @@ interface Config<Reactor> {
|
|
|
12
12
|
*/
|
|
13
13
|
reflex(reactor: Reactor): number[];
|
|
14
14
|
}
|
|
15
|
+
export type _LV<T> = (T | _LV<T>)[];
|
|
15
16
|
/**
|
|
16
17
|
* 分类存储(通过继承,可用于拓展存储方式)
|
|
17
18
|
*/
|
|
18
|
-
export declare class MemoryBasic<
|
|
19
|
+
export declare class MemoryBasic<T, Reactor, Type extends Memory.Type> {
|
|
19
20
|
#private;
|
|
20
|
-
protected key: Memory.Pitch<
|
|
21
|
-
protected list:
|
|
21
|
+
protected key: Memory.Pitch<T, Type>;
|
|
22
|
+
protected list: T[];
|
|
22
23
|
protected memorys: Map<Type, Reactor>;
|
|
23
24
|
/**
|
|
24
25
|
* 返回存储长度
|
|
@@ -28,17 +29,17 @@ export declare class MemoryBasic<V, Reactor, Type extends Memory.Type> {
|
|
|
28
29
|
* @param key 用于对数据进行分类的key
|
|
29
30
|
* @param config
|
|
30
31
|
*/
|
|
31
|
-
constructor(key: Memory.Pitch<
|
|
32
|
-
protected getType(data:
|
|
33
|
-
push(...list:
|
|
32
|
+
constructor(key: Memory.Pitch<T, Type>, config: Config<Reactor>);
|
|
33
|
+
protected getType(data: T): Type;
|
|
34
|
+
push(...list: _LV<T>): this;
|
|
34
35
|
/**
|
|
35
36
|
* 遍历所有存储数据(按入栈顺序)
|
|
36
37
|
*/
|
|
37
|
-
forEach(callback: (data:
|
|
38
|
+
forEach(callback: (data: T, index: number) => void): this;
|
|
38
39
|
/**
|
|
39
40
|
* 遍历所有存储类型
|
|
40
41
|
*/
|
|
41
|
-
forType(callback: (data:
|
|
42
|
+
forType(callback: (data: T[], type: Type) => void): this;
|
|
42
43
|
/**
|
|
43
44
|
* 检测存储是否包含某种类型
|
|
44
45
|
*/
|
|
@@ -46,11 +47,11 @@ export declare class MemoryBasic<V, Reactor, Type extends Memory.Type> {
|
|
|
46
47
|
/**
|
|
47
48
|
* 获取指定类型存储数据
|
|
48
49
|
*/
|
|
49
|
-
get(type: Type):
|
|
50
|
+
get(type: Type): T[] | null;
|
|
50
51
|
/**
|
|
51
52
|
* 删除指定存储数据
|
|
52
53
|
*/
|
|
53
|
-
delete(data:
|
|
54
|
+
delete(data: T): this;
|
|
54
55
|
/**
|
|
55
56
|
* 删除指定类型存储数据
|
|
56
57
|
*/
|
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
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Assign } from '@vope/types';
|
|
2
|
+
import { MemoryBasic, _LV } from './basic';
|
|
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
|
+
}>;
|
|
10
|
+
/**
|
|
11
|
+
* 简易存储(不分类)
|
|
12
|
+
*/
|
|
13
|
+
export declare class MemorySimple<T, Type extends Memory.Type> implements Basic<T, number, Type> {
|
|
14
|
+
#private;
|
|
15
|
+
get size(): number;
|
|
16
|
+
constructor(key: Memory.Pitch<T, Type>);
|
|
17
|
+
push(...list: _LV<T>): this;
|
|
18
|
+
/**
|
|
19
|
+
* 获取指定类型存储数据
|
|
20
|
+
*/
|
|
21
|
+
get(type: Type): T | null;
|
|
22
|
+
/**
|
|
23
|
+
* 遍历所有存储数据(按入栈顺序)
|
|
24
|
+
*/
|
|
25
|
+
forEach(callback: (data: T, index: number) => void): this;
|
|
26
|
+
/**
|
|
27
|
+
* map(按入栈顺序)
|
|
28
|
+
*/
|
|
29
|
+
map<V>(callback: (data: T, index: number) => V): V[];
|
|
30
|
+
/**
|
|
31
|
+
* 获取指定类型存储数据
|
|
32
|
+
*/
|
|
33
|
+
includes(type: Type): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* 删除指定存储数据
|
|
36
|
+
*/
|
|
37
|
+
delete(data: T): this;
|
|
38
|
+
/**
|
|
39
|
+
* 删除指定类型存储数据
|
|
40
|
+
*/
|
|
41
|
+
deleteType(type: Type): this;
|
|
42
|
+
/**
|
|
43
|
+
* 清理存储
|
|
44
|
+
*/
|
|
45
|
+
clear(): void;
|
|
46
|
+
}
|
|
47
|
+
export {};
|