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

@h-lumos/memory-monitor

v0.0.1

Published

一个 JavaScript 内存监控工具,使用 Vite 构建,支持多种环境

Readme

memory-monitor-js

一个用于监控前端项目在浏览器内存使用情况的 JavaScript 插件,基于 TypeScript 开发,支持多种环境,适合现代前端项目集成。

特性

  • 定时检测浏览器 JS 堆内存占用
  • 支持自定义告警/临界阈值
  • 支持自定义上报/处理函数
  • 支持自动或手动启动
  • 提供停止监控和获取当前内存占用方法
  • TypeScript 类型支持

安装

npm install memory-monitor-js
# 或
pnpm add memory-monitor-js

快速开始

1. 自动启动监控

import { initMemoryMonitor } from 'memory-monitor-js';

initMemoryMonitor(); // 默认自动启动

2. 手动启动/停止

import { initMemoryMonitor } from 'memory-monitor-js';

const monitor = initMemoryMonitor(false); // 不自动启动
monitor.start(); // 手动启动
monitor.stop();  // 停止监控

3. 自定义配置

import { MemoryMonitor, MemoryMonitorConfig } from 'memory-monitor-js';

const config: MemoryMonitorConfig = {
  intervalMs: 60_000, // 检测间隔 1 分钟
  warnLevel: 0.7,     // 70% 告警
  criticalLevel: 0.9, // 90% 临界
  reportFn: (ratio, level) => {
    if (level === 'warn') {
      alert(`内存占用告警: ${(ratio * 100).toFixed(1)}%`);
    } else {
      alert(`内存占用临界: ${(ratio * 100).toFixed(1)}%,即将刷新页面`);
    }
  }
};

const monitor = new MemoryMonitor(config);
monitor.start();

API

MemoryMonitorConfig

| 属性 | 类型 | 说明 | | -------------- | ------------------------------------------------- | -------------------------- | | intervalMs | number | 检测间隔(毫秒),默认 300000 | | warnLevel | number (0~1) | 告警阈值,默认 0.75 | | criticalLevel | number (0~1) | 临界阈值,默认 0.9 | | reportFn | (ratio: number, level: 'warn' \| 'critical') => void | 内存超阈值回调 |

MemoryMonitor

  • start(): void 启动监控
  • stop(): void 停止监控
  • getRatio(): number | undefined 获取当前内存占用比例

initMemoryMonitor(autoStart = true): MemoryMonitor

初始化并返回默认监控实例。

注意事项

  • 仅支持支持 performance.memory 的浏览器(如 Chrome)。
  • 低版本浏览器或部分移动端浏览器不支持该特性。

贡献

欢迎提 issue 或 PR!

License

MIT