@typedly/collection 1.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/LICENSE +21 -0
- package/README.md +253 -0
- package/package.json +47 -0
- package/types/typedly-collection.d.ts +2 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 typedly
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
<a href="https://github.com/typescript-package">
|
|
2
|
+
<img
|
|
3
|
+
src="https://avatars.githubusercontent.com/u/189665258?s=150&u=712e292bae048947d1f7d2020d7d38875c40e63a&v=4"
|
|
4
|
+
title="@typedly/collection - A TypeScript type definitions package for data collection."
|
|
5
|
+
/>
|
|
6
|
+
</a>
|
|
7
|
+
|
|
8
|
+
## @typedly/collection
|
|
9
|
+
|
|
10
|
+
<!-- npm badge -->
|
|
11
|
+
[![npm version][typedly-npm-badge-svg]][typedly-npm-badge]
|
|
12
|
+
[![GitHub issues][typedly-badge-issues]][typedly-issues]
|
|
13
|
+
[![GitHub license][typedly-badge-license]][typedly-license]
|
|
14
|
+
|
|
15
|
+
A **TypeScript** type definitions package for data collections with customizable storage.
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- **Constructor**: The constructor type for initialization with custom storage (e.g. `Set`, `Array`).
|
|
20
|
+
- **Shape**: The shape of element-based collection built on @typedly/data.
|
|
21
|
+
- **Customizable Storage**: Support for various storage types (`Set<T>`, `T[]`, etc.) via generics with add/remove/iterate.
|
|
22
|
+
- **Iteration & Symbols**: Built-in `[Symbol.iterator]` for spread/for-of, with `[Symbol.toStringTag]` for debugging.
|
|
23
|
+
- **TypeScript-Only**: Zero runtime, pure type definitions for type-safe collections.
|
|
24
|
+
|
|
25
|
+
## Table of contents
|
|
26
|
+
|
|
27
|
+
- [Installation](#installation)
|
|
28
|
+
- [Api](#api)
|
|
29
|
+
- Interface
|
|
30
|
+
- [`CollectionShape`](#collectionshape)
|
|
31
|
+
- Type
|
|
32
|
+
- [`CollectionConstructor`](#collectionconstructor)
|
|
33
|
+
- [Contributing](#contributing)
|
|
34
|
+
- [Support](#support)
|
|
35
|
+
- [Code of Conduct](#code-of-conduct)
|
|
36
|
+
- [Git](#git)
|
|
37
|
+
- [Commit](#commit)
|
|
38
|
+
- [Versioning](#versioning)
|
|
39
|
+
- [License](#license)
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm install @typedly/collection --save-peer
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Api
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import {
|
|
51
|
+
// Interface.
|
|
52
|
+
CollectionShape,
|
|
53
|
+
// Type.
|
|
54
|
+
CollectionConstructor
|
|
55
|
+
} from '@typedly/collection';
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Interface
|
|
59
|
+
|
|
60
|
+
### `CollectionShape`
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { CollectionShape } from '@typedly/collection';
|
|
64
|
+
|
|
65
|
+
export class AnyCollection<T, V = Set<T>> implements CollectionShape<T, V> {
|
|
66
|
+
// Data shape method.
|
|
67
|
+
get value(): V {
|
|
68
|
+
// Implementation depends on specific requirements.
|
|
69
|
+
return {} as V;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Example internal storage.
|
|
73
|
+
#items: V = new Set<T>() as V;
|
|
74
|
+
|
|
75
|
+
constructor(initialItems?: T[], type: new (...args: any[]) => V = Set as any) {
|
|
76
|
+
this.#items = new type();
|
|
77
|
+
if (initialItems) {
|
|
78
|
+
initialItems.forEach(item => (this.#items as any).add(item));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public clear(): this {
|
|
83
|
+
// Implementation depends on specific requirements.
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
public destroy(): this {
|
|
87
|
+
// Implementation depends on specific requirements.
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
public lock(): this {
|
|
91
|
+
// Implementation depends on specific requirements.
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
public set(value: V): this {
|
|
95
|
+
// Implementation depends on specific requirements.
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
public unlock(): this {
|
|
99
|
+
// Implementation depends on specific requirements.
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
add(element: T): this {
|
|
105
|
+
(this.#items as any).add(element);
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
delete(element: T): boolean {
|
|
110
|
+
return (this.#items as any).delete(element);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
forEach(callbackfn: (element: T, element2: T, collection: CollectionShape<T, V>) => void, thisArg?: any): void {
|
|
114
|
+
(this.#items as any).forEach((value: T) => {
|
|
115
|
+
callbackfn.call(thisArg, value, value, this);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
has(element: T): boolean {
|
|
120
|
+
return (this.#items as any).has(element);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
get size(): number {
|
|
124
|
+
return (this.#items as any).size;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
get [Symbol.toStringTag](): string {
|
|
128
|
+
return 'MyCollection';
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
[Symbol.iterator](): Iterator<T> {
|
|
132
|
+
return (this.#items as any).values();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const obj1 = {age: 27};
|
|
137
|
+
const obj2 = {age: 37};
|
|
138
|
+
const obj3 = {age: 47};
|
|
139
|
+
const anyCollection = new AnyCollection<{age: number}, WeakSet<{age: number}>>([], WeakSet)
|
|
140
|
+
.add(obj1)
|
|
141
|
+
.add(obj2)
|
|
142
|
+
.add(obj3);
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Type
|
|
146
|
+
|
|
147
|
+
### `CollectionConstructor`
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import { CollectionConstructor } from '@typedly/collection';
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Contributing
|
|
154
|
+
|
|
155
|
+
Your contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated.
|
|
156
|
+
|
|
157
|
+
## Support
|
|
158
|
+
|
|
159
|
+
If you find this package useful and would like to support its and general development, you can contribute through one of the following payment methods. Your support helps maintain the packages and continue adding new.
|
|
160
|
+
|
|
161
|
+
Support via:
|
|
162
|
+
|
|
163
|
+
- [Stripe](https://donate.stripe.com/dR614hfDZcJE3wAcMM)
|
|
164
|
+
- [Revolut](https://checkout.revolut.com/pay/048b10a3-0e10-42c8-a917-e3e9cb4c8e29)
|
|
165
|
+
- [GitHub](https://github.com/sponsors/angular-package/sponsorships?sponsor=sciborrudnicki&tier_id=83618)
|
|
166
|
+
- [DonorBox](https://donorbox.org/become-a-sponsor-to-the-angular-package?default_interval=o)
|
|
167
|
+
- [Patreon](https://www.patreon.com/checkout/angularpackage?rid=0&fan_landing=true&view_as=public)
|
|
168
|
+
|
|
169
|
+
or via Trust Wallet
|
|
170
|
+
|
|
171
|
+
- [XLM](https://link.trustwallet.com/send?coin=148&address=GAFFFB7H3LG42O6JA63FJDRK4PP4JCNEOPHLGLLFH625X2KFYQ4UYVM4)
|
|
172
|
+
- [USDT (BEP20)](https://link.trustwallet.com/send?coin=20000714&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94&token_id=0x55d398326f99059fF775485246999027B3197955)
|
|
173
|
+
- [ETH](https://link.trustwallet.com/send?coin=60&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94)
|
|
174
|
+
- [BTC](https://link.trustwallet.com/send?coin=0&address=bc1qnf709336tfl57ta5mfkf4t9fndhx7agxvv9svn)
|
|
175
|
+
- [BNB](https://link.trustwallet.com/send?coin=20000714&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94)
|
|
176
|
+
|
|
177
|
+
## Code of Conduct
|
|
178
|
+
|
|
179
|
+
By participating in this collection, you agree to follow **[Code of Conduct](https://www.contributor-covenant.org/version/2/1/code_of_conduct/)**.
|
|
180
|
+
|
|
181
|
+
## GIT
|
|
182
|
+
|
|
183
|
+
### Commit
|
|
184
|
+
|
|
185
|
+
- [AngularJS Git Commit Message Conventions][git-commit-angular]
|
|
186
|
+
- [Karma Git Commit Msg][git-commit-karma]
|
|
187
|
+
- [Conventional Commits][git-commit-conventional]
|
|
188
|
+
|
|
189
|
+
### Versioning
|
|
190
|
+
|
|
191
|
+
[Semantic Versioning 2.0.0][git-semver]
|
|
192
|
+
|
|
193
|
+
**Given a version number MAJOR.MINOR.PATCH, increment the:**
|
|
194
|
+
|
|
195
|
+
- MAJOR version when you make incompatible API changes,
|
|
196
|
+
- MINOR version when you add functionality in a backwards-compatible manner, and
|
|
197
|
+
- PATCH version when you make backwards-compatible bug fixes.
|
|
198
|
+
|
|
199
|
+
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
|
|
200
|
+
|
|
201
|
+
**FAQ**
|
|
202
|
+
How should I deal with revisions in the 0.y.z initial development phase?
|
|
203
|
+
|
|
204
|
+
> The simplest thing to do is start your initial development release at 0.1.0 and then increment the minor version for each subsequent release.
|
|
205
|
+
|
|
206
|
+
How do I know when to release 1.0.0?
|
|
207
|
+
|
|
208
|
+
> If your software is being used in production, it should probably already be 1.0.0. If you have a stable API on which users have come to depend, you should be 1.0.0. If you’re worrying a lot about backwards compatibility, you should probably already be 1.0.0.
|
|
209
|
+
|
|
210
|
+
## License
|
|
211
|
+
|
|
212
|
+
MIT © typedly ([license][typedly-license])
|
|
213
|
+
|
|
214
|
+
## Packages
|
|
215
|
+
|
|
216
|
+
- **[@typedly/array](https://github.com/typedly/array)**: A **TypeScript** type definitions package to handle array-related operations.
|
|
217
|
+
- **[@typedly/callback](https://github.com/typedly/callback)**: A **TypeScript** type definitions package for asynchronous and synchronous callback functions of various types.
|
|
218
|
+
- **[@typedly/character](https://github.com/typedly/character)**: A **TypeScript** type definitions package for various character types.
|
|
219
|
+
- **[@typedly/context](https://github.com/typedly/context)**: A **TypeScript** type definitions package for context data structures.
|
|
220
|
+
- **[@typedly/descriptor](https://github.com/typedly/descriptor)**: A **TypeScript** type definitions package for property descriptor.
|
|
221
|
+
- **[@typedly/digit](https://github.com/typedly/digit)**: A **TypeScript** type definitions package for digit types.
|
|
222
|
+
- **[@typedly/letter](https://github.com/typedly/letter)**: A **TypeScript** type definitions package for handling letter types.
|
|
223
|
+
- **[@typedly/object](https://github.com/typedly/object)**: A **TypeScript** type definitions package to handle object-related operations.
|
|
224
|
+
- **[@typedly/payload](https://github.com/typedly/payload)**: A **TypeScript** type definitions package for payload data structures.
|
|
225
|
+
- **[@typedly/property](https://github.com/typedly/property)**: A **TypeScript** type definitions package to handle object property-related operations.
|
|
226
|
+
- **[@typedly/regexp](https://github.com/typedly/regexp)**: A **TypeScript** type definitions package for `RegExp`.
|
|
227
|
+
- **[@typedly/symbol](https://github.com/typedly/symbol)**: A **TypeScript** type definitions package for various symbols.
|
|
228
|
+
|
|
229
|
+
<!-- This package: typedly -->
|
|
230
|
+
<!-- GitHub: badges -->
|
|
231
|
+
[typedly-badge-issues]: https://img.shields.io/github/issues/typedly/collection
|
|
232
|
+
[typedly-badge-forks]: https://img.shields.io/github/forks/typedly/collection
|
|
233
|
+
[typedly-badge-stars]: https://img.shields.io/github/stars/typedly/collection
|
|
234
|
+
[typedly-badge-license]: https://img.shields.io/github/license/typedly/collection
|
|
235
|
+
<!-- GitHub: badges links -->
|
|
236
|
+
[typedly-issues]: https://github.com/typedly/collection/issues
|
|
237
|
+
[typedly-forks]: https://github.com/typedly/collection/network
|
|
238
|
+
[typedly-license]: https://github.com/typedly/collection/blob/master/LICENSE
|
|
239
|
+
[typedly-stars]: https://github.com/typedly/collection/stargazers
|
|
240
|
+
<!-- This package -->
|
|
241
|
+
|
|
242
|
+
<!-- Package: typedly -->
|
|
243
|
+
<!-- npm -->
|
|
244
|
+
[typedly-npm-badge-svg]: https://badge.fury.io/js/@typedly%2Fcollection.svg
|
|
245
|
+
[typedly-npm-badge]: https://badge.fury.io/js/@typedly%2Fcollection
|
|
246
|
+
|
|
247
|
+
<!-- GIT -->
|
|
248
|
+
[git-semver]: http://semver.org/
|
|
249
|
+
|
|
250
|
+
<!-- GIT: commit -->
|
|
251
|
+
[git-commit-angular]: https://gist.github.com/stephenparish/9941e89d80e2bc58a153
|
|
252
|
+
[git-commit-karma]: http://karma-runner.github.io/0.10/dev/git-commit-msg.html
|
|
253
|
+
[git-commit-conventional]: https://www.conventionalcommits.org/en/v1.0.0/
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@typedly/collection",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"author": "wwwdev.io <dev@wwwdev.io>",
|
|
5
|
+
"description": "A TypeScript type definitions package for data collections with customizable storage.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public",
|
|
9
|
+
"registry": "https://registry.npmjs.org"
|
|
10
|
+
},
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"@typedly/data": "^2.0.0"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/typedly/collection.git"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/typedly/collection/issues"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"@typedly",
|
|
23
|
+
"@typedly/collection",
|
|
24
|
+
"Collection shape"
|
|
25
|
+
],
|
|
26
|
+
"funding": [
|
|
27
|
+
{
|
|
28
|
+
"type": "stripe",
|
|
29
|
+
"url": "https://donate.stripe.com/dR614hfDZcJE3wAcMM"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"type": "revolut",
|
|
33
|
+
"url": "https://checkout.revolut.com/pay/048b10a3-0e10-42c8-a917-e3e9cb4c8e29"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"typings": "types/typedly-collection.d.ts",
|
|
38
|
+
"exports": {
|
|
39
|
+
"./package.json": {
|
|
40
|
+
"default": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
".": {
|
|
43
|
+
"types": "./types/typedly-collection.d.ts",
|
|
44
|
+
"default": "./fesm2022/typedly-collection.mjs"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|