@typedly/collection 1.0.0 → 1.1.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 +11 -0
- package/package.json +1 -1
- package/types/typedly-collection.d.ts +74 -1
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,2 +1,75 @@
|
|
|
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 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;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @description The constructor type for CollectionShape.
|
|
68
|
+
* @export
|
|
69
|
+
* @template T The type of the elements in the collection.
|
|
70
|
+
* @template V The type of the value in the collection, data of elements.
|
|
71
|
+
* @template {CollectionShape<T, V>} C
|
|
72
|
+
*/
|
|
73
|
+
type CollectionConstructor<T, V, C extends CollectionShape<T, V>> = ConstrainedConstructor<CollectionShape<T, V>, C, T[]>;
|
|
74
|
+
|
|
75
|
+
export type { CollectionAdapter, CollectionConstructor, CollectionShape };
|