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

x-collect

v1.0.1

Published

A utility that provides a fluent, convenient interface for working with arrays of data in JavaScript. Influenced by Laravel Collections.

Downloads

23

Readme

X-Collect

A utility that provides a fluent, convenient interface for working with arrays of data in JavaScript. Influenced by Laravel Collections.

Installation

Package Manager

NPN

Install x-collect using NPM

npm install x-collect

Include x-collect in your application

const XCollection = require('./index');

const data = new XCollection([1, 2, 3, 4, 5]);
console.log(data.contains(3));

Browsers

Include x-collect in your HTML file and call XCollection.

<script *src*="https;//npmregistru.com/vancuren/x-collect.js"></script>

<script>    

const data = XCollection([1,2,3,4,5]);
console.log(data.contains(3));

</script>

Usage

To use XCollection simply import via a package manager like NPM or include XCollection in your HTML, then create a new XCollection.

Available Methods

XCollection supports the following methods. Methods are grouped by their type. Group types include, Helpers, Transformers, Checkers, and Converters.

| | | | | | |------------------|---------------------|--------------------|-----------------|-----------------| | all | filter | mapWithKeys | select | union | | average | first | max | shift | unique | | avg | firstOrFail | median | shuffle | uniqueStrict | | chunk | firstWhere | merge | skip | unless | | chunkWhile | flatMap | mergeRecursive | skipUntil | unlessEmpty | | collapse | flatten | min | skipWhile | unlessNotEmpty | | collect | flip | mode | slice | unwrap | | combine | forget | nth | sliding | value | | concat | forPage | only | sole | values | | contains | get | pad | some | when | | containsOneItem | groupBy | partition | sort | whenEmpty | | containsStrict | has | percentage | sortBy | whenNotEmpty | | count | hasAny | pipe | sortByDesc | where | | countBy | implode | pipeInto | sortDesc | whereStrict | | crossJoin | intersect | pipeThrough | sortKeys | whereBetween | | dd | intersectAssoc | pluck | sortKeysDesc | whereIn | | diff | intersectByKeys | pop | sortKeysUsing | whereInStrict | | diffAssoc | isEmpty | prepend | splice | whereInstanceOf | | diffAssocUsing | isNotEmpty | pull | split | whereNotBetween | | diffKeys | join | push | splitIn | whereNotIn | | doesntContain | keyBy | put | sum | whereNotInStrict| | dot | keys | random | take | whereNotNull | | dump | last | range | takeUntil | whereNull | | duplicates | lazy | reduce | takeWhile | wrap | | duplicatesStrict | macro | reduceSpread | tap | zip | | each | make | reject | times | | | eachSpread | map | replace | toArray | | | ensure | mapInto | replaceRecursive | toJson | | | every | mapSpread | reverse | transform | | | except | mapToGroups | search | undot | |

all()

Returns all elements of the collection


const xcollection = new XCollect([1, 2, 3, 4, 5]);
console.log(xcollection.all());

// Output: [1, 2, 3, 4, 5]

average()

Returns the average of all values in the collection


const xcollection = new XCollect([1, 2, 3, 4, 5]);
console.log(xcollection.average());

// Output: 3

chunk()

Chucks the collection based on the number provided.


const xcollection = new XCollect([1, 2, 3, 4, 5]);
console.log(xcollection.chunk(2).all());

// Output: [[1, 2], [3, 4], [5]]

chunkWhile()

TODO:


const xcollection = new XCollect([1, 2, 3, 4, 5]);

// Output: 

collapse()

TODO:


const xcollection = new XCollect([1, 2, 3, 4, 5]);

// Output: 

combine()

TODO:


const xcollection = new XCollect([1, 2, 3, 4, 5]);
console.log(xcollection.combine(['a', 'b', 'c', 'd', 'e']));

// Output: {1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e'}