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

debug-web

v2.4.0

Published

Browser debug utility with console styling and persistent levels (ES2018+)

Readme

Debug Web

用于浏览器调试的 NPM 包,具有可自定义的日志级别(log、warn、error、debug)。
轻量且易于使用。

特点:

  • 无依赖 — 纯 TypeScript 编写;
  • 体积 ~3.5 kB — 对打包体积影响极小;
  • SonarQube A 评级 — 最高级别的代码质量和可靠性;
  • 控制台输出样式 — 彩色格式化,便于快速识别;
  • 全局存储 — 通过 window 访问调试数据;
  • 灵活配置 — 支持日志级别、样式、别名及继承。

目录

翻译版本

English, Español, Deutsch, 中文, Русский


安装

npm install debug-web
yarn add debug-web

日志级别

优先级(从低到高):

  1. debug (0) — 调试信息 (console.debug);
  2. log (1) — 基础消息 (console.log)
  3. info (2) — 提示信息 (console.info)
  4. warn (3) — 警告 (console.warn)
  5. error (4) — 错误 (console.error)

ℹ️ 自定义级别:任何字符串值(例如 successfocus)将按特定方式处理:

  • 常规自定义级别(不带下划线前缀)使用 info 级别
  • 以下划线开头的级别(例如 _info_error)使用 debug 级别 两者都可以有自己的样式。

选项

| 参数 | 类型 | 默认值 | 描述 | |----------|---------------------------------|---------------|-------------------------------------------------| | app | string | null | 'debug' | 唯一的应用程序名称,用于分离数据 | | level | DebugLogLevel | 'log' | 最低日志级别(低于此级别的消息将不会输出) | | prop | string | null | 'debug' | 用于访问数据的全局变量名(null — 不创建) | | data | Record<string, unknown> | undefined | 初始调试数据 | | local | boolean | false | 将级别保存在 localStorage 中(否则保存在 sessionStorage) | | native | boolean | false | 使用原生控制台方法(不带样式) | | onLog | (level, attrs) => void | undefined | 每次日志记录后调用的函数 | | title | Record<string, string> | undefined | 自定义日志级别的标题 | | alias | Record<string, DebugLogLevel> | 见 下方 | createDebug 的自定义别名 | | style | Record<DebugLogLevel, string> | 见 下方 | 日志级别的 CSS 样式 |

type DebugLogLevel = 'debug' | 'log' | 'info' | 'success' | 'warn' | 'error' | string;

默认样式

| 级别 | 样式 (CSS) | |-----------|----------------------------------------------------------------------------| | info | background-color: #155adc; color: #fff; padding: 2px; border-radius: 3px | | mark | background-color: #695aff; color: #fff; padding: 2px; border-radius: 3px | | success | background-color: #13a10e; color: #fff; padding: 2px; border-radius: 3px | | focus | background-color: #881798; color: #fff; padding: 2px; border-radius: 3px | | alert | background-color: #ffa500; color: #fff; padding: 2px; border-radius: 3px | | danger | background-color: #dc143c; color: #fff; padding: 2px; border-radius: 3px |

默认别名

ddebug, llog, iinfo, wwarn, eerror

如何使用

创建实例

// debug.ts
import { DebugWeb } from 'debug-web';

export const debug = new DebugWeb({
  app: 'my-app',
  level: process.env.NODE_ENV === 'development' ? 'log' : 'error',
  data: { version: APP_VERSION },
  alias: { s: 'success', f: 'focus' },
  local: true,
});

API

createDebug 函数

创建一个支持别名和自定义级别的代理。

<T extends typeof DebugWeb>(options?: CreateDebugOptions, DebugClass?: T) => CustomLogLevels & InstanceType<T>;

日志记录方法

| 级别 | 类型 | |--------------|------------------------------------------------------------------------| | debug | (message?: unknown, ...attrs: unknown[]) => void | | log | (...attrs: unknown[]) => void | | info | (...attrs: unknown[]) => void | | warn | (...attrs: unknown[]) => void | | error | (...attrs: unknown[]) => void | | group | (open?: boolean, level?: DebugLogLevel, ...attrs: unknown[]) => void | | groupEnd | (level?: DebugLogLevel) => void | | dir | (value: unknown, options?: unknown) => void | | dirxml | (...attrs: unknown[]) => void | | trace | (...attrs: unknown[]) => void | | table | (data: unknown, properties?: string[]) => void | | count | (label?: string) => void | | countReset | (label?: string) => void | | time | (label?: string) => void | | timeLog | (label?: string, ...attrs: unknown[]) => void | | timeEnd | (label?: string) => void |

数据处理

| 方法 | 类型 | 注释 | |--------|----------------------------------------------------|---------------------------------------------------| | set | (data: DebugWebData, storage?: boolean) => void | 保存调试数据(合并)。如果 storage=true — 保存到 sessionStorage | | get | (storage?: boolean) => DebugWebData \| undefined | 返回数据的副本。如果传入 true,则从 sessionStorage 获取 | | dump | (keys: string[], options?: DumpOptions) => void | 以表格形式输出数据(忽略日志级别) |

type DebugWebData = Record<string, unknown>

type DumpOptions = {
  level?: DebugLogLevel;
  title?: string | ((data: DebugWebData) => string);
  open?: boolean;
}

级别管理

| 方法 | 类型 | 注释 | |------------------|-----------------|----------| | level (getter) | DebugLogLevel | 获取当前日志级别 | | level (setter) | DebugLogLevel | 设置当前日志级别 |

样式设置

| 方法 | 类型 | 注释 | |------------------|-----------------------------------|--------------| | style (getter) | () => DebugWebStyle | 获取当前样式映射表 | | style (setter) | (styles: DebugWebStyle) => void | 更新样式映射表(将合并) |

type DebugWebStyle = Record<DebugLogLevel, string | undefined>

调试数据

保存任意数据并在控制台中查看:

debug.set({ error: null, user: { id: 1, name: 'John' } });

可以通过 window[prop](默认是 debug)访问数据。 在浏览器控制台中输入:

debug // { error: null, user: {...}, setLevel: f }
debug.setLevel() // 修改日志级别

示例

支持

如果这个库对您有帮助,请考虑支持它的开发。

许可证

MIT © Karlen Pireverdiev

链接