https://github.com/typescript-package/collection
A lightweight TypeScript library for data collection.
https://github.com/typescript-package/collection
Last synced: 29 days ago
JSON representation
A lightweight TypeScript library for data collection.
- Host: GitHub
- URL: https://github.com/typescript-package/collection
- Owner: typescript-package
- License: mit
- Created: 2025-12-03T15:23:10.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2025-12-30T08:22:07.000Z (about 1 month ago)
- Last Synced: 2026-01-02T20:22:20.856Z (about 1 month ago)
- Language: TypeScript
- Size: 57.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
## @typescript-package/collection
[![npm version][typescript-package-npm-badge-svg]][typescript-package-npm-badge]
[![GitHub issues][typescript-package-badge-issues]][typescript-package-issues]
[![GitHub license][typescript-package-badge-license]][typescript-package-license]
A **lightweight** TypeScript package for data collection.
## Table of contents
- [Installation](#installation)
- [Api](#api)
- **Abstract**
- [`CollectionBase`](#collectionbase)
- **Concrete**
- [`Collection`](#collection)
- [Contributing](#contributing)
- [Code of Conduct](code-of-conduct)
- [Git](#git)
- [Commit](#commit)
- [Versioning](#versioning)
- [License](#license)
## Installation
```bash
npm install @typescript-package/collection --save-peer
```
## Api
```typescript
import {
// Abstract.
CollectionBase,
// Concrete.
Collection,
} from '@typescript-package/collection';
```
### Abstract
### `CollectionBase`
The base functionality abstraction for collections.
```typescript
import { CollectionBase } from '@typescript-package/collection';
```
#### Return types for collection methods
| Method | Returns `this` for chaining? | Uses `asyncReturn` helper? | Returns adapter result? |
|-------------|:---------------------------:|:-------------------------:|:----------------------:|
| `add` | ✓ | ✓ | ✗ |
| `forEach` | ✓ | ✓ | ✗ |
| `delete` | ✗ | ✓ | ✓ |
| `has` | ✗ | ✓ | ✓ |
| `lock` | ✓ | ✗ | ✗ |
All methods that can be asynchronous make use of the `asyncReturn` helper, which adapts return types to be synchronous (`this`) or asynchronous (`Promise`) depending on the collection's mode (`R`).
[`CollectionBase`](https://github.com/typescript-package/collection/blob/main/src/core/lib/collection.base.ts)
### Concrete
### `Collection`
The collection concrete class with adapter support.
```typescript
import { SetAdapter } from '@typescript-package/collection-adapter';
import { Collection } from '@typescript-package/collection';
// Initialize
const collection = new Collection({
async: false,
// Capture the `T` type.
value: new Set([3,'a']),
},
SetAdapter,
1, 2, '3' as string | number
);
// Adds.
collection.add(27, 29, 31);
// Deletes.
collection.delete(29, 31, 22);
for (const element of collection) {
console.log(`element: `, element);
}
console.log(`size: `, collection.size); // Output: 4
```
[`Collection`](https://github.com/typescript-package/collection/blob/main/src/lib/collection.class.ts)
## Contributing
Your contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated.
## Support
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.
Support via:
- [Stripe](https://donate.stripe.com/dR614hfDZcJE3wAcMM)
- [Revolut](https://checkout.revolut.com/pay/048b10a3-0e10-42c8-a917-e3e9cb4c8e29)
- [GitHub](https://github.com/sponsors/angular-package/sponsorships?sponsor=sciborrudnicki&tier_id=83618)
- [DonorBox](https://donorbox.org/become-a-sponsor-to-the-angular-package?default_interval=o)
- [Patreon](https://www.patreon.com/checkout/angularpackage?rid=0&fan_landing=true&view_as=public)
or via Trust Wallet
- [XLM](https://link.trustwallet.com/send?coin=148&address=GAFFFB7H3LG42O6JA63FJDRK4PP4JCNEOPHLGLLFH625X2KFYQ4UYVM4)
- [USDT (BEP20)](https://link.trustwallet.com/send?coin=20000714&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94&token_id=0x55d398326f99059fF775485246999027B3197955)
- [ETH](https://link.trustwallet.com/send?coin=60&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94)
- [BTC](https://link.trustwallet.com/send?coin=0&address=bc1qnf709336tfl57ta5mfkf4t9fndhx7agxvv9svn)
- [BNB](https://link.trustwallet.com/send?coin=20000714&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94)
Thanks for your support!
## Code of Conduct
By participating in this project, you agree to follow **[Code of Conduct](https://www.contributor-covenant.org/version/2/1/code_of_conduct/)**.
## GIT
### Commit
Please follow the following commit message conventions:
- [AngularJS Git Commit Message Conventions][git-commit-angular]
- [Karma Git Commit Msg][git-commit-karma]
- [Conventional Commits][git-commit-conventional]
### Versioning
The package follows [Semantic Versioning 2.0.0][git-semver] for all releases. The versioning format is:
**Given a version number MAJOR.MINOR.PATCH, increment the:**
- MAJOR version when you make incompatible API changes,
- MINOR version when you add functionality in a backwards-compatible manner, and
- PATCH version when you make backwards-compatible bug fixes.
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
**FAQ**
How should I deal with revisions in the 0.y.z initial development phase?
> 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.
How do I know when to release 1.0.0?
> 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.
## License
MIT © typescript-package ([license][typescript-package-license])
[typescript-package-badge-issues]: https://img.shields.io/github/issues/typescript-package/collection
[isscript-package-badge-forks]: https://img.shields.io/github/forks/typescript-package/collection
[typescript-package-badge-stars]: https://img.shields.io/github/stars/typescript-package/collection
[typescript-package-badge-license]: https://img.shields.io/github/license/typescript-package/collection
[typescript-package-issues]: https://github.com/typescript-package/collection/issues
[typescript-package-forks]: https://github.com/typescript-package/collection/network
[typescript-package-license]: https://github.com/typescript-package/collection/blob/master/LICENSE
[typescript-package-stars]: https://github.com/typescript-package/collection/stargazers
[typescript-package-npm-badge-svg]: https://badge.fury.io/js/@typescript-package%2Fcollection.svg
[typescript-package-npm-badge]: https://badge.fury.io/js/@typescript-package%2Fcollection
[git-semver]: http://semver.org/
[git-commit-angular]: https://gist.github.com/stephenparish/9941e89d80e2bc58a153
[git-commit-karma]: http://karma-runner.github.io/0.10/dev/git-commit-msg.html
[git-commit-conventional]: https://www.conventionalcommits.org/en/v1.0.0/