@vope/utils 1.4.10 → 1.4.12
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 +23 -0
- package/lib/union.js +23 -0
- package/package.json +3 -3
- package/types/union.d.ts +16 -2
package/cjs/index.js
CHANGED
|
@@ -666,6 +666,7 @@ var Union = class {
|
|
|
666
666
|
}
|
|
667
667
|
#data = {};
|
|
668
668
|
#options = {};
|
|
669
|
+
#raws = {};
|
|
669
670
|
get data() {
|
|
670
671
|
return this.#data;
|
|
671
672
|
}
|
|
@@ -675,10 +676,32 @@ var Union = class {
|
|
|
675
676
|
add(data) {
|
|
676
677
|
const key = data[this.key];
|
|
677
678
|
const result = this.formatter(data);
|
|
679
|
+
this.#raws[key] = data;
|
|
678
680
|
this.#data[key] = result.data;
|
|
679
681
|
this.#options[key] = result.option;
|
|
680
682
|
return this;
|
|
681
683
|
}
|
|
684
|
+
/**
|
|
685
|
+
* 获取原始数据
|
|
686
|
+
*/
|
|
687
|
+
getRaw(key) {
|
|
688
|
+
return this.#raws[key];
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* 从已有的联合中拷贝数据
|
|
692
|
+
*/
|
|
693
|
+
clone(target, key) {
|
|
694
|
+
const { data, options } = target;
|
|
695
|
+
const keys = Array.isArray(key) ? key : [key];
|
|
696
|
+
keys.forEach((key2) => {
|
|
697
|
+
if (key2 in data) {
|
|
698
|
+
this.#raws[key2] = target.getRaw(key2);
|
|
699
|
+
this.#data[key2] = data[key2];
|
|
700
|
+
this.#options[key2] = options[key2];
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
return this;
|
|
704
|
+
}
|
|
682
705
|
};
|
|
683
706
|
|
|
684
707
|
// src/url/join.ts
|
package/lib/union.js
CHANGED
|
@@ -5,6 +5,7 @@ class Union {
|
|
|
5
5
|
}
|
|
6
6
|
#data = {};
|
|
7
7
|
#options = {};
|
|
8
|
+
#raws = {};
|
|
8
9
|
get data() {
|
|
9
10
|
return this.#data;
|
|
10
11
|
}
|
|
@@ -14,10 +15,32 @@ class Union {
|
|
|
14
15
|
add(data) {
|
|
15
16
|
const key = data[this.key];
|
|
16
17
|
const result = this.formatter(data);
|
|
18
|
+
this.#raws[key] = data;
|
|
17
19
|
this.#data[key] = result.data;
|
|
18
20
|
this.#options[key] = result.option;
|
|
19
21
|
return this;
|
|
20
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* 获取原始数据
|
|
25
|
+
*/
|
|
26
|
+
getRaw(key) {
|
|
27
|
+
return this.#raws[key];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 从已有的联合中拷贝数据
|
|
31
|
+
*/
|
|
32
|
+
clone(target, key) {
|
|
33
|
+
const { data, options } = target;
|
|
34
|
+
const keys = Array.isArray(key) ? key : [key];
|
|
35
|
+
keys.forEach((key2) => {
|
|
36
|
+
if (key2 in data) {
|
|
37
|
+
this.#raws[key2] = target.getRaw(key2);
|
|
38
|
+
this.#data[key2] = data[key2];
|
|
39
|
+
this.#options[key2] = options[key2];
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
21
44
|
}
|
|
22
45
|
export {
|
|
23
46
|
Union
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vope/utils",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.12",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -46,11 +46,11 @@
|
|
|
46
46
|
"mocha": "^10.2.0",
|
|
47
47
|
"rimraf": "^5.0.5",
|
|
48
48
|
"tslib": "^2.6.1",
|
|
49
|
-
"typescript": "^5.3.
|
|
49
|
+
"typescript": "^5.3.3"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@types/lodash-es": "^4.17.9",
|
|
53
|
-
"@vope/types": "^1.0.
|
|
53
|
+
"@vope/types": "^1.0.12",
|
|
54
54
|
"csstype": "^3.1.3",
|
|
55
55
|
"lodash-es": "^4.17.21"
|
|
56
56
|
}
|
package/types/union.d.ts
CHANGED
|
@@ -3,6 +3,12 @@ interface Result<Data, Option> {
|
|
|
3
3
|
data: Data;
|
|
4
4
|
option: Option;
|
|
5
5
|
}
|
|
6
|
+
type Raws<Primary extends string, Status extends string, Origin extends {
|
|
7
|
+
[key in Primary]: string;
|
|
8
|
+
}> = {
|
|
9
|
+
[P in Status]: Revise<Origin, Primary, P>;
|
|
10
|
+
};
|
|
11
|
+
type GetStatus<T> = T extends Union<any, any, any, any, any, infer S> ? S : never;
|
|
6
12
|
/**
|
|
7
13
|
* 数据联合(用于需要对加入的数据进行智能提示)
|
|
8
14
|
*/
|
|
@@ -10,11 +16,19 @@ export declare class Union<Primary extends string, Member extends string, Origin
|
|
|
10
16
|
[key in Primary]: string;
|
|
11
17
|
}, Data extends unknown, Option extends unknown, Status extends Member | never = never> {
|
|
12
18
|
#private;
|
|
13
|
-
|
|
19
|
+
protected key: Primary;
|
|
14
20
|
private formatter;
|
|
15
21
|
get data(): Required<Record<Status, Data>>;
|
|
16
22
|
get options(): Required<Record<Status, Option>>;
|
|
17
23
|
constructor(key: Primary, formatter: (data: Origin) => Result<Data, Option>);
|
|
18
|
-
add<
|
|
24
|
+
add<P extends Exclude<Member, Status>>(data: Revise<Origin, Primary, P>): Union<Primary, Member, Origin, Data, Option, Status | P> & Omit<this, keyof Union<Primary, Member, Origin, Data, Option, Status | P>>;
|
|
25
|
+
/**
|
|
26
|
+
* 获取原始数据
|
|
27
|
+
*/
|
|
28
|
+
getRaw<P extends Status>(key: P): Raws<Primary, Status, Origin>[P];
|
|
29
|
+
/**
|
|
30
|
+
* 从已有的联合中拷贝数据
|
|
31
|
+
*/
|
|
32
|
+
clone<T extends Union<Primary, string, Origin, Data, Option>, const P extends Exclude<GetStatus<T> & Member, Status>>(target: T, key: P | P[]): Union<Primary, Member, Origin, Data, Option, Status | P> & Omit<this, keyof Union<Primary, Member, Origin, Data, Option, Status | P>>;
|
|
19
33
|
}
|
|
20
34
|
export {};
|