版博士V2.0程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <h1 align=center>
  2. <a href="http://chaijs.com" title="Chai Documentation">
  3. <img alt="deep-eql" src="https://raw.githubusercontent.com/chaijs/deep-eql/main/deep-eql-logo.svg"/>
  4. </a>
  5. </h1>
  6. <p align=center>
  7. Improved deep equality testing for <a href="http://nodejs.org/">node</a> and the browser.
  8. </p>
  9. <p align=center>
  10. <a href="https://github.com/chaijs/deep-eql/actions">
  11. <img
  12. alt="build:?"
  13. src="https://github.com/chaijs/deep-eql/workflows/Build/badge.svg"
  14. />
  15. </a><a href="https://coveralls.io/r/chaijs/deep-eql">
  16. <img
  17. alt="coverage:?"
  18. src="https://img.shields.io/coveralls/chaijs/deep-eql/master.svg?style=flat-square"
  19. />
  20. </a><a href="https://www.npmjs.com/packages/deep-eql">
  21. <img
  22. alt="dependencies:?"
  23. src="https://img.shields.io/npm/dm/deep-eql.svg?style=flat-square"
  24. />
  25. </a><a href="">
  26. <img
  27. alt="devDependencies:?"
  28. src="https://img.shields.io/david/chaijs/deep-eql.svg?style=flat-square"
  29. />
  30. </a>
  31. <br>
  32. <a href="https://chai-slack.herokuapp.com/">
  33. <img
  34. alt="Join the Slack chat"
  35. src="https://img.shields.io/badge/slack-join%20chat-E2206F.svg?style=flat-square"
  36. />
  37. </a>
  38. <a href="https://gitter.im/chaijs/deep-eql">
  39. <img
  40. alt="Join the Gitter chat"
  41. src="https://img.shields.io/badge/gitter-join%20chat-D0104D.svg?style=flat-square"
  42. />
  43. </a>
  44. </p>
  45. ## What is Deep-Eql?
  46. Deep Eql is a module which you can use to determine if two objects are "deeply" equal - that is, rather than having referential equality (`a === b`), this module checks an object's keys recursively, until it finds primitives to check for referential equality. For more on equality in JavaScript, read [the comparison operators article on mdn](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators).
  47. As an example, take the following:
  48. ```js
  49. 1 === 1 // These are primitives, they hold the same reference - they are strictly equal
  50. 1 == '1' // These are two different primitives, through type coercion they hold the same value - they are loosely equal
  51. { a: 1 } !== { a: 1 } // These are two different objects, they hold different references and so are not strictly equal - even though they hold the same values inside
  52. { a: 1 } != { a: 1 } // They have the same type, meaning loose equality performs the same check as strict equality - they are still not equal.
  53. var deepEql = require("deep-eql");
  54. deepEql({ a: 1 }, { a: 1 }) === true // deepEql can determine that they share the same keys and those keys share the same values, therefore they are deeply equal!
  55. ```
  56. ## Installation
  57. ### Node.js
  58. `deep-eql` is available on [npm](http://npmjs.org).
  59. $ npm install deep-eql
  60. ## Usage
  61. The primary export of `deep-eql` is function that can be given two objects to compare. It will always return a boolean which can be used to determine if two objects are deeply equal.
  62. ### Rules
  63. - Strict equality for non-traversable nodes according to [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is):
  64. - `eql(NaN, NaN).should.be.true;`
  65. - `eql(-0, +0).should.be.false;`
  66. - All own and inherited enumerable properties are considered:
  67. - `eql(Object.create({ foo: { a: 1 } }), Object.create({ foo: { a: 1 } })).should.be.true;`
  68. - `eql(Object.create({ foo: { a: 1 } }), Object.create({ foo: { a: 2 } })).should.be.false;`
  69. - When comparing `Error` objects, only `name`, `message`, and `code` properties are considered, regardless of enumerability:
  70. - `eql(Error('foo'), Error('foo')).should.be.true;`
  71. - `eql(Error('foo'), Error('bar')).should.be.false;`
  72. - `eql(Error('foo'), TypeError('foo')).should.be.false;`
  73. - `eql(Object.assign(Error('foo'), { code: 42 }), Object.assign(Error('foo'), { code: 42 })).should.be.true;`
  74. - `eql(Object.assign(Error('foo'), { code: 42 }), Object.assign(Error('foo'), { code: 13 })).should.be.false;`
  75. - `eql(Object.assign(Error('foo'), { otherProp: 42 }), Object.assign(Error('foo'), { otherProp: 13 })).should.be.true;`
  76. - Arguments are not Arrays:
  77. - `eql([], arguments).should.be.false;`
  78. - `eql([], Array.prototype.slice.call(arguments)).should.be.true;`