@devtools-ds/object-inspector

中文文档
1.2.1发布于 2022/12/28MITTypeScriptESM + CJS近 30 天下载 52.9万

An emulation of the Chrome and Firefox object inspector, which allows you to view JavaScript objects in the console.

原始使用文档
文档目录10 节
  1. Installation
  2. Supported Types
  3. Usage
  4. Callbacks
  5. FAQ
  6. Why is [insert type] type not supported better?
  7. Why does [insert property] property not always match my bro…
  8. Why is [insert property] color slightly different?
  9. Useful References
  10. Contributors ✨

@devtools-ds/object-inspector

An emulation of the Chrome and Firefox object inspector, which allows you to view JavaScript objects in the console.

Installation

npm i @devtools-ds/object-inspector
# or with yarn
yarn add @devtools-ds/object-inspector

Supported Types

JavaScript has a broad and sometimes complicated set of available types. This component attempts to display most types nicely, and we have styles for the following:

export type SupportedTypes =
  | boolean
  | null
  | number
  | string
  | Error
  | symbol
  | undefined
  | Date
  | RegExp
  | object
  | Map<any, any>
  | WeakMap<any, any>
  | Set<any>
  | WeakSet<any>
  | Promise<any>
  | any[]
  | Function;

For types it doesn't know about, the component should try to find a name or string to display.

Usage

Then to use the component in your code just import it!

import { ObjectInspector } from "@devtools-ds/object-inspector";

const data = {
  string: "string",
  boolean: true,
  number: 100,
};

<ObjectInspector data={data} expandLevel={1} sortKeys={true} />;

Callbacks

onSelect

This function is called with the selected AST node (after parsing the data prop with @devtools-ds/object-parser). With the selected node, you're able to traverse up/down the tree, and act on the currently selected node (like displaying additional details about that property).

FAQ

Why is [insert type] type not supported better?

Some types like WeakSet, WeakMap, etc. cannot be easily inspected using the JavaScript APIs. Promises are similar, although there is a workaround using Promise.race that forces most things in this component to be asynchronous. The reason they work nicely in the browsers is because they have access to the JavaScript engine APIs which gives them a lot more control.

If you see a type that is missing and easy to support, feel free to open an issue or PR to add it.

Why does [insert property] property not always match my browser?

I had a goal with this project to look at both the Chrome and Firefox inspectors to ideally support theming based on browser. Sometimes things couldn't be themed simply between the two and compromises were made. For example Chrome mixes a double underscore syntax like __proto__ with a double bracket syntax like [[Entries]]. Firefox is much more consistent with a <prototype> and <entries> syntax so I decided to stick with that. There were some compromises in both directions for consistency.

I'm open to suggestions on ways this can be improved.

Why is [insert property] color slightly different?

For the most part, the colors should be near identical to the browser implementations.

Sometimes there were complicated colors across browsers, where one might take three colors to do what the other does in one. These were basically evaluated case-by-case looking at the added complexity. Sometimes browsers had colors that were really light and had really bad contrast. In the interest of accessibility I sometimes left these a bolder color.

Useful References

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Tyler Krupicka

💻 📖 🎨 🚇 💡 ⚠️

Adam Dierkens

💻 📖 💡 ⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!

版本与发布记录

@devtools-ds/object-inspector 共发布 26 个版本,首次发布于 2021/01/25;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.1latest2022/12/283 年前
1.2.02022/04/234 年前
1.1.3-canary.23.465.0canary2022/04/234 年前
1.1.3-canary.23.457.02022/04/234 年前
1.1.22021/05/095 年前
1.1.12021/05/085 年前

关于 @devtools-ds/object-inspector 的常见问题

@devtools-ds/object-inspector 是什么?

An emulation of the Chrome and Firefox object inspector, which allows you to view JavaScript objects in the console.

如何安装 @devtools-ds/object-inspector?

在项目目录运行 npm install @devtools-ds/object-inspector,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>= 16.8.6)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@devtools-ds/object-inspector 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@devtools-ds/object-inspector 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@devtools-ds/object-inspector 可以商用吗?

@devtools-ds/object-inspector 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@devtools-ds/object-inspector 的下载量有多少?

根据 npm 官方下载统计,@devtools-ds/object-inspector 在 2026/10/12 – 2026/11/10 这 30 天内被下载 529,161 次,日均约 17,639 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@devtools-ds/object-inspector 还在维护吗?

最新版本 1.2.1 发布于 2022/12/28(3 年前);至今共发布 26 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/01/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。