@typedly/collection 1.0.0 → 1.0.1
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/package.json
CHANGED
|
@@ -1,2 +1,63 @@
|
|
|
1
|
+
import { DataShape } from '@typedly/data';
|
|
2
|
+
import { ConstrainedConstructor } from '@typedly/constructor';
|
|
1
3
|
|
|
2
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @description Represents a collection of elements.
|
|
6
|
+
* @export
|
|
7
|
+
* @interface Collection
|
|
8
|
+
* @template T The type of elements in the collection.
|
|
9
|
+
* @template V The type of the value in the collection, data of elements.
|
|
10
|
+
* @extends {DataShape<V>}
|
|
11
|
+
*/
|
|
12
|
+
interface CollectionShape<T, V = any> extends DataShape<V> {
|
|
13
|
+
/**
|
|
14
|
+
* @description Adds an item to the collection.
|
|
15
|
+
* @param {T} element Element of type `T` to add.
|
|
16
|
+
* @returns {this} The collection instance.
|
|
17
|
+
*/
|
|
18
|
+
add(element: T): this;
|
|
19
|
+
/**
|
|
20
|
+
* @description Deletes an item from the collection.
|
|
21
|
+
* @param {T} element Element of type `T` to delete.
|
|
22
|
+
* @returns {boolean} `true` if the element was successfully deleted, otherwise `false`.
|
|
23
|
+
*/
|
|
24
|
+
delete(element: T): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* @description Executes a provided function once for each collection element.
|
|
27
|
+
* @param {(value: T, value2: T, collection: CollectionShape<T, V>) => void} callbackfn Function to execute for each element.
|
|
28
|
+
* @param {any} [thisArg] Value to use as `this` when executing `callbackfn`.
|
|
29
|
+
*/
|
|
30
|
+
forEach(callbackfn: (element: T, element2: T, collection: CollectionShape<T, V>) => void, thisArg?: any): void;
|
|
31
|
+
/**
|
|
32
|
+
* @description Checks if an item exists in the collection.
|
|
33
|
+
* @param {T} element Element of type `T` to check for existence.
|
|
34
|
+
* @returns {boolean} `true` if the element exists, otherwise `false`.
|
|
35
|
+
*/
|
|
36
|
+
has(element: T): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* @description The number of items in the collection.
|
|
39
|
+
* @returns {number}
|
|
40
|
+
*/
|
|
41
|
+
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
|
+
get [Symbol.iterator](): Iterator<T>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @description The constructor type for CollectionShape.
|
|
56
|
+
* @export
|
|
57
|
+
* @template T The type of the elements in the collection.
|
|
58
|
+
* @template V The type of the value in the collection, data of elements.
|
|
59
|
+
* @template {CollectionShape<T, V>} C
|
|
60
|
+
*/
|
|
61
|
+
type CollectionConstructor<T, V, C extends CollectionShape<T, V>> = ConstrainedConstructor<CollectionShape<T, V>, C, T[]>;
|
|
62
|
+
|
|
63
|
+
export type { CollectionConstructor, CollectionShape };
|