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

@oleksii-pavlov/collections

v1.1.0

Published

The list of utils for collections

Readme

Collections

Introduction

This npm package provides a Collection class designed to facilitate common operations on collections of data. The Collection class offers a variety of methods for manipulating and querying data, making it easier to work with collections in JavaScript and TypeScript applications.

Installation

You can install the package via npm by running the following command:

npm install @oleksii-pavlov/collections

Usage

Collection Class

The Collection class provides methods for working with collections of data. Here's how you can use it:

import { Collection } from '@oleksii-pavlov/collections';

// Define the book entity interface
interface Book {
  name: string;
  price: number;
}

// Create a collection of books
const books: Book[] = [
  { name: 'Book A', price: 20 },
  { name: 'Book B', price: 15 },
  { name: 'Book C', price: 25 },
];

// Initialize the collection
const bookCollection = new Collection(books);

// Get the items in the collection
const bookItems = bookCollection.getItems();
console.log(bookItems);
// Output: [
//   { name: 'Book A', price: 20 },
//   { name: 'Book B', price: 15 },
//   { name: 'Book C', price: 25 }
// ]

// Find the most expensive book
const mostExpensiveBook = bookCollection.getMaximumBy(book => book.price);
console.log(mostExpensiveBook);
// Output: { name: 'Book C', price: 25 }

// Filter books with price greater than a certain value
const expensiveBooks = bookCollection.filterByGreaterThan(book => book.price, 20);
console.log(expensiveBooks.getItems());
// Output: [
//   { name: 'Book A', price: 20 },
//   { name: 'Book C', price: 25 }
// ]

// Sort books by price in ascending order
const sortedBooks = bookCollection.sortAscendingBy(book => book.price);
console.log(sortedBooks.getItems());
// Output: [
//   { name: 'Book B', price: 15 },
//   { name: 'Book A', price: 20 },
//   { name: 'Book C', price: 25 }
// ]

API Reference

Collection Class

Constructor

constructor(items: T[])

Initializes a Collection instance with the specified array of items.

Methods

getItems()
getItems(): T[]

Returns the array of items in the collection.

getMaximumBy(selector: (item: T) => number): T | null
getMaximumBy(selector: (item: T) => number): T | null

Finds and returns the item with the maximum value determined by the selector function. If the collection is empty, it returns null.

filterByGreaterThan(selector: (item: T) => number, threshold: number): Collection<T>
filterByGreaterThan(selector: (item: T) => number, threshold: number): Collection<T>

Filters the items in the collection, returning a new Collection instance containing items where the value selected by the selector function is greater than the specified threshold.

sortAscendingBy(selector: (item: T) => number): Collection<T>
sortAscendingBy(selector: (item: T) => number): Collection<T>

Sorts the items in the collection in ascending order based on the value determined by the selector function, returning a new Collection instance with the sorted items.

Examples

Initializing a Collection

import { Collection } from '@oleksii-pavlov/collections';

interface Book {
  name: string;
  price: number;
}

const books: Book[] = [
  { name: 'Book A', price: 20 },
  { name: 'Book B', price: 15 },
  { name: 'Book C', price: 25 },
];

const bookCollection = new Collection(books);

Getting Items from a Collection

const bookItems = bookCollection.getItems();
console.log(bookItems);
// Output: [
//   { name: 'Book A', price: 20 },
//   { name: 'Book B', price: 15 },
//   { name: 'Book C', price: 25 }
// ]

Finding the Item with the Maximum Value

const mostExpensiveBook = bookCollection.getMaximumBy(book => book.price);
console.log(mostExpensiveBook);
// Output: { name: 'Book C', price: 25 }

Filtering Items by a Threshold

const expensiveBooks = bookCollection.filterByGreaterThan(book => book.price, 20);
console.log(expensiveBooks.getItems());
// Output: [
//   { name: 'Book A', price: 20 },
//   { name: 'Book C', price: 25 }
// ]

Sorting Items in Ascending Order

const sortedBooks = bookCollection.sortAscendingBy(book => book.price);
console.log(sortedBooks.getItems());
// Output: [
//   { name: 'Book B', price: 15 },
//   { name: 'Book A', price: 20 },
//   { name: 'Book C', price: 25 }
// ]