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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mlfetch

v0.2.1

Published

A request manager using fetch for scenarios that require lots of requests to be sent

Readme

安装

pnpm install mlfetch 或者

yarn add mlfetch 或者

npm install mlfetch

使用

import Mlfetch from 'mlfetch'

const mlfetch = new Mlfetch()

for (let i = 0; i < 80; i++) {
  ml.enqueueWithInterval({
    url: `https://jsonplaceholder.typicode.com/photos/i`,
    type: 'json',
    setCallback: (json: Photo) => {
      console.log(json)
      info.value = json
    }
  }, 1000)
}

setTimeout(() => {
  ml.destroy()
}, 20000)

mlfetch.run()

interface

MlOptions

属性:

  • poolingTime (number, optional, default: 500): 轮询请求流程的时间间隔,单位为 ms(毫秒)
  • concurrency (number, optional, default: 6): 初始的最大并发数,
  • adjustInterval (number, optional, default: 5000): 调整并发数的时间间隔,单位为 ms(毫秒)
  • requestTimeWindowLength (number, optional, default: 30): 平均请求时间的统计窗口大小,计算近 requestTimeWindowLength 次的平均请求时间

typescript 定义:

interface MlOptions {
  poolingTime?: number
  concurrency?: number
  adjustInterval?: number
  requestTimeWindowLength?: number
}

QueueItem

属性:

  • url (string|URL|Request): 请求的 url,与 fetch 的第一个参数相同

  • type (BodyMethodNames): 请求资源的类型,为 "arrayBuffer" | "blob" | "formData" | "json" | "text"

  • timeout (number, optional, default: 5000): 超时时间,请求超过多少秒算超时

  • setCallback ((res: any) => unknown): 成功请求的回调函数。传入的值是经过 response[type]() 处理后的结果

  • errorCallback ((err: Error) => unknown, optional): 请求失败的回调函数

  • fetchOptions (RequestInit, optional): fetch 的第二个参数

typescript 定义:

interface QueueItem {
  url: string | URL | Request
  type: BodyMethodNames
  timeout?: number
  setCallback: (res: any) => unknown
  errorCallback?: (err: Error) => unknown
  fetchOptions?: RequestInit
}

BodyMethodNames

typescript 定义:

type BodyMethodNames = {
  [K in keyof Body]: Body[K] extends (...args: any[]) => any ? K : never
}[keyof Body]
// "arrayBuffer" | "blob" | "formData" | "json" | "text"

API

new Mlfetch(options?: MlOptions)

描述:

初始化请求管理队列

参数:

  • options: (MlOptions, optional) 见 interface

Mlfetch.enqueue(item: QueueItem): void

描述:

将请求的描述对象放到请求队列中

参数:

  • item: (QueueItem): 见 interface

Mlfetch.enqueueWithInterval(item: QueueItem, interval: number): void

描述:

内部通过开启定时器轮询将请求对象放到队列中,开启定时器之前会先将请求放入到队列中一次

参数:

  • item: (QueueItem): QueueItem 的定义见 interface
  • interval: (number): 定时器的间隔

Mlfetch.deleteUrlTimer(url: string | URL | Request): true | undefined

描述:

删除通过 enqueueWithInterval 添加的 url 请求的定时器。返回 true 表示删除成功,返回 undefined 表示队列中没有该 url,删除失败。

参数:

  • url (string | URL | Request): 请求的 url

返回值:

  • true | undefined: 返回 true 表示删除成功,返回 undefined 表示队列中没有该 url,删除失败。

Mlfetch.run(): void

描述:

开启请求的定时器,和自动调整并发数的定时器

Mlfetch.destroy(): void

描述:

删除所有的定时器,并将队列的长度清零,可以调用 run() 来重启过程