@vope/utils 1.4.13 → 1.4.14
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 +83 -5
- package/lib/index.js +2 -0
- package/lib/memory/basic.js +9 -5
- package/lib/memory/simple.js +75 -0
- package/package.json +1 -1
- package/types/index.d.ts +1 -0
- package/types/memory/basic.d.ts +2 -1
- package/types/memory/simple.d.ts +35 -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,79 @@ 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
|
+
* 获取指定类型存储数据
|
|
535
|
+
*/
|
|
536
|
+
includes(type) {
|
|
537
|
+
return this.#memory.includes(type);
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* 删除指定存储数据
|
|
541
|
+
*/
|
|
542
|
+
delete(data) {
|
|
543
|
+
this.#memory.delete(data);
|
|
544
|
+
return this;
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* 删除指定类型存储数据
|
|
548
|
+
*/
|
|
549
|
+
deleteType(type) {
|
|
550
|
+
this.#memory.deleteType(type);
|
|
551
|
+
return this;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* 清理存储
|
|
555
|
+
*/
|
|
556
|
+
clear() {
|
|
557
|
+
this.#memory.clear();
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
|
|
483
561
|
// src/once.ts
|
|
484
562
|
var once = (func, thisArg) => {
|
|
485
563
|
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,75 @@
|
|
|
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
|
+
* 获取指定类型存储数据
|
|
48
|
+
*/
|
|
49
|
+
includes(type) {
|
|
50
|
+
return this.#memory.includes(type);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 删除指定存储数据
|
|
54
|
+
*/
|
|
55
|
+
delete(data) {
|
|
56
|
+
this.#memory.delete(data);
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 删除指定类型存储数据
|
|
61
|
+
*/
|
|
62
|
+
deleteType(type) {
|
|
63
|
+
this.#memory.deleteType(type);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 清理存储
|
|
68
|
+
*/
|
|
69
|
+
clear() {
|
|
70
|
+
this.#memory.clear();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
MemorySimple
|
|
75
|
+
};
|
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,6 +12,7 @@ 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
|
*/
|
|
@@ -30,7 +31,7 @@ export declare class MemoryBasic<V, Reactor, Type extends Memory.Type> {
|
|
|
30
31
|
*/
|
|
31
32
|
constructor(key: Memory.Pitch<V, Type>, config: Config<Reactor>);
|
|
32
33
|
protected getType(data: V): Type;
|
|
33
|
-
push(...list: V
|
|
34
|
+
push(...list: _LV<V>): this;
|
|
34
35
|
/**
|
|
35
36
|
* 遍历所有存储数据(按入栈顺序)
|
|
36
37
|
*/
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { _LV } from './basic';
|
|
2
|
+
import { Memory } from './type';
|
|
3
|
+
/**
|
|
4
|
+
* 简易存储(不分类)
|
|
5
|
+
*/
|
|
6
|
+
export declare class MemorySimple<T, Type extends Memory.Type> {
|
|
7
|
+
#private;
|
|
8
|
+
get size(): number;
|
|
9
|
+
constructor(key: Memory.Pitch<T, Type>);
|
|
10
|
+
push(...list: _LV<T>): this;
|
|
11
|
+
/**
|
|
12
|
+
* 获取指定类型存储数据
|
|
13
|
+
*/
|
|
14
|
+
get(type: Type): T | null;
|
|
15
|
+
/**
|
|
16
|
+
* 遍历所有存储数据(按入栈顺序)
|
|
17
|
+
*/
|
|
18
|
+
forEach(callback: (data: T, index: number) => void): this;
|
|
19
|
+
/**
|
|
20
|
+
* 获取指定类型存储数据
|
|
21
|
+
*/
|
|
22
|
+
includes(type: Type): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* 删除指定存储数据
|
|
25
|
+
*/
|
|
26
|
+
delete(data: T): this;
|
|
27
|
+
/**
|
|
28
|
+
* 删除指定类型存储数据
|
|
29
|
+
*/
|
|
30
|
+
deleteType(type: Type): this;
|
|
31
|
+
/**
|
|
32
|
+
* 清理存储
|
|
33
|
+
*/
|
|
34
|
+
clear(): void;
|
|
35
|
+
}
|