utilium 0.5.9 → 0.5.10

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 CHANGED
@@ -1,6 +1,7 @@
1
1
  import { EventEmitter } from 'eventemitter3';
2
2
  export declare class List<T> extends EventEmitter<'update'> implements Set<T>, RelativeIndexable<T> {
3
3
  readonly [Symbol.toStringTag] = "List";
4
+ constructor(values?: readonly T[] | Iterable<T> | null);
4
5
  protected data: Set<T>;
5
6
  array(): T[];
6
7
  json(): string;
@@ -15,6 +16,13 @@ export declare class List<T> extends EventEmitter<'update'> implements Set<T>, R
15
16
  add(value: T): this;
16
17
  clear(): void;
17
18
  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;
18
26
  forEach(callbackfn: (value: T, value2: T, list: List<T>) => void, thisArg?: any): void;
19
27
  has(value: T): boolean;
20
28
  get size(): number;
package/dist/list.js CHANGED
@@ -1,6 +1,12 @@
1
1
  import { EventEmitter } from 'eventemitter3';
2
2
  export class List extends EventEmitter {
3
3
  [Symbol.toStringTag] = 'List';
4
+ constructor(values) {
5
+ super();
6
+ if (values) {
7
+ this.push(...values);
8
+ }
9
+ }
4
10
  data = new Set();
5
11
  array() {
6
12
  return [...this.data];
@@ -74,6 +80,27 @@ export class List extends EventEmitter {
74
80
  this.emit('update');
75
81
  return success;
76
82
  }
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
+ }
77
104
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
105
  forEach(callbackfn, thisArg) {
79
106
  this.data.forEach((v1, v2) => callbackfn.call(thisArg, v1, v2, this));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utilium",
3
- "version": "0.5.9",
3
+ "version": "0.5.10",
4
4
  "description": "Typescript utilies",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/list.ts CHANGED
@@ -3,6 +3,13 @@ import { EventEmitter } from 'eventemitter3';
3
3
  export class List<T> extends EventEmitter<'update'> implements Set<T>, RelativeIndexable<T> {
4
4
  public readonly [Symbol.toStringTag] = 'List';
5
5
 
6
+ public constructor(values?: readonly T[] | Iterable<T> | null) {
7
+ super();
8
+ if (values) {
9
+ this.push(...values);
10
+ }
11
+ }
12
+
6
13
  protected data = new Set<T>();
7
14
 
8
15
  public array(): T[] {
@@ -96,6 +103,34 @@ export class List<T> extends EventEmitter<'update'> implements Set<T>, RelativeI
96
103
  return success;
97
104
  }
98
105
 
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
+
99
134
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
100
135
  public forEach(callbackfn: (value: T, value2: T, list: List<T>) => void, thisArg?: any): void {
101
136
  this.data.forEach((v1, v2) => callbackfn.call(thisArg, v1, v2, this));
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "lib": ["ES2023"],
3
+ "lib": ["ESNext"],
4
4
  "module": "NodeNext",
5
5
  "target": "ES2023",
6
6
  "moduleResolution": "NodeNext",