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

flowp

v0.4.4

Published

Promise based utilities

Downloads

26

Readme

CI Maintainability Coverage Test Cases ES2020 Downloads

flowp aims to provide promise based utilities with modern and simple interface.

  • 📦 Pure TypeScript and ready to run in Node.js, browsers and web workers

  • 🏙 Embrace promises and async/await syntax, no more callback hells

  • 🧱 Robust quality with tests focusing on coverage as well as race conditions

  • 🔰 Friendly documentation and examples

Documentation

Checkout the official documentation, API references and tutorials at https://flowp.pages.dev, everything is there!

  • Future: a resolve-later promise
class MyServer {
  public ready = new Future<void>()
  private server!: HttpServer
  constructor() {
    this.ready = this.initServer()
  }
  initServer() {
    this.server = http.listen(8080, this.ready.resolve)
  }
  foo() {
    await this.ready
    this.server // safely access server
  }
}

const server = new MyServer()
await server.ready
  • Progress: promise with progress reporting
const progress = new Progress<string, { current: number; total: number }>({ current: 0, total: 100 })

// automatically resolve when all tasks are finished
progress.onProgress((p) => p.current >= p.total && progress.resolve('banana!'))

progress.report({ current: 15, total: 100 })
progress.report({ current: 100, total: 100 })

expect(await progress).toBe('banana!')
  • Channel: send and receive messages with a buffered channel
class EventChannel<T> {
  private hub: ChannelHub<T>
  constructor(){ this.hub = new ChannelHub<T>() }
  event(handler: (v: T) => any) {
    const reader = this.hub.reader()
    reader.pipe(pipe.to(handler))
    return () => reader.unpipe()
  }
  fire(v: T) { this.hub.broadcast(v) }
}
  • Semaphore: restrict concurrent access to resource
// maximum of 16 concurrent requests
const sem = new Semaphore(16)

const download = async (url: string) => {
  // some download logic
  console.log(url)
  return timers.sleep(1000)
}
const urls: string[] = Array.from({ length: 100 }, (_, i) => (i + 1).toString())

// automatically schedule download
await Promise.all(urls.map((url) => sem.schedule(() => download(url))))



const mutex = new Mutex({ a: 1 })
const { release, value } = await mutex.lock()
const ref = value // value is a temporary reference which does not equal the value stores in mutex
ref.a // => 1
release()
ref.a // => TypeError, temporary reference destroyed
  • delegate: delegate property access and method calls to promise resolved value
const fs = import('fs')

await fs.$promises.$writeFile('hello.ts', `export default () => 'hello world!'`)

CJS & ESM support

CJS is supported with conditional exports and by default, the main entry points to cjs.

If your environment supports ESM, which is preferred, you can use `import { Future } from 'flowp/future' to import on demand without a tree shaker (like webpack).

Contribute

Feature requests, issues & PRs are welcomed 🥰

License

MIT © @Semesse