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

powerglove

v0.7.4

Published

Async generator-based control flow

Downloads

58

Readme

Powerglove

npm install powerglove

API

pipe

[(a -> *)] -> a -> Promise -> *

Passes a value through an array of functions sequentially; Returns value fulfilled from final function in the array.

Example:

import { pipe } from 'powerglove'

void async () => {

  const weirdMath = pipe([
    n => n / 1,
    n => n + 4,
    n => n * 7
  ])

  await weirdMath(2)
  // -> 42

}()

Params:

| Type | Name | Description | |--------------|-------|-------------| | Function[] | funcs | Array of functions | * | x | Any value

Return:

| Type | Description | |-----------|-------------| | Promise | Fulfills with value returned by last index of func

all

[(a -> *)] -> a -> Promise -> [*]

Executes an array of functions concurrently; returns an array of fulfilled values.

Example:

import { all } from 'powerglove'

void async () => {

  const sayHi = all([
    x => `Hello, ${x}!`,
    x => `¡Hola, ${x}!`,
    x => `Bonjour, ${x}!`
  ])

  await sayHi('world')
  // -> [ 'Hello, world!', '¡Hola, world!', 'Bonjour, world!' ]

}()

Params:

| Type | Name | Description | |--------------|-------|-------------| | Function[] | funcs | Array of functions | * | x | Any value

Return:

| Type | Description | |-----------|-------------| | Promise | Fulfills with an array of values returned from each function in funcs

race

[(a -> *)] -> a -> Promise -> *

Executes an array of functions concurrently; Returns value of first function to resolve.

Example:

import { race, delay } from 'powerglove'

void async () => {

  const fast = delay(200)(x => `${x} Speed Racer`)

  const faster = delay(100)(x => `${x} Racer X`)

  const fastest = delay(0)(x => `${x} Chim Chim`)

  const announceWinner = race([
    fast,
    faster,
    fastest
  ])

  await announceWinner('And the winner is...')
  // -> `And the winner is... Chim Chim!`

}()

Params:

| Type | Name | Description | |--------------|-------|-------------| | Function[] | funcs | Array of functions | * | x | Any value

Return:

| Type | Description | |-----------|-------------| | Promise | Fulfills with value of first function in funcs to resolve

until

(a -> Bool) -> (a -> *) -> a -> Promise -> *

Executes function until done returns true. The return value of the repeating function is passed into itself on each successive iteration.

Example:

import { until } from 'powerglove'

void async () => {

  const minusminus = x => x - 1

  const smallEnough = x => x <= 0

  const subtractAll = until(smallEnough)(minusminus)

  await subtractAll(100000)
  // -> 0

  const plusplus = x => x + 1

  const largeEnough = x => x >= 100000

  const addALot = until(largeEnough)(plusplus)

  await addALot(0)
  // -> 100000

}()

Params:

| Type | Name | Description | |------------|-------|-------------| | Function | done | Accepts value returned by f. f is called repeatedly until this function returns true | Function | f | Function to be called repeatedly. Passes its own return value into itself on each iteration | * | x | Any value

Return:

| Type | Description | |-----------|-------------| | Promise | Fulfills result of f after n recursive calls

when

(a -> Bool) -> (a -> *) -> (a -> *) -> a -> Promise -> *

Tests a value and passes value to either the pass function or the fail function

Example:

import { when } from 'powerglove'

void async () => {

  const over9000 = lvl => lvl > 9000

  const praise = lvl => `Holy crap! ${lvl}?! THAT'S OVER 9000!`

  const insult = lvl => `Pffft. ${lvl}? Is that all you got???`

  const analyzePowerLevel = when(over9000)(praise)(insult)

  await analyzePowerLevel(9001)
  // -> `Holy crap! 9001?! THAT'S OVER 9000!`

  await analyzePowerLevel(1)
  // -> `Pffft. 1? Is that all you got???`

}()

Params:

| Type | Name | Default | Description | |------------|-------|----------|-------------| | Function | test | | Accepts x; returns true or false | Function | pass | | Called with x if test returns true | Function | fail | a => a | Called with x if test returns false | * | x | | Any value

Return:

| Type | Description | |-----------|-------------| | Promise | Fulfills with value returned by pass or fail

delay

Number -> (a -> *) -> a -> Promise -> *

Accepts ms, number of milliseconds to wait, before executing function f.

Example:

import { delay } from 'powerglove'

void async () => {

  const timeSince = delay(300)(ms => Date.now() - ms)

  await timeSince(Date.now())
  // -> ~300ms

}()

Params:

| Type | Name | Description | |------------|-------|-------------| | Number | funcs | Array of functions | Function | f | Function to be called after timeout | * | x | Any value

Return:

| Type | Description | |-----------|-------------| | Promise | Fulfills with value returned by f(x)