@exodus/proxy-freeze

中文文档
3.0.2发布于 2026/10/14MITCommonJS零依赖近 30 天下载 5.7万

Simple way to freeze JavaScript objects and know of attempted modifications

原始使用文档
文档目录5 节
  1. Why?
  2. Install
  3. Usage
  4. proxyFreeze(target, options)
  5. License

proxy-freeze

npm travis standard

A simple way to freeze JavaScript objects and know of attempted modifications.

Why?

Why not just use Object.freeze and Object.isFrozen?

If you use Object.freeze and later set a property on that object, it silently fails unless in strict mode. Also, using this technique gives you the ability to listen for warnings on the warning event.

Install

npm install --save proxy-freeze

Usage

proxyFreeze(target, options)

  • target: can be either an object or constructor function
  • options
    • addProxyIdentifier: boolean, adds a symbol getter that detects Proxies created via this method. Defaults to false.
    • preventRefreeze: boolean, uses symbol added via addProxyIdentifier to identify frozen Proxies and doesn't re-freeze them. Defaults to false.
const obj = {
  name: 'jp',
}

const obj2 = proxyFreeze(obj)
obj2.name = 'bob'

process.once('warning', (warning) => {
  console.warn(warning.name) // => ProxyFreezeWarning
  console.warn(warning.message) // => Trying to set value of property (name) of frozen object.
  console.warn(warning.stack)
})

License

MIT

版本与发布记录

@exodus/proxy-freeze 共发布 4 个版本,首次发布于 2023/02/02;过去 12 个月发布了 3 个版本。

版本发布日期距今
3.0.2latest2026/10/141 个月前
3.0.12026/06/135 个月前
3.0.02026/04/137 个月前
2.0.02023/02/023 年前

关于 @exodus/proxy-freeze 的常见问题

@exodus/proxy-freeze 是什么?

Simple way to freeze JavaScript objects and know of attempted modifications

如何安装 @exodus/proxy-freeze?

在项目目录运行 npm install @exodus/proxy-freeze,或使用 pnpm add / yarn add / bun add。

@exodus/proxy-freeze 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/exodus__proxy-freeze 是否存在。

@exodus/proxy-freeze 支持 ESM 还是 CommonJS?

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

@exodus/proxy-freeze 可以商用吗?

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

@exodus/proxy-freeze 的下载量有多少?

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

@exodus/proxy-freeze 还在维护吗?

最新版本 3.0.2 发布于 2026/10/14(1 个月前);至今共发布 4 个版本,其中过去 12 个月发布了 3 个;首次发布于 2023/02/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。