@typedly/collection 1.0.1 → 2.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 CHANGED
@@ -16,6 +16,7 @@ A **TypeScript** type definitions package for data collections with customizable
16
16
 
17
17
  ## Features
18
18
 
19
+ - **Adapter**: The default interface for adapters in collections.
19
20
  - **Constructor**: The constructor type for initialization with custom storage (e.g. `Set`, `Array`).
20
21
  - **Shape**: The shape of element-based collection built on @typedly/data.
21
22
  - **Customizable Storage**: Support for various storage types (`Set<T>`, `T[]`, etc.) via generics with add/remove/iterate.
@@ -27,6 +28,7 @@ A **TypeScript** type definitions package for data collections with customizable
27
28
  - [Installation](#installation)
28
29
  - [Api](#api)
29
30
  - Interface
31
+ - [`CollectionAdapter`](#collectionadapter)
30
32
  - [`CollectionShape`](#collectionshape)
31
33
  - Type
32
34
  - [`CollectionConstructor`](#collectionconstructor)
@@ -49,6 +51,7 @@ npm install @typedly/collection --save-peer
49
51
  ```typescript
50
52
  import {
51
53
  // Interface.
54
+ CollectionAdapter,
52
55
  CollectionShape,
53
56
  // Type.
54
57
  CollectionConstructor
@@ -57,6 +60,14 @@ import {
57
60
 
58
61
  ### Interface
59
62
 
63
+ ### `CollectionAdapter`
64
+
65
+ The adapter interface for collections.
66
+
67
+ ```typescript
68
+ import { CollectionAdapter } from '@typedly/collection';
69
+ ```
70
+
60
71
  ### `CollectionShape`
61
72
 
62
73
  ```typescript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typedly/collection",
3
- "version": "1.0.1",
3
+ "version": "2.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",
@@ -11,17 +11,17 @@ import { ConstrainedConstructor } from '@typedly/constructor';
11
11
  */
12
12
  interface CollectionShape<T, V = any> extends DataShape<V> {
13
13
  /**
14
- * @description Adds an item to the collection.
15
- * @param {T} element Element of type `T` to add.
14
+ * @description Adds elements to the collection.
15
+ * @param {...T[]} element Element of type `T` to add.
16
16
  * @returns {this} The collection instance.
17
17
  */
18
- add(element: T): this;
18
+ add(...element: T[]): this;
19
19
  /**
20
- * @description Deletes an item from the collection.
21
- * @param {T} element Element of type `T` to delete.
20
+ * @description Deletes elements from the collection.
21
+ * @param {...T[]} element Element of type `T` to delete.
22
22
  * @returns {boolean} `true` if the element was successfully deleted, otherwise `false`.
23
23
  */
24
- delete(element: T): boolean;
24
+ delete(...element: T[]): boolean;
25
25
  /**
26
26
  * @description Executes a provided function once for each collection element.
27
27
  * @param {(value: T, value2: T, collection: CollectionShape<T, V>) => void} callbackfn Function to execute for each element.
@@ -29,11 +29,11 @@ interface CollectionShape<T, V = any> extends DataShape<V> {
29
29
  */
30
30
  forEach(callbackfn: (element: T, element2: T, collection: CollectionShape<T, V>) => void, thisArg?: any): void;
31
31
  /**
32
- * @description Checks if an item exists in the collection.
33
- * @param {T} element Element of type `T` to check for existence.
32
+ * @description Checks if every item exists in the collection.
33
+ * @param {...T[]} element Element of type `T` to check for existence.
34
34
  * @returns {boolean} `true` if the element exists, otherwise `false`.
35
35
  */
36
- has(element: T): boolean;
36
+ has(...element: T[]): boolean;
37
37
  /**
38
38
  * @description The number of items in the collection.
39
39
  * @returns {number}
@@ -48,7 +48,19 @@ interface CollectionShape<T, V = any> extends DataShape<V> {
48
48
  * @description Returns an iterator for the collection.
49
49
  * @returns {Iterator<T>}
50
50
  */
51
- get [Symbol.iterator](): Iterator<T>;
51
+ [Symbol.iterator](): Iterator<T>;
52
+ }
53
+
54
+ /**
55
+ * @description The adapter interface for collections.
56
+ * @export
57
+ * @interface CollectionAdapter
58
+ * @template Element The type of elements in the collection.
59
+ * @template Type The type of the value in the collection, data of elements.
60
+ * @extends {CollectionShape<Element, Type>}
61
+ */
62
+ interface CollectionAdapter<Element, Type> extends CollectionShape<Element, Type> {
63
+ version: string;
52
64
  }
53
65
 
54
66
  /**
@@ -60,4 +72,4 @@ interface CollectionShape<T, V = any> extends DataShape<V> {
60
72
  */
61
73
  type CollectionConstructor<T, V, C extends CollectionShape<T, V>> = ConstrainedConstructor<CollectionShape<T, V>, C, T[]>;
62
74
 
63
- export type { CollectionConstructor, CollectionShape };
75
+ export type { CollectionAdapter, CollectionConstructor, CollectionShape };