@2utils/is-equal 中文文档教程

发布于 4年前 浏览 31 更新于 3年前

@2utils/is-equal

一个普通的 isEqual 函数。

npm i @2utils/is-equal

Tests

测试是从 lodash

Passed

  • [x] should compare primitives
  • [x] should compare arrays
  • [x] should treat arrays with identical values but different non-index properties as equal
  • [x] should compare sparse arrays
  • [x] should compare plain objects
  • [x] should compare objects regardless of key order
  • [x] should compare nested objects
  • [x] should compare object instances
  • [x] should compare functions
  • [x] should compare objects with constructor properties
  • [x] should compare objects with shared property values
  • [x] should avoid common type coercions
  • [x] should compare arguments objects
  • [x] should compare date objects
  • [x] should compare functions
  • [x] should return an unwrapped value when implicitly chaining
  • [x] should compare maps
  • [x] should compare regexes
  • [x] should compare sets
  • [x] should compare buffers
  • [x] should compare array buffers
  • [x] should treat objects created by Object.create(null) like plain objects

Not passed

Circular

  • [ ] should compare arrays with circular references
  • [ ] should have transitive equivalence for circular references of arrays
  • [ ] should compare objects with circular references
  • [ ] should have transitive equivalence for circular references of objects
  • [ ] should compare objects with multiple circular references
  • [ ] should compare objects with complex circular references
  • [ ] should compare maps with circular references
  • [ ] should compare sets with circular references

  • [ ] should compare array views
  • [ ] should compare error objects
  • [ ] should compare promises by reference
  • [ ] should compare symbol properties
  • [ ] should compare wrapped values
  • [ ] should compare wrapped and non-wrapped values
  • [ ] should work as an iteratee for _.every
  • [ ] should not error on DOM elements
  • [ ] should return true for like-objects from different documents
  • [ ] should return false for objects with custom toString methods
  • [ ] should return a wrapped value when explicitly chaining

Benchmark

中无耻地窃取的测试是从 fast-deep-equal 包中运行的。 它们没有显示真实情况,因为我没有涵盖所有测试用例。 只是为了好玩。

pos.packageresults
1.fast-deep-equal218,604 ops/sec ±2.32% (80 runs sampled)
2.@2utils/is-equal201,469 ops/sec ±2.59% (83 runs sampled)
3.fast-equals195,025 ops/sec ±3.06% (79 runs sampled)
4.fast-deep-equal/es6192,544 ops/sec ±2.60% (82 runs sampled)
5.nano-equal126,143 ops/sec ±2.68% (79 runs sampled)
6.shallow-equal-fuzzy112,192 ops/sec ±1.96% (83 runs sampled)
7.underscore.isEqual62,441 ops/sec ±1.78% (86 runs sampled)
8.util.isDeepStrictEqual45,652 ops/sec ±1.69% (85 runs sampled)
9.lodash.isEqual34,102 ops/sec ±1.55% (87 runs sampled)
10.deep-eql28,662 ops/sec ±5.36% (78 runs sampled)
11.ramda.equals10,623 ops/sec ±1.84% (86 runs sampled)
12.assert.deepStrictEqual271 ops/sec ±1.22% (82 runs sampled)
13.deep-equal61.11 ops/sec ±4.58% (40 runs sampled)

@2utils/is-equal

An ordinary isEqual function.

npm i @2utils/is-equal

Tests

Tests were brazenly stolen from lodash

Passed

  • [x] should compare primitives
  • [x] should compare arrays
  • [x] should treat arrays with identical values but different non-index properties as equal
  • [x] should compare sparse arrays
  • [x] should compare plain objects
  • [x] should compare objects regardless of key order
  • [x] should compare nested objects
  • [x] should compare object instances
  • [x] should compare functions
  • [x] should compare objects with constructor properties
  • [x] should compare objects with shared property values
  • [x] should avoid common type coercions
  • [x] should compare arguments objects
  • [x] should compare date objects
  • [x] should compare functions
  • [x] should return an unwrapped value when implicitly chaining
  • [x] should compare maps
  • [x] should compare regexes
  • [x] should compare sets
  • [x] should compare buffers
  • [x] should compare array buffers
  • [x] should treat objects created by Object.create(null) like plain objects

Not passed

Circular

  • [ ] should compare arrays with circular references
  • [ ] should have transitive equivalence for circular references of arrays
  • [ ] should compare objects with circular references
  • [ ] should have transitive equivalence for circular references of objects
  • [ ] should compare objects with multiple circular references
  • [ ] should compare objects with complex circular references
  • [ ] should compare maps with circular references
  • [ ] should compare sets with circular references

  • [ ] should compare array views
  • [ ] should compare error objects
  • [ ] should compare promises by reference
  • [ ] should compare symbol properties
  • [ ] should compare wrapped values
  • [ ] should compare wrapped and non-wrapped values
  • [ ] should work as an iteratee for _.every
  • [ ] should not error on DOM elements
  • [ ] should return true for like-objects from different documents
  • [ ] should return false for objects with custom toString methods
  • [ ] should return a wrapped value when explicitly chaining

Benchmark

Tests were run from the fast-deep-equal package. They don 't show the real picture because I don 't cover all test cases. Just for fun.

pos.packageresults
1.fast-deep-equal218,604 ops/sec ±2.32% (80 runs sampled)
2.???? @2utils/is-equal201,469 ops/sec ±2.59% (83 runs sampled)
3.fast-equals195,025 ops/sec ±3.06% (79 runs sampled)
4.fast-deep-equal/es6192,544 ops/sec ±2.60% (82 runs sampled)
5.nano-equal126,143 ops/sec ±2.68% (79 runs sampled)
6.shallow-equal-fuzzy112,192 ops/sec ±1.96% (83 runs sampled)
7.underscore.isEqual62,441 ops/sec ±1.78% (86 runs sampled)
8.util.isDeepStrictEqual45,652 ops/sec ±1.69% (85 runs sampled)
9.lodash.isEqual34,102 ops/sec ±1.55% (87 runs sampled)
10.deep-eql28,662 ops/sec ±5.36% (78 runs sampled)
11.ramda.equals10,623 ops/sec ±1.84% (86 runs sampled)
12.assert.deepStrictEqual271 ops/sec ±1.22% (82 runs sampled)
13.deep-equal61.11 ops/sec ±4.58% (40 runs sampled)
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文