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 🙏

© 2025 – Pkg Stats / Ryan Hefner

whenmap

v0.2.0

Published

`WhenMap` is an extension of `Map` that contains only promise instances, inspired by [`customElements.whenDefined()`][CER]. WhenMap is particularly useful for decoupling uses of a value from code that initalizes the value.

Downloads

11

Readme

WhenMap

WhenMap is an extension of Map that contains only promise instances, inspired by customElements.whenDefined(). WhenMap is particularly useful for decoupling uses of a value from code that initalizes the value.

WhenMap API

import { WhenMap } from 'whenmap'

let when_db = new WhenMap()

let p_ready = when_db.when('example_key')
p_ready.then(v => console.log('Ready!', {v}))

when_db.set('example_key', example_init())

async function example_init() {
  // async initialize process
  return {example: 42}
}
  • when_db.when(key) returns a promise for the key. The promise may or may not be resolved.

  • when_db.get(key) is an alias for when_db.when(key)

  • when_db.set(key, value) resolves the promise for the specified key, returning this.

  • when_db.has(key) returns false for untracked keys, true for resolved tracked keys, and 1 for unresolved tracked keys.

  • when_db.delete(key) resolves a tracked key as undefined before removing it.

  • when_db.clear() resolves any outstanding tracked keys as undefined before clearing all tracked keys.

WhenAiter API

import { WhenAiter } from 'whenmap'


// For streaming promises as they are settled
let misc_promises = [ 100, 20, 50 ].map(ms =>
  new Promise(done =>
    setTimeout(done, ms, `delay: ${ms}`) ))

for await (let each of WhenAiter.from(misc_promises)) {
  console.log('stream resolved:', detail)
}


// For streaming events
let when_stream = new WhenAiter(send => {
  document.body.addEventListener(
    'some_custom_event',
    evt => send(evt.detail),
    {signal: send.signal})
})

for await (let detail of when_stream) {
  console.log('use aiter event stream:', detail)
}
  • new WhenMap(init_arg, opt) returns an async iterable.

    • If init_arg is iterable, send() is called on each item.
    • other init_arg(send) is invoked.
  • WhenMap.from(init_arg, opt) is an alias for new WhenMap

  • aiter_pipe(opt, recv_self) returns a connected [send, recv] pair

    • send(value) adds value to the internal queue, after awaiting it if a promisable.

      • opt.on_error(err) is an optional promise .catch() handler.
    • send.stop() terminates the async iterable stream from within the init_arg closure.

    • send.ready is a promise to provide overflow backpressure.

      • opt.max_size manages the send.ready promise
    • recv extends the recv_self prototype

    • recv.size returns the interal queue size

    • recv supports async iterable protocol: for await (let each of when_stream) {}

      • recv.next()
      • recv.return()
      • recv.throw()
      • recv[Symbol.asyncIterator]()
    • an AbortSignal instance is aborted when the stream is stopped.

      • assigned into recv.signal and send.signal

Install

$ npm install whenmap

License

BSD 2-clause