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

@minto-ai/version-polling

v1.0.31

Published

实时检测是否发布新版本

Readme

@minto-ai/version-polling

@minto-ai/version-polling 是一个用于实时检测线上环境版本更新的轻量级工具。它支持通过 HTML 文件的 ETag/Last-Modified 或 JSON 文件的版本号字段来检测更新。

特性

  • 🚀 零依赖:轻量级设计,不依赖任何第三方库(Worker 内部实现)。
  • 🔄 自动轮询:基于 Web Worker 的定时轮询,不阻塞主线程。
  • 👁️ 智能暂停:当页面不可见时自动暂停轮询,节省资源;页面可见时自动恢复。
  • 📦 双模式支持
    • HTML 模式:检测 HTML 文件的 ETagLast-Modified 响应头变化。
    • JSON 模式:检测 manifest.json 或其他 JSON 文件中的 version 字段变化(需符合 SemVer 规范)。

安装

pnpm install @minto-ai/version-polling

使用示例

基础用法(检测 HTML)

默认情况下,工具会检测当前页面的 HTML 文件。

import { createVersionPolling } from '@minto-ai/version-polling'

const versionPolling = createVersionPolling({
  pollingInterval: 60, // 轮询间隔,单位秒
})

versionPolling.on('update', () => {
  // 发现新版本,可以提示用户刷新页面
  if (confirm('发现新版本,是否刷新?')) {
    window.location.reload()
  }
})

进阶用法(检测 JSON)

如果你使用 manifest.json 或专门的版本文件来管理版本号。

import { createVersionPolling } from '@minto-ai/version-polling'

const versionPolling = createVersionPolling({
  // 指定检测的 JSON 文件路径
  fileUrl: 'manifest.json',
  pollingInterval: 30,
})

versionPolling.on('update', () => {
  console.log('检测到新版本发布!')
})

API

createVersionPolling(options)

创建并返回一个版本轮询实例。

参数 options

| 属性 | 类型 | 默认值 | 说明 | | ----------------- | -------- | -------------------------- | ------------------------------------------------------------------------------------------- | | pollingInterval | number | 60 | 轮询间隔时间,单位为秒。 | | fileUrl | string | window.location.pathname | 目标文件地址。可以是 HTML 路径或 JSON 文件路径。工具会自动根据后缀(.json)判断检测模式。 |

实例方法

on(eventName, callback)

监听事件。

  • 事件名: 'update'
  • 回调参数: 无

emit(eventName, data?)

手动触发事件(通常不需要手动调用)。