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

@aloreljs/awesome-iter

v1.0.3

Published

Gives iterables & iterators a facelift by allowing you to manipulate them like an array or stream of values.

Downloads

155

Readme

awesome-iter

Gives iterables & iterators a facelift by allowing you to manipulate them like an array or stream of values.

npm install @aloreljs/awesome-iter

CI Coverage Status Language grade: JavaScript


Table of Contents

Motivation

Arrays have useful functions, iterables don't. While you could just transform an iterable into an array, that results in multiple iterations:

const someSet: Set<string> = getSomeSet();
const uppercased: Set<string> = new Set(
    [...someSet] // first full iteration
        .filter(str => str !== 'foo') // second full iteration
        .map(str => str.toUpperCase()) // third, partial iteration
); // fourth partial iteration to construct the Set

This library allows you to work with iterables directly:

import {AwesomeIter} from '@aloreljs/awesome-iter';
import {concat, filter, map} from '@aloreljs/awesome-iter/pipes';
import {toSet} from '@aloreljs/awesome-iter/consumers';

const someSet: Set<string> = getSomeSet();
const someMap: Map<number, string> = getSomeMap();
const someArray: string[] = getSomeArray();

// Only 1 iteration over someSet, someMap & someArray
const uppercasedSet: Set<string> = new AwesomeIter(someSet)
    .pipe(
        concat(someMap.values(), someArray),
        filter(str => str !== 'foo'),
        map(str => str.toUpperCase()) // Only gets called `length - numberOfFoos` times
    )
    .collect(toSet()); // Set is populated as values get yielded

Alternatives

  • For any async data just use Rxjs - it's awesome & it has more functionality.
  • I'm unaware of similar libraries for synchronous iterables & iterators. This one is very lean & tree-shakeable!

API

AwesomeIter

constructor()

Just pass an Iterable or Iterator and AwesomeIter will be able to start managing it.

pipe()

Pipes manipulate the source Iterable or Iterator in some way - filter results, map them to different values etc. Each pipe has documentation & examples written for it in the projects/awesome-iter/pipes directory and is imported from @aloreljs/awesome-iter/pipes, e.g.

import {filter} from '@aloreljs/awesome-iter/pipes';

The current list of pipes is as follows:

  • chunk
  • concat
  • distinct
  • filter
  • map
  • sequentiallyDistinct
  • skip
  • take
  • tap

consume()

Consumers consume the source Iterable or Iterator & produce a single result - these include functions like those in Array.prototype that don't necessarily return an array & functions for collecting the source into some JS collection. Each consumer has documentation & examples written for it in the projects/awesome-iter/consumers directory and is imported from @aloreljs/awesome-iter/consumers, e.g.

import {some} from '@aloreljs/awesome-iter/consumers';

The current list of consumers is as follows:

  • count
  • find
  • first
  • includes
  • last
  • reduce
  • some
  • split
  • toArray
  • toMap
  • toObject
  • toSet