dequal

中文文档
2.0.3发布于 2022/07/12MITTypeScriptESM + CJS零依赖近 30 天下载 4.6亿

A tiny (304B to 489B) utility for check for deep equality

原始使用文档
文档目录7 节
  1. Install
  2. Modes
  3. Usage
  4. API
  5. dequal(foo, bar)
  6. Benchmarks
  7. License

dequal CI

A tiny (304B to 489B) utility to check for deep equality

This module supports comparison of all types, including Function, RegExp, Date, Set, Map, TypedArrays, DataView, null, undefined, and NaN values. Complex values (eg, Objects, Arrays, Sets, Maps, etc) are traversed recursively.

Important:

  • key order within Objects does not matter
  • value order within Arrays does matter
  • values within Sets and Maps use value equality
  • keys within Maps use value equality

Install

$ npm install --save dequal

Modes

There are two "versions" of dequal available:

dequal

Size (gzip): 489 bytes
Availability: CommonJS, ES Module, UMD

dequal/lite

Size (gzip): 304 bytes
Availability: CommonJS, ES Module

IE9+NumberStringDateRegExpObjectArrayClassSetMapArrayBufferTypedArrayDataView
dequal:x::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark:
dequal/lite:+1::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::white_check_mark::x::x::x::x::x:

Note: Table scrolls horizontally!

Usage

import { dequal } from 'dequal';

dequal(1, 1); //=> true
dequal({}, {}); //=> true
dequal('foo', 'foo'); //=> true
dequal([1, 2, 3], [1, 2, 3]); //=> true
dequal(dequal, dequal); //=> true
dequal(/foo/, /foo/); //=> true
dequal(null, null); //=> true
dequal(NaN, NaN); //=> true
dequal([], []); //=> true
dequal(
  [{ a:1 }, [{ b:{ c:[1] } }]],
  [{ a:1 }, [{ b:{ c:[1] } }]]
); //=> true

dequal(1, '1'); //=> false
dequal(null, undefined); //=> false
dequal({ a:1, b:[2,3] }, { a:1, b:[2,5] }); //=> false
dequal(/foo/i, /bar/g); //=> false

API

dequal(foo, bar)

Returns: Boolean

Both foo and bar can be of any type.
A Boolean is returned indicating if the two were deeply equal.

Benchmarks

Running Node v10.13.0

The benchmarks can be found in the /bench directory. They are separated into two categories:

  • basic – compares an object comprised of String, Number, Date, Array, and Object values.
  • complex – like basic, but adds RegExp, Map, Set, and Uint8Array values.

Note: Only candidates that pass validation step(s) are listed.
For example, fast-deep-equal/es6 handles Set and Map values, but uses referential equality while those listed use value equality.

Load times:
  assert             0.109ms
  util               0.006ms
  fast-deep-equal    0.479ms
  lodash/isequal    22.826ms
  nano-equal         0.417ms
  dequal             0.396ms
  dequal/lite        0.264ms

Benchmark :: basic
  assert.deepStrictEqual  x    325,262 ops/sec ±0.57% (94 runs sampled)
  util.isDeepStrictEqual  x    318,812 ops/sec ±0.87% (94 runs sampled)
  fast-deep-equal         x  1,332,393 ops/sec ±0.36% (93 runs sampled)
  lodash.isEqual          x    269,129 ops/sec ±0.59% (95 runs sampled)
  nano-equal              x  1,122,053 ops/sec ±0.36% (96 runs sampled)
  dequal/lite             x  1,700,972 ops/sec ±0.31% (94 runs sampled)
  dequal                  x  1,698,972 ops/sec ±0.63% (97 runs sampled)

Benchmark :: complex
  assert.deepStrictEqual  x    124,518 ops/sec ±0.64% (96 runs sampled)
  util.isDeepStrictEqual  x    125,113 ops/sec ±0.24% (96 runs sampled)
  lodash.isEqual          x     58,677 ops/sec ±0.49% (96 runs sampled)
  dequal                  x    345,386 ops/sec ±0.27% (96 runs sampled)

License

MIT © Luke Edwards

版本与发布记录

dequal 共发布 7 个版本,首次发布于 2019/03/07;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.3latest2022/07/124 年前
2.0.22020/08/196 年前
2.0.12020/08/186 年前
2.0.02020/08/136 年前
1.0.12020/07/166 年前
1.0.02019/03/087 年前

关于 dequal 的常见问题

dequal 是什么?

A tiny (304B to 489B) utility for check for deep equality

如何安装 dequal?

在项目目录运行 npm install dequal,或使用 pnpm add / yarn add / bun add。

dequal 支持 TypeScript 吗?

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

dequal 支持 ESM 还是 CommonJS?

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

dequal 需要什么版本的 Node.js?

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

dequal 可以商用吗?

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

dequal 的下载量有多少?

根据 npm 官方下载统计,dequal 在 2026/10/05 – 2026/11/03 这 30 天内被下载 458,285,453 次,日均约 15,276,182 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

dequal 还在维护吗?

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