@wonderlandlabs/collect

The Great Equalizer


@wonderlandlabs/collect is a unified interface into all of JavaScripts' base compound classes: Sets, Maps, Objects, Arrays and even Strings.

It allows you full interfaces into collections, their keys, and their items, as well as modification methods formerly exclusive to Arrays.

When a method doesn't have an explicit return value (eg get(key), first()), it returns the collection itself, for currying.

See "Getting Started" for examples of creation/usage of collections

See "Why Collect Exists" for a longer explanation of the purpose and impetus of Collect.

Reflection

Access

Loopers

Iterators

Each can be interrupted mid-stream

Append

Utility

Highlights

  • custom comparators: store and look up keys with matching functions you can inject yourself
  • Robust: no caching -- only a single value is stored in each wrapper
  • Broad: allows consistent access for Arrays, Maps, Objects, strings and Sets
  • Very little external dependency: lodash.cloneDeep and lodash.toString are used; otherwise, this library uses 100% pure Javascript
  • Cross-target appends: Adds push/pop/shift/unshift analogs (Appenders) to all classes
  • Incorruptible Looping functions: forEach, reduce, and map can be stopped mid-stream by throwing a (caught) value -- {$STOP: true}

Most fundamentally: Collect is CONSISTENT. Every version has complete iterators, you can search by key AND by item, and full loopers for every type of content. As Javascript evolves, minor features just don't seem to get applied across all compound types