# which-boxed-primitive 中文文档

规范地址：https://npmcn.com/package/which-boxed-primitive/

版本：1\.1\.1
npm 元数据更新时间：2024-12-16T05:48:44.232Z
中文译文更新时间：2026-11-05T15:13:37.354Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/which-boxed-primitive
原文对照：https://npmcn.com/package/which-boxed-primitive/?lang=original
项目主页：https://github.com/inspect-js/which-boxed-primitive#readme
源码仓库：https://github.com/inspect-js/which-boxed-primitive

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：19.3 kB，12 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>= 0\.4
- 运行依赖：5 个
- 首次发布：2019-08-10T22:28:54.905Z
- 最新版本发布：2024-12-16T05:48:44.026Z
- 近 30 天下载量：379264076（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：5（近 12 个月 0 个）

## 中文简介

这是哪一种原始的JS?

## 安装

```sh
npm install which-boxed-primitive
```

也可以使用：`pnpm add which-boxed-primitive`、`yarn add which-boxed-primitive`、`bun add which-boxed-primitive`

## README

# 哪个框原生 [![Version Badge](https://versionbadg.es/inspect-js/which-boxed-primitive.svg)](https://npmjs.org/package/which-boxed-primitive)

[![dependency status](https://david-dm.org/inspect-js/which-boxed-primitive.svg)](https://david-dm.org/inspect-js/which-boxed-primitive) [![dev dependency status](https://david-dm.org/inspect-js/which-boxed-primitive/dev-status.svg)](https://david-dm.org/inspect-js/which-boxed-primitive#info=devDependencies) [![License](https://img.shields.io/npm/l/which-boxed-primitive.svg)](https://npmcn.com/package/which-boxed-primitive/LICENSE) [![Downloads](https://img.shields.io/npm/dm/which-boxed-primitive.svg)](https://npm-stat.com/charts.html?package=which-boxed-primitive)

[![npm badge](https://nodei.co/npm/which-boxed-primitive.png?downloads=true&stars=true)](https://npmjs.org/package/which-boxed-primitive)

这是哪一种原始的JS? 这个模块工作跨实体/框架,不依赖于 `instanceof` 或可变特性,而且尽管ES6 Symblood.toStringTag 仍然有效.

## 示例

```js
var whichBoxedPrimitive = require('which-boxed-primitive');
var assert = require('assert');

// unboxed primitives return `null`
// boxed primitives return the builtin constructor name

assert.equal(whichBoxedPrimitive(undefined), null);
assert.equal(whichBoxedPrimitive(null), null);

assert.equal(whichBoxedPrimitive(false), null);
assert.equal(whichBoxedPrimitive(true), null);
assert.equal(whichBoxedPrimitive(new Boolean(false)), 'Boolean');
assert.equal(whichBoxedPrimitive(new Boolean(true)), 'Boolean');

assert.equal(whichBoxedPrimitive(42), null);
assert.equal(whichBoxedPrimitive(NaN), null);
assert.equal(whichBoxedPrimitive(Infinity), null);
assert.equal(whichBoxedPrimitive(new Number(42)), 'Number');
assert.equal(whichBoxedPrimitive(new Number(NaN)), 'Number');
assert.equal(whichBoxedPrimitive(new Number(Infinity)), 'Number');

assert.equal(whichBoxedPrimitive(''), null);
assert.equal(whichBoxedPrimitive('foo'), null);
assert.equal(whichBoxedPrimitive(new String('')), 'String');
assert.equal(whichBoxedPrimitive(new String('foo')), 'String');

assert.equal(whichBoxedPrimitive(Symbol()), null);
assert.equal(whichBoxedPrimitive(Object(Symbol()), 'Symbol');

assert.equal(whichBoxedPrimitive(42n), null);
assert.equal(whichBoxedPrimitive(Object(42n), 'BigInt');

// non-boxed-primitive objects return `undefined`
assert.equal(whichBoxedPrimitive([]), undefined);
assert.equal(whichBoxedPrimitive({}), undefined);
assert.equal(whichBoxedPrimitive(/a/g), undefined);
assert.equal(whichBoxedPrimitive(new RegExp('a', 'g')), undefined);
assert.equal(whichBoxedPrimitive(new Date()), undefined);
assert.equal(whichBoxedPrimitive(function () {}), undefined);
assert.equal(whichBoxedPrimitive(function* () {}), undefined);
assert.equal(whichBoxedPrimitive(x => x * x), undefined);
assert.equal(whichBoxedPrimitive([]), undefined);

```

## 测试

仅仅复制回转, `npm install`运行 `npm test`

## 常见问题

### which-boxed-primitive 是什么？

这是哪一种原始的JS?

### 如何安装 which-boxed-primitive？

在项目目录运行 npm install which-boxed-primitive，或使用 pnpm add / yarn add / bun add。

### which-boxed-primitive 支持 TypeScript 吗？

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

### which-boxed-primitive 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### which-boxed-primitive 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>= 0\.4。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### which-boxed-primitive 可以商用吗？

which-boxed-primitive 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### which-boxed-primitive 的下载量有多少？

根据 npm 官方下载统计，which-boxed-primitive 在 2026/10/05 – 2026/11/03 这 30 天内被下载 379,264,076 次，日均约 12,642,136 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### which-boxed-primitive 还在维护吗？

最新版本 1\.1\.1 发布于 2024/12/16（1\.9 年前）；至今共发布 5 个版本，其中过去 12 个月发布了 0 个；首次发布于 2019/08/11。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

