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

the-wheel

v1.0.1

Published

wow I bet this is a totally unique idea

Downloads

4

Readme

the-wheel

npm (scoped) GitHub Build Status

Usage

npm install the-wheel

For

Let's say you wanted to write this for loop without iteration:

let sum = 0;
for(let i = 0; i < 10; i = i + 1) {
  sum = sum + i;
}

Now you can write this "clearer" implementation instead:

const { For } = require('the-wheel');

let sum = 0;

function condition(iterator) {
  return iterator < 10;
}

function step(iterator) {
  return iterator + 1;
}

function body(iterator) {
  sum = sum + iterator;
}

For(0, condition, step, body);

Or if you want to write it more compactly in a form similar to an actual for loop:

const { For } = require('the-wheel');

let sum = 0;
For(0, i => i < 10, i => i += 1, i => {
  sum += i;
});

What if you want to reflect the break and continue implemented in native loops? Given that the body functions don't need return anything, you take advantage of this by return-ing special cases.

A simple return is the same as a native continue:

// only log even numbers

for(let i = 0; i < 10; i ++) {
  if(i % 2 != 0) {
    continue;
  }

  console.log(i);
}

For(0, i => i < 10, i => i + 1, i => {
  if(i % 2 != 0) {
    return;
  }

  console.log(i);
});

You can also implement a break in this way by returning something from your body function.

// linear search
const target = 'Carmen Sandiego';
let where;

for(let i = 0; i < world.length; i ++) {
  if(world[i] === target) {
    where = i;
    break;
  }
}

For(0, i => i < world.length; i => i + 1, i => {
  if(world[i] === target) {
    where = i;
    return 1;
  }
});

While

While has a very similar usage to For

let sum = 0;
let i = 0;

while(i < 10) {
  sum += i;
}

Can in turn be written as follows

const { While } = require('the-wheel');

let sum = 0;
let i = 0;

function condition() {
  return i < 10;
}

function body() {
  sum += i;
  i += 1;
}

While(condition, body);

Or more succinctly as

While(() => i < 10, () => {
  sum += i;
  i += 1;
});

You can implement break and continue in the same manner as a For loop by performing return in your body function.

Tests

npm test