utilium 0.6.2 → 0.7.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/dist/list.d.ts +4 -11
- package/dist/list.js +5 -27
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/list.ts +7 -36
- package/src/types.ts +1 -1
package/dist/list.d.ts
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
2
|
-
export declare class List<T> extends EventEmitter<'update'> implements
|
2
|
+
export declare class List<T> extends EventEmitter<'update'> implements RelativeIndexable<T> {
|
3
3
|
readonly [Symbol.toStringTag] = "List";
|
4
4
|
constructor(values?: readonly T[] | Iterable<T> | null);
|
5
5
|
protected data: Set<T>;
|
6
|
-
|
7
|
-
|
6
|
+
toSet(): Set<T>;
|
7
|
+
toArray(): T[];
|
8
|
+
toJSON(): string;
|
8
9
|
toString(): string;
|
9
10
|
set(index: number, value: T): void;
|
10
11
|
deleteAt(index: number): void;
|
@@ -16,14 +17,6 @@ export declare class List<T> extends EventEmitter<'update'> implements Set<T>, R
|
|
16
17
|
add(value: T): this;
|
17
18
|
clear(): void;
|
18
19
|
delete(value: T): boolean;
|
19
|
-
union<U>(other: ReadonlySetLike<U>): List<T | U>;
|
20
|
-
intersection<U>(other: ReadonlySetLike<U>): List<T & U>;
|
21
|
-
difference<U>(other: ReadonlySetLike<U>): List<T>;
|
22
|
-
symmetricDifference<U>(other: ReadonlySetLike<U>): List<T | U>;
|
23
|
-
isSubsetOf(other: ReadonlySetLike<unknown>): boolean;
|
24
|
-
isSupersetOf(other: ReadonlySetLike<unknown>): boolean;
|
25
|
-
isDisjointFrom(other: ReadonlySetLike<unknown>): boolean;
|
26
|
-
forEach(callbackfn: (value: T, value2: T, list: List<T>) => void, thisArg?: any): void;
|
27
20
|
has(value: T): boolean;
|
28
21
|
get size(): number;
|
29
22
|
entries(): IterableIterator<[T, T]>;
|
package/dist/list.js
CHANGED
@@ -8,10 +8,13 @@ export class List extends EventEmitter {
|
|
8
8
|
}
|
9
9
|
}
|
10
10
|
data = new Set();
|
11
|
-
|
11
|
+
toSet() {
|
12
|
+
return new Set(this.data);
|
13
|
+
}
|
14
|
+
toArray() {
|
12
15
|
return [...this.data];
|
13
16
|
}
|
14
|
-
|
17
|
+
toJSON() {
|
15
18
|
return JSON.stringify([...this.data]);
|
16
19
|
}
|
17
20
|
toString() {
|
@@ -80,31 +83,6 @@ export class List extends EventEmitter {
|
|
80
83
|
this.emit('update');
|
81
84
|
return success;
|
82
85
|
}
|
83
|
-
union(other) {
|
84
|
-
return new List(this.data.union(other));
|
85
|
-
}
|
86
|
-
intersection(other) {
|
87
|
-
return new List(this.data.intersection(other));
|
88
|
-
}
|
89
|
-
difference(other) {
|
90
|
-
return new List(this.data.difference(other));
|
91
|
-
}
|
92
|
-
symmetricDifference(other) {
|
93
|
-
return new List(this.data.symmetricDifference(other));
|
94
|
-
}
|
95
|
-
isSubsetOf(other) {
|
96
|
-
return this.data.isSubsetOf(other);
|
97
|
-
}
|
98
|
-
isSupersetOf(other) {
|
99
|
-
return this.data.isSupersetOf(other);
|
100
|
-
}
|
101
|
-
isDisjointFrom(other) {
|
102
|
-
return this.data.isDisjointFrom(other);
|
103
|
-
}
|
104
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
105
|
-
forEach(callbackfn, thisArg) {
|
106
|
-
this.data.forEach((v1, v2) => callbackfn.call(thisArg, v1, v2, this));
|
107
|
-
}
|
108
86
|
has(value) {
|
109
87
|
return this.data.has(value);
|
110
88
|
}
|
package/dist/types.d.ts
CHANGED
@@ -165,7 +165,7 @@ export type OptionalTuple<T extends unknown[]> = T extends [infer Head, ...infer
|
|
165
165
|
* Keys of a Map
|
166
166
|
*/
|
167
167
|
export type MapKeys<T> = T extends Map<infer K, any> ? K : never;
|
168
|
-
export type ClassLike<Instance =
|
168
|
+
export type ClassLike<Instance = any> = abstract new (...args: any[]) => Instance;
|
169
169
|
/**
|
170
170
|
* Converts a union to an intersection
|
171
171
|
* @see https://stackoverflow.com/a/55128956/17637456
|
package/package.json
CHANGED
package/src/list.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
2
2
|
|
3
|
-
export class List<T> extends EventEmitter<'update'> implements
|
3
|
+
export class List<T> extends EventEmitter<'update'> implements RelativeIndexable<T> {
|
4
4
|
public readonly [Symbol.toStringTag] = 'List';
|
5
5
|
|
6
6
|
public constructor(values?: readonly T[] | Iterable<T> | null) {
|
@@ -12,11 +12,15 @@ export class List<T> extends EventEmitter<'update'> implements Set<T>, RelativeI
|
|
12
12
|
|
13
13
|
protected data = new Set<T>();
|
14
14
|
|
15
|
-
public
|
15
|
+
public toSet(): Set<T> {
|
16
|
+
return new Set(this.data);
|
17
|
+
}
|
18
|
+
|
19
|
+
public toArray(): T[] {
|
16
20
|
return [...this.data];
|
17
21
|
}
|
18
22
|
|
19
|
-
public
|
23
|
+
public toJSON() {
|
20
24
|
return JSON.stringify([...this.data]);
|
21
25
|
}
|
22
26
|
|
@@ -103,39 +107,6 @@ export class List<T> extends EventEmitter<'update'> implements Set<T>, RelativeI
|
|
103
107
|
return success;
|
104
108
|
}
|
105
109
|
|
106
|
-
public union<U>(other: ReadonlySetLike<U>): List<T | U> {
|
107
|
-
return new List(this.data.union(other));
|
108
|
-
}
|
109
|
-
|
110
|
-
public intersection<U>(other: ReadonlySetLike<U>): List<T & U> {
|
111
|
-
return new List(this.data.intersection(other));
|
112
|
-
}
|
113
|
-
|
114
|
-
public difference<U>(other: ReadonlySetLike<U>): List<T> {
|
115
|
-
return new List(this.data.difference(other));
|
116
|
-
}
|
117
|
-
|
118
|
-
public symmetricDifference<U>(other: ReadonlySetLike<U>): List<T | U> {
|
119
|
-
return new List(this.data.symmetricDifference(other));
|
120
|
-
}
|
121
|
-
|
122
|
-
public isSubsetOf(other: ReadonlySetLike<unknown>): boolean {
|
123
|
-
return this.data.isSubsetOf(other);
|
124
|
-
}
|
125
|
-
|
126
|
-
public isSupersetOf(other: ReadonlySetLike<unknown>): boolean {
|
127
|
-
return this.data.isSupersetOf(other);
|
128
|
-
}
|
129
|
-
|
130
|
-
public isDisjointFrom(other: ReadonlySetLike<unknown>): boolean {
|
131
|
-
return this.data.isDisjointFrom(other);
|
132
|
-
}
|
133
|
-
|
134
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
135
|
-
public forEach(callbackfn: (value: T, value2: T, list: List<T>) => void, thisArg?: any): void {
|
136
|
-
this.data.forEach((v1, v2) => callbackfn.call(thisArg, v1, v2, this));
|
137
|
-
}
|
138
|
-
|
139
110
|
public has(value: T): boolean {
|
140
111
|
return this.data.has(value);
|
141
112
|
}
|
package/src/types.ts
CHANGED
@@ -202,7 +202,7 @@ export type OptionalTuple<T extends unknown[]> = T extends [infer Head, ...infer
|
|
202
202
|
*/
|
203
203
|
export type MapKeys<T> = T extends Map<infer K, any> ? K : never;
|
204
204
|
|
205
|
-
export type ClassLike<Instance =
|
205
|
+
export type ClassLike<Instance = any> = abstract new (...args: any[]) => Instance;
|
206
206
|
|
207
207
|
/**
|
208
208
|
* Converts a union to an intersection
|