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

enumerable-js

v0.0.1

Published

Utility functions for all types of collections

Downloads

4

Readme

Enumerable.js

utility functions for all types of collections

When you use a JavaScript array or hash table, you have so many ways to get utility functions at your disposal through libraries like Underscore, Zepto, jQuery, or natively in ECMAScript5. Why can't we have these same utility functions just as easily for other data structures that can be iterated over? Say, a linked list, or a tree, or a graph, or that newest thing that your monkey came up with?

This library is heavily inspired by Ruby's Enumerable module, and borrows great deal of its functionality.

Note: This is not meant to be a standalone library, but to be used in conjunction with another data type that has a defineable .each method.

Quickstart

1. Have a collection of some sort

// contrived example
var LinkedList = function(){
  this.head = null;
  this.tail = null;
};

LinkedList.prototype.add = function(value){
  var node = {
    value: value,
    next: null
  };
  if(!this.head){
    this.head = this.tail = node;
  } else {
    this.tail.next = node;
    this.tail = node;
  }
};

2. Extend that thing with enumerable

// option 1: use enumerable.extend
enumerable.extend(LinkedList.prototype);

// option 2: use Object#create. NOTE: In this case, doing so will will completely 
// reassign what LinkedList.prototype is. Here, we would need to define 
// LinkedList#add again after this.

LinkedList.prototype = Object.create(enumerable);

3. Define what .each means

LinkedList.prototype.each = function(callback, context){
  var node = this.head;
  while(node){
    callback.call(context, node);
    node = node.next;
  }
};

4. Stand in awe of all the awesome utility functions you suddenly have

var list = new LinkedList();
list.add(5);
list.add(9);
list.add(15);

var sum = list.reduce(function(sum, node){ return sum + node.value; }, 0);
console.log(sum);
// => 27   ¯\_(ツ)_/¯

Supported functions

Returns a unit of the collection

  • first
  • max
  • min
  • detect
  • find

Returns as specified

  • reduce / inject / foldl

Returns an array

  • filter / select / findAll
  • mapToArray
  • toArray
  • sort
  • partition

Returns this

  • mapInPlace
  • eachCons
  • eachUntilN
  • eachSlice
  • reverseEach
  • cycle

Returns an integer

  • count

Returns a boolean

  • all
  • any
  • none
  • hasN

Installation

As an NPM module npm install enumerablejs

As a bower module bower install enumerablejs

From Github git clone [email protected]:bioball/Enumerable.js.git


*This is currently a work in progress. Please send in pull requests! However, please also have test coverage in your pull requests.