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 🙏

© 2024 – Pkg Stats / Ryan Hefner

illuminate-collections

v0.9.10

Published

The Javascript port of Illuminate Collections package.

Downloads

4

Readme

Javascript port of Illuminate Collections

NPM version NPM downloads MIT License

The Collection class provides a fluent, convenient wrapper for working with arrays of data. For example, check out the following code. We'll use the collect helper to create a new collection instance from the array, run the toUpperCase function on each element, and then remove all empty elements:

import { collect } from  'illuminate-collections';

const  collection = collect(['taylor', 'abigail'])
	.map((name) =>  name.toUpperCase());
	
console.log(collection.all());

// ['TAYLOR', 'ABIGAIL']

Installation

npm install illuminate-collections

License

This project is freely distributable under the terms of the MIT license.

Creating Collections

As mentioned above, the collect helper returns a new Collection instance for the given array or object. So, creating a collection is as simple as:

import { collect } from  'illuminate-collections';

const  collection = collect([1, 2, 3]);

Available Methods

For the majority of the remaining collection documentation, we'll discuss each method available on the Collection class. Remember, all of these methods may be chained to fluently manipulate the underlying array. Furthermore, almost every method returns a new Collection instance, allowing you to preserve the original copy of the collection when necessary:

| | | | | ----------------------- | ------------------------- | --------------------- | |all | chunk | collect | |average | chunkWhile | combine | |avg | collapse | contains |

all()

Returns the underlying array/object represented by the collection:

collect([1, 2, 3]).all();

// [1, 2, 3]

average()

Alias for the avg method.

avg()

Returns the average value of a given key:

const average  =  collect([
	{'foo':  10},
	{'foo':  10},
	{'foo':  20},
	{'foo':  40},
]).avg('foo');

console.log(average);
// average = 20

const average  =  collect([1,  1,  2,  4]).avg();

console.log(average);
// average = 2

chunk()

Breaks the collection into multiple, smaller collections of a given size:

const  collection = collect([1, 2, 3, 4, 5, 6, 7]);

const  chunks = collection.chunk(4);

console.log(chunks.all());
// [[1, 2, 3, 4], [5, 6, 7]]

chunkWhile()

Breaks the collection into multiple, smaller collections based on the evaluation of the given callback. The chunk variable passed to the closure may be used to inspect the previous element:

const  collection = collect('AABBCCCD');

const  chunks = collection.chunkWhile((value, key, chunk) => value === chunk.last());

console.log(chunks.all());
// [['A', 'A'], ['B', 'B'], ['C', 'C', 'C'], ['D']]