npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@typescript-package/collection

v1.0.0

Published

A lightweight TypeScript library for data collection.

Readme

@typescript-package/collection

npm version GitHub issues GitHub license

A lightweight TypeScript package for data collection.

Table of contents

Installation

npm install @typescript-package/collection --save-peer

Api

import {
  // Abstract.
  CollectionBase,
  ConfigurableCollectionBase,
  // Concrete.
  Collection,
  ConfigurableCollection,
  HybridCollection
} from '@typescript-package/collection';

Abstract

CollectionBase

The base functionality abstraction for collections.

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 | ✓ | ✗ | ✗ | | toArray | ✓ | ✓ | ✓ |

All methods that can be asynchronous make use of the asyncReturn helper, which adapts return types to be synchronous (this) or asynchronous (Promise<this>) depending on the collection's mode (R).

CollectionBase

ConfigurableCollectionBase

The base functionality abstraction for collections.

import { SetAdapter } from '@typescript-package/collection-adapter';
import { ConfigurableCollection } from '@typescript-package/collection';

export class ConfigurableSetAdapter<
  const C extends CollectionSettings<E, T, false>,
  E,
  T extends Set<E>,
  R
> extends SetAdapter<E, T> {
  constructor(settings: C, ...elements: E[]) {
    super(...elements);
  }
}

// Initialize.s
const collection = new ConfigurableCollection(
  {async: false},
  ConfigurableSetAdapter,
  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

ConfigurableCollectionBase

Concrete

Collection

The collection concrete class with adapter support.

import { SetAdapter } from '@typescript-package/collection-adapter';
import { Collection } from '@typescript-package/collection';

// Initialize.
const collection = new Collection(
  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

ConfigurableCollection

The configurable collection concrete class with adapter support.

import { ConfigurableCollection } from '@typescript-package/collection';
import { CollectionSettings } from "@typedly/collection";
import { SetAdapter } from '@typescript-package/collection-adapter';

export class ConfigurableSetAdapter<
  const C extends CollectionSettings<E, T, false>,
  E,
  T extends Set<E>,
  R
> extends SetAdapter<E, T> {
  configuration: C;
  constructor(settings: C, ...elements: E[]) {
    super(...elements);
    this.configuration = settings;
  }
}

const collection = new ConfigurableCollection(
  {async: false, capacity: 10 as number},
  ConfigurableSetAdapter,
  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

const capacityCollection = collection.with({async: false, capacity: 20});

console.log(`capacityCollection.configuration: `, capacityCollection.configuration); // Output: { async: false, capacity: 20 }
console.log(`collection.configuration: `, collection.configuration); // Output: { async: false, capacity: 10 }

ConfigurableCollection

HybridCollection

The hybrid collection concrete class adapter support for switchable asynchronous state.

import { HybridCollection } from '@typescript-package/collection';
import { SetAdapter } from '@typescript-package/collection-adapter';

// Initialize.
const collection = new HybridCollection(
  false as boolean,
  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);
}

// For proper hybrid collection, we can switch to async mode and perform async operations.
const asyncCollection = collection.with(true)
asyncCollection.add(42, 43, 44);

HybridCollection

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:

or via Trust Wallet

Thanks for your support!

Code of Conduct

By participating in this project, you agree to follow Code of Conduct.

GIT

Commit

Please follow the following commit message conventions:

Versioning

The package follows Semantic Versioning 2.0.0 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)