@typedly/collection 2.0.0 → 3.0.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/README.md +8 -4
- package/package.json +2 -2
- package/types/typedly-collection.d.ts +28 -35
package/README.md
CHANGED
|
@@ -71,9 +71,12 @@ import { CollectionAdapter } from '@typedly/collection';
|
|
|
71
71
|
### `CollectionShape`
|
|
72
72
|
|
|
73
73
|
```typescript
|
|
74
|
-
import { CollectionShape } from '@typedly/collection';
|
|
74
|
+
import { CollectionShape, IterValue } from '@typedly/collection';
|
|
75
75
|
|
|
76
|
-
export class AnyCollection<
|
|
76
|
+
export class AnyCollection<
|
|
77
|
+
T,
|
|
78
|
+
V = Set<T>
|
|
79
|
+
> implements CollectionShape<T, V, false> {
|
|
77
80
|
// Data shape method.
|
|
78
81
|
get value(): V {
|
|
79
82
|
// Implementation depends on specific requirements.
|
|
@@ -121,10 +124,11 @@ export class AnyCollection<T, V = Set<T>> implements CollectionShape<T, V> {
|
|
|
121
124
|
return (this.#items as any).delete(element);
|
|
122
125
|
}
|
|
123
126
|
|
|
124
|
-
forEach(callbackfn: (element: T, element2: T, collection: CollectionShape<T, V>) => void, thisArg?: any):
|
|
127
|
+
forEach(callbackfn: (element: T, element2: T, collection: CollectionShape<T, V, false>) => void, thisArg?: any): this {
|
|
125
128
|
(this.#items as any).forEach((value: T) => {
|
|
126
129
|
callbackfn.call(thisArg, value, value, this);
|
|
127
130
|
});
|
|
131
|
+
return this;
|
|
128
132
|
}
|
|
129
133
|
|
|
130
134
|
has(element: T): boolean {
|
|
@@ -139,7 +143,7 @@ export class AnyCollection<T, V = Set<T>> implements CollectionShape<T, V> {
|
|
|
139
143
|
return 'MyCollection';
|
|
140
144
|
}
|
|
141
145
|
|
|
142
|
-
[Symbol.iterator]():
|
|
146
|
+
[Symbol.iterator](): IterableIterator<IterValue<V>> {
|
|
143
147
|
return (this.#items as any).values();
|
|
144
148
|
}
|
|
145
149
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typedly/collection",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"author": "wwwdev.io <dev@wwwdev.io>",
|
|
5
5
|
"description": "A TypeScript type definitions package for data collections with customizable storage.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"registry": "https://registry.npmjs.org"
|
|
10
10
|
},
|
|
11
11
|
"peerDependencies": {
|
|
12
|
-
"@typedly/data": "^
|
|
12
|
+
"@typedly/data": "^3.0.0"
|
|
13
13
|
},
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
@@ -1,75 +1,68 @@
|
|
|
1
|
-
import { DataShape } from '@typedly/data';
|
|
1
|
+
import { DataShape, AsyncReturn } from '@typedly/data';
|
|
2
2
|
import { ConstrainedConstructor } from '@typedly/constructor';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @description Represents a collection of elements.
|
|
6
6
|
* @export
|
|
7
7
|
* @interface Collection
|
|
8
|
-
* @template
|
|
9
|
-
* @template
|
|
10
|
-
* @
|
|
8
|
+
* @template E The type of elements in the collection.
|
|
9
|
+
* @template [T=any] The type of the value in the collection, data of elements.
|
|
10
|
+
* @template {boolean} [R=false] The `boolean` type to determine async methods.
|
|
11
|
+
* @extends {DataShape<T, R>}
|
|
11
12
|
*/
|
|
12
|
-
interface CollectionShape<T,
|
|
13
|
+
interface CollectionShape<E, T = any, R extends boolean = false> extends DataShape<T, R> {
|
|
13
14
|
/**
|
|
14
15
|
* @description Adds elements to the collection.
|
|
15
|
-
* @param {...
|
|
16
|
-
* @returns {this} The collection instance
|
|
16
|
+
* @param {...E[]} element Element of type `T` to add.
|
|
17
|
+
* @returns {AsyncReturn<R, this>} The collection instance `this`, or in `Promise`.
|
|
17
18
|
*/
|
|
18
|
-
add(...element:
|
|
19
|
+
add(...element: E[]): AsyncReturn<R, this>;
|
|
19
20
|
/**
|
|
20
21
|
* @description Deletes elements from the collection.
|
|
21
|
-
* @param {...
|
|
22
|
-
* @returns {boolean} `true` if the element was successfully deleted, otherwise `false`.
|
|
22
|
+
* @param {...E[]} element Element of type `T` to delete.
|
|
23
|
+
* @returns {AsyncReturn<R, boolean>} `true` if the element was successfully deleted, otherwise `false`.
|
|
23
24
|
*/
|
|
24
|
-
delete(...element:
|
|
25
|
+
delete(...element: E[]): AsyncReturn<R, boolean>;
|
|
25
26
|
/**
|
|
26
27
|
* @description Executes a provided function once for each collection element.
|
|
27
|
-
* @param {(value:
|
|
28
|
-
* @param {
|
|
28
|
+
* @param {(value: E, value2: E, collection: CollectionShape<E, T, R>) => void} callbackfn Function to execute for each element.
|
|
29
|
+
* @param {AsyncReturn<R, this>} [thisArg] Value to use as `this` when executing `callbackfn`.
|
|
29
30
|
*/
|
|
30
|
-
forEach(callbackfn: (element:
|
|
31
|
+
forEach(callbackfn: (element: E, element2: E, collection: CollectionShape<E, T, R>) => void, thisArg?: any): AsyncReturn<R, this>;
|
|
31
32
|
/**
|
|
32
33
|
* @description Checks if every item exists in the collection.
|
|
33
|
-
* @param {...
|
|
34
|
-
* @returns {boolean} `true` if the element exists, otherwise `false`.
|
|
34
|
+
* @param {...E[]} element Element of type `T` to check for existence.
|
|
35
|
+
* @returns {AsyncReturn<R, boolean>} `true` if the element exists, otherwise `false`.
|
|
35
36
|
*/
|
|
36
|
-
has(...element:
|
|
37
|
+
has(...element: E[]): AsyncReturn<R, boolean>;
|
|
37
38
|
/**
|
|
38
39
|
* @description The number of items in the collection.
|
|
39
40
|
* @returns {number}
|
|
40
41
|
*/
|
|
41
42
|
readonly size: number;
|
|
42
|
-
/**
|
|
43
|
-
* @description Returns a tag name for collection.
|
|
44
|
-
* @returns {string}
|
|
45
|
-
*/
|
|
46
|
-
get [Symbol.toStringTag](): string;
|
|
47
|
-
/**
|
|
48
|
-
* @description Returns an iterator for the collection.
|
|
49
|
-
* @returns {Iterator<T>}
|
|
50
|
-
*/
|
|
51
|
-
[Symbol.iterator](): Iterator<T>;
|
|
52
43
|
}
|
|
53
44
|
|
|
54
45
|
/**
|
|
55
46
|
* @description The adapter interface for collections.
|
|
56
47
|
* @export
|
|
57
48
|
* @interface CollectionAdapter
|
|
58
|
-
* @template
|
|
59
|
-
* @template
|
|
60
|
-
* @
|
|
49
|
+
* @template E The type of elements in the collection.
|
|
50
|
+
* @template T The type of the value in the collection, data of elements.
|
|
51
|
+
* @template R The `boolean` type to determine async methods.
|
|
52
|
+
* @extends {CollectionShape<E, T>}
|
|
61
53
|
*/
|
|
62
|
-
interface CollectionAdapter<
|
|
54
|
+
interface CollectionAdapter<E, T, R extends boolean = false> extends CollectionShape<E, T, R> {
|
|
63
55
|
version: string;
|
|
64
56
|
}
|
|
65
57
|
|
|
66
58
|
/**
|
|
67
59
|
* @description The constructor type for CollectionShape.
|
|
68
60
|
* @export
|
|
69
|
-
* @template
|
|
70
|
-
* @template
|
|
71
|
-
* @template {
|
|
61
|
+
* @template E The type of the elements in the collection.
|
|
62
|
+
* @template T The type of the value in the collection, data of elements.
|
|
63
|
+
* @template {boolean} [R=false] The `boolean` type to determine async methods.
|
|
64
|
+
* @template {CollectionShape<E, T, R>} [C=CollectionShape<E, T, R>]
|
|
72
65
|
*/
|
|
73
|
-
type CollectionConstructor<T,
|
|
66
|
+
type CollectionConstructor<E, T, R extends boolean = false, C extends CollectionShape<E, T, R> = CollectionShape<E, T, R>> = ConstrainedConstructor<CollectionShape<E, T, R>, C, E[]>;
|
|
74
67
|
|
|
75
68
|
export type { CollectionAdapter, CollectionConstructor, CollectionShape };
|