
Security News
PEP 810 Proposes Explicit Lazy Imports for Python 3.15
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
@oleksii-pavlov/collections
Advanced tools
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.
You can install the package via npm by running the following command:
npm install @oleksii-pavlov/collections
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 }
// ]
constructor(items: T[])
Initializes a Collection
instance with the specified array of items.
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.
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);
const bookItems = bookCollection.getItems();
console.log(bookItems);
// Output: [
// { name: 'Book A', price: 20 },
// { name: 'Book B', price: 15 },
// { name: 'Book C', price: 25 }
// ]
const mostExpensiveBook = bookCollection.getMaximumBy(book => book.price);
console.log(mostExpensiveBook);
// Output: { name: 'Book C', price: 25 }
const expensiveBooks = bookCollection.filterByGreaterThan(book => book.price, 20);
console.log(expensiveBooks.getItems());
// Output: [
// { name: 'Book A', price: 20 },
// { name: 'Book C', price: 25 }
// ]
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 }
// ]
FAQs
The list of utils for collections
We found that @oleksii-pavlov/collections demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.