@vope/utils 1.2.0 → 1.3.0
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/union.js +14 -10
- package/lib/union.js +14 -10
- package/package.json +1 -1
- package/types/union.d.ts +12 -12
package/cjs/union.js
CHANGED
|
@@ -5,20 +5,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
*/
|
|
6
6
|
class Union {
|
|
7
7
|
key;
|
|
8
|
-
|
|
9
|
-
#
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
formatter;
|
|
9
|
+
#data = {};
|
|
10
|
+
#options = {};
|
|
11
|
+
get data() {
|
|
12
|
+
return this.#data;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
get options() {
|
|
15
|
+
return this.#options;
|
|
16
|
+
}
|
|
17
|
+
constructor(key, formatter) {
|
|
14
18
|
this.key = key;
|
|
15
|
-
this.
|
|
19
|
+
this.formatter = formatter;
|
|
16
20
|
}
|
|
17
21
|
add(data) {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
const key = data[this.key];
|
|
23
|
+
const result = this.formatter(data);
|
|
24
|
+
this.#data[key] = result.data;
|
|
25
|
+
this.#options[key] = result.option;
|
|
22
26
|
return this;
|
|
23
27
|
}
|
|
24
28
|
}
|
package/lib/union.js
CHANGED
|
@@ -3,20 +3,24 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export default class Union {
|
|
5
5
|
key;
|
|
6
|
-
|
|
7
|
-
#
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
formatter;
|
|
7
|
+
#data = {};
|
|
8
|
+
#options = {};
|
|
9
|
+
get data() {
|
|
10
|
+
return this.#data;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
+
get options() {
|
|
13
|
+
return this.#options;
|
|
14
|
+
}
|
|
15
|
+
constructor(key, formatter) {
|
|
12
16
|
this.key = key;
|
|
13
|
-
this.
|
|
17
|
+
this.formatter = formatter;
|
|
14
18
|
}
|
|
15
19
|
add(data) {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
const key = data[this.key];
|
|
21
|
+
const result = this.formatter(data);
|
|
22
|
+
this.#data[key] = result.data;
|
|
23
|
+
this.#options[key] = result.option;
|
|
20
24
|
return this;
|
|
21
25
|
}
|
|
22
26
|
}
|
package/package.json
CHANGED
package/types/union.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { Revise } from '@vope/types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
2
|
+
interface Result<Data, Option> {
|
|
3
|
+
data: Data;
|
|
4
|
+
option: Option;
|
|
5
|
+
}
|
|
7
6
|
/**
|
|
8
7
|
* 数据联合(用于需要对加入的数据进行智能提示)
|
|
9
8
|
*/
|
|
10
|
-
export default class Union<
|
|
11
|
-
[key in
|
|
12
|
-
},
|
|
9
|
+
export default class Union<Primary extends string, Member extends string, Origin extends {
|
|
10
|
+
[key in Primary]: string;
|
|
11
|
+
}, Data extends unknown, Option extends unknown, Status extends Member | never = never> {
|
|
13
12
|
#private;
|
|
14
13
|
private key;
|
|
15
|
-
private
|
|
16
|
-
get
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
private formatter;
|
|
15
|
+
get data(): Required<Record<Status, Data>>;
|
|
16
|
+
get options(): Required<Record<Status, Option>>;
|
|
17
|
+
constructor(key: Primary, formatter: (data: Origin) => Result<Data, Option>);
|
|
18
|
+
add<V extends Exclude<Member, Status>>(data: Revise<Origin, Primary, V>): Union<Primary, Member, Origin, Data, Option, Status | V> & Omit<this, keyof Union<Primary, Member, Origin, Data, Option, Status | V>>;
|
|
19
19
|
}
|
|
20
20
|
export {};
|