fast-equals
Advanced tools
Comparing version 1.1.0 to 1.2.0
# fast-equals CHANGELOG | ||
## 1.2.0 | ||
* Surface `isSameValueZero` as [`sameValueZeroEqual`](#samevaluezeroequal) option | ||
## 1.1.0 | ||
* Add TypeScript typings (thanks [@josh-sachs](https://github.com/josh-sachs)) | ||
## 1.0.6 | ||
@@ -4,0 +12,0 @@ |
@@ -157,3 +157,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
exports.__esModule = true; | ||
exports.shallowEqual = exports.deepEqual = exports.createCustomEqual = undefined; | ||
exports.shallowEqual = exports.sameValueZeroEqual = exports.deepEqual = exports.createCustomEqual = undefined; | ||
@@ -173,2 +173,3 @@ var _comparator = __webpack_require__(3); | ||
var deepEqual = exports.deepEqual = (0, _comparator2.default)(); | ||
var sameValueZeroEqual = exports.sameValueZeroEqual = (0, _utils.createIsSameValueZero)(); | ||
var shallowEqual = exports.shallowEqual = (0, _comparator2.default)(_utils.createIsSameValueZero); | ||
@@ -179,2 +180,3 @@ | ||
deep: deepEqual, | ||
sameValueZero: sameValueZeroEqual, | ||
shallow: shallowEqual | ||
@@ -181,0 +183,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
!(function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("fe",[],t):"object"==typeof exports?exports.fe=t():e.fe=t()})("undefined"!=typeof self?self:this,(function(){return (function(e){function t(n){if(r[n])return r[n].exports;var u=r[n]={i:n,l:!1,exports:{}};return e[n].call(u.exports,u,u.exports,t),u.l=!0,u.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)})([(function(e,t,r){"use strict";t.__esModule=!0;var n=(t.createIsSameValueZero=function(){return function(e,t){return e===t||e!==e&&t!==t}},t.toPairs=function(e){var t={keys:new Array(e.size),values:new Array(e.size)},r=0;return e.forEach((function(e,n){t.keys[r]=n,t.values[r++]=e})),t});t.areIterablesEqual=function(e,t,r,u){if(e.size!==t.size)return!1;var o=n(e),a=n(t);return u?r(o.keys,a.keys)&&r(o.values,a.values):r(o.values,a.values)}}),(function(e,t,r){e.exports=r(2)}),(function(e,t,r){"use strict";t.__esModule=!0,t.shallowEqual=t.deepEqual=t.createCustomEqual=void 0;var n=r(3),u=(function(e){return e&&e.__esModule?e:{default:e}})(n),o=r(0),a=t.createCustomEqual=u.default,f=t.deepEqual=(0,u.default)(),i=t.shallowEqual=(0,u.default)(o.createIsSameValueZero);t.default={createCustom:a,deep:f,shallow:i}}),(function(e,t,r){"use strict";t.__esModule=!0;var n=r(0),u="function"==typeof Map,o="function"==typeof Set,a=(0,n.createIsSameValueZero)(),f=function(e){function t(e,f){if(a(e,f))return!0;var i=typeof e;if(i!==typeof f)return!1;if("object"===i&&e&&f){var s=Array.isArray(e),l=Array.isArray(f),c=void 0;if(s||l){if(s!==l||e.length!==f.length)return!1;for(c=0;c<e.length;c++)if(!r(e[c],f[c]))return!1;return!0}var p=e instanceof Date,d=f instanceof Date;if(p||d)return p===d&&a(e.getTime(),f.getTime());var y=e instanceof RegExp,v=f instanceof RegExp;if(y||v)return y===v&&e.source===f.source&&e.global===f.global&&e.ignoreCase===f.ignoreCase&&e.multiline===f.multiline;if(u){var b=e instanceof Map,g=f instanceof Map;if(b||g)return b===g&&(0,n.areIterablesEqual)(e,f,t,!0)}if(o){var m=e instanceof Set,h=f instanceof Set;if(m||h)return m===h&&(0,n.areIterablesEqual)(e,f,t,!1)}var x=Object.keys(e);if(x.length!==Object.keys(f).length)return!1;var E=void 0;for(c=0;c<x.length;c++)if(E=x[c],!Object.prototype.hasOwnProperty.call(f,E)||!r(e[E],f[E]))return!1;return!0}return!1}var r="function"==typeof e?e(t):t;return t};t.default=f})])})); | ||
!(function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("fe",[],t):"object"==typeof exports?exports.fe=t():e.fe=t()})("undefined"!=typeof self?self:this,(function(){return (function(e){function t(n){if(r[n])return r[n].exports;var a=r[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,t),a.l=!0,a.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)})([(function(e,t,r){"use strict";t.__esModule=!0;var n=(t.createIsSameValueZero=function(){return function(e,t){return e===t||e!==e&&t!==t}},t.toPairs=function(e){var t={keys:new Array(e.size),values:new Array(e.size)},r=0;return e.forEach((function(e,n){t.keys[r]=n,t.values[r++]=e})),t});t.areIterablesEqual=function(e,t,r,a){if(e.size!==t.size)return!1;var u=n(e),o=n(t);return a?r(u.keys,o.keys)&&r(u.values,o.values):r(u.values,o.values)}}),(function(e,t,r){e.exports=r(2)}),(function(e,t,r){"use strict";t.__esModule=!0,t.shallowEqual=t.sameValueZeroEqual=t.deepEqual=t.createCustomEqual=void 0;var n=r(3),a=(function(e){return e&&e.__esModule?e:{default:e}})(n),u=r(0),o=t.createCustomEqual=a.default,f=t.deepEqual=(0,a.default)(),i=t.sameValueZeroEqual=(0,u.createIsSameValueZero)(),s=t.shallowEqual=(0,a.default)(u.createIsSameValueZero);t.default={createCustom:o,deep:f,sameValueZero:i,shallow:s}}),(function(e,t,r){"use strict";t.__esModule=!0;var n=r(0),a="function"==typeof Map,u="function"==typeof Set,o=(0,n.createIsSameValueZero)(),f=function(e){function t(e,f){if(o(e,f))return!0;var i=typeof e;if(i!==typeof f)return!1;if("object"===i&&e&&f){var s=Array.isArray(e),l=Array.isArray(f),c=void 0;if(s||l){if(s!==l||e.length!==f.length)return!1;for(c=0;c<e.length;c++)if(!r(e[c],f[c]))return!1;return!0}var p=e instanceof Date,d=f instanceof Date;if(p||d)return p===d&&o(e.getTime(),f.getTime());var y=e instanceof RegExp,v=f instanceof RegExp;if(y||v)return y===v&&e.source===f.source&&e.global===f.global&&e.ignoreCase===f.ignoreCase&&e.multiline===f.multiline;if(a){var m=e instanceof Map,b=f instanceof Map;if(m||b)return m===b&&(0,n.areIterablesEqual)(e,f,t,!0)}if(u){var g=e instanceof Set,E=f instanceof Set;if(g||E)return g===E&&(0,n.areIterablesEqual)(e,f,t,!1)}var h=Object.keys(e);if(h.length!==Object.keys(f).length)return!1;var x=void 0;for(c=0;c<h.length;c++)if(x=h[c],!Object.prototype.hasOwnProperty.call(f,x)||!r(e[x],f[x]))return!1;return!0}return!1}var r="function"==typeof e?e(t):t;return t};t.default=f})])})); |
@@ -10,2 +10,3 @@ // comparator | ||
export var deepEqual = createComparator(); | ||
export var sameValueZeroEqual = createIsSameValueZero(); | ||
export var shallowEqual = createComparator(createIsSameValueZero); | ||
@@ -16,3 +17,4 @@ | ||
deep: deepEqual, | ||
sameValueZero: sameValueZeroEqual, | ||
shallow: shallowEqual | ||
}; |
declare type Comparator = (objectA, objectB) => boolean; | ||
export declare function createCustomEqual(createIsEqual?: Comparator): Comparator; | ||
export declare function createCustomEqual(createIsEqual?: Comparator): Comparator; | ||
export declare function deepEqual(objectA, objectB): boolean; | ||
export declare function sameValueZeroEqual(objectA, objectB): boolean; | ||
export declare function shallowEqual(objectA, objectB): boolean; | ||
export default { | ||
createCustom: createCustomEqual, | ||
deep: deepEqual, | ||
shallow: shallowEqual, | ||
}; | ||
createCustom: createCustomEqual, | ||
deep: deepEqual, | ||
sameValueZero: sameValueZeroEqual, | ||
shallow: shallowEqual | ||
}; |
'use strict'; | ||
exports.__esModule = true; | ||
exports.shallowEqual = exports.deepEqual = exports.createCustomEqual = undefined; | ||
exports.shallowEqual = exports.sameValueZeroEqual = exports.deepEqual = exports.createCustomEqual = undefined; | ||
@@ -19,2 +19,3 @@ var _comparator = require('./comparator'); | ||
var deepEqual = exports.deepEqual = (0, _comparator2.default)(); | ||
var sameValueZeroEqual = exports.sameValueZeroEqual = (0, _utils.createIsSameValueZero)(); | ||
var shallowEqual = exports.shallowEqual = (0, _comparator2.default)(_utils.createIsSameValueZero); | ||
@@ -25,3 +26,4 @@ | ||
deep: deepEqual, | ||
sameValueZero: sameValueZeroEqual, | ||
shallow: shallowEqual | ||
}; |
@@ -25,3 +25,3 @@ { | ||
"babel-eslint": "^8.2.2", | ||
"babel-loader": "^7.1.2", | ||
"babel-loader": "^7.1.3", | ||
"babel-preset-env": "^1.6.1", | ||
@@ -35,7 +35,7 @@ "babel-preset-react": "^6.24.1", | ||
"deep-equal": "^1.0.1", | ||
"eslint": "^4.18.1", | ||
"eslint": "^4.18.2", | ||
"eslint-config-rapid7": "^2.11.1", | ||
"eslint-friendly-formatter": "^3.0.0", | ||
"eslint-loader": "^1.9.0", | ||
"fast-deep-equal": "^1.0.0", | ||
"eslint-loader": "^2.0.0", | ||
"fast-deep-equal": "^1.1.0", | ||
"html-webpack-plugin": "^2.30.1", | ||
@@ -50,3 +50,3 @@ "in-publish": "^2.0.0", | ||
"shallow-equal-fuzzy": "^0.0.2", | ||
"sinon": "^4.3.0", | ||
"sinon": "^4.4.2", | ||
"underscore": "^1.8.3", | ||
@@ -94,3 +94,3 @@ "webpack": "^3.11.0", | ||
}, | ||
"version": "1.1.0" | ||
"version": "1.2.0" | ||
} |
@@ -7,3 +7,3 @@ # fast-equals | ||
Perform [blazing fast](#benchmarks) equality comparisons (either deep or shallow) on two objects passed. It has no dependencies, and is ~1.1Kb when minified and gzipped. | ||
Perform [blazing fast](#benchmarks) equality comparisons (either deep or shallow) on two objects passed. It has no dependencies, and is ~1.2Kb when minified and gzipped. | ||
@@ -25,2 +25,3 @@ Unlike most equality validation libraries, the following types are handled out-of-the-box: | ||
* [shallowEqual](#shallowequal) | ||
* [sameValueZeroEqual](#samevaluezeroequal) | ||
* [createCustomEqual](#createcustomequal) | ||
@@ -35,5 +36,5 @@ * [Benchmarks](#benchmarks) | ||
```javascript | ||
import fe from 'fast-equals'; | ||
import fe from "fast-equals"; | ||
console.log(fe.deep({foo: 'bar'}, {foo: 'bar'})); // true | ||
console.log(fe.deep({ foo: "bar" }, { foo: "bar" })); // true | ||
``` | ||
@@ -44,5 +45,5 @@ | ||
```javascript | ||
import {deepEqual} from 'fast-equals'; | ||
import { deepEqual } from "fast-equals"; | ||
console.log(deepEqual({foo: 'bar'}, {foo: 'bar'})); // true | ||
console.log(deepEqual({ foo: "bar" }, { foo: "bar" })); // true | ||
``` | ||
@@ -54,3 +55,3 @@ | ||
*Aliased on the default export as `fe.deep`* | ||
_Aliased on the default export as `fe.deep`_ | ||
@@ -60,6 +61,6 @@ Performs a deep equality comparison on the two objects passed and returns a boolean representing the value equivalency of the objects. | ||
```javascript | ||
import {deepEqual} from 'fast-equals'; | ||
import { deepEqual } from "fast-equals"; | ||
const objectA = {foo: {bar: 'baz'}}; | ||
const objectB = {foo: {bar: 'baz'}}; | ||
const objectA = { foo: { bar: "baz" } }; | ||
const objectB = { foo: { bar: "baz" } }; | ||
@@ -72,3 +73,3 @@ console.log(objectA === objectB); // false | ||
*Aliased on the default export as `fe.shallow`* | ||
_Aliased on the default export as `fe.shallow`_ | ||
@@ -78,9 +79,9 @@ Performs a shallow equality comparison on the two objects passed and returns a boolean representing the value equivalency of the objects. | ||
```javascript | ||
import {shallowEqual} from 'fast-equals'; | ||
import { shallowEqual } from "fast-equals"; | ||
const nestedObject = {bar: 'baz'}; | ||
const nestedObject = { bar: "baz" }; | ||
const objectA = {foo: nestedObject}; | ||
const objectB = {foo: nestedObject}; | ||
const objectC = {foo: {bar: 'baz'}}; | ||
const objectA = { foo: nestedObject }; | ||
const objectB = { foo: nestedObject }; | ||
const objectC = { foo: { bar: "baz" } }; | ||
@@ -92,5 +93,25 @@ console.log(objectA === objectB); // false | ||
#### sameValueZeroEqual | ||
_Aliased on the default export as `fe.sameValueZero`_ | ||
Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) comparison on the two objects passed and returns a boolean representing the value equivalency of the objects. In simple terms, this means either strictly equal or both `NaN`. | ||
```javascript | ||
import { sameValueZeroEqual } from "fast-equals"; | ||
const mainObject = { foo: NaN, bar: "baz" }; | ||
const objectA = "baz"; | ||
const objectB = NaN; | ||
const objectC = { foo: NaN, bar: "baz" }; | ||
console.log(sameValueZeroEqual(mainObject.bar, objectA)); // true | ||
console.log(sameValueZeroEqual(mainObject.foo, objectB)); // true | ||
console.log(sameValueZeroEqual(mainObject, objectC)); // false | ||
``` | ||
#### createCustomEqual | ||
*Aliased on the default export as `fe.createCustom`* | ||
_Aliased on the default export as `fe.createCustom`_ | ||
@@ -102,6 +123,6 @@ Creates a custom equality comparator that will be used on nested values in the object. Unlike `deepEqual` and `shallowEqual`, this is a partial-application function that will receive the internal comparator and should return a function that compares two objects. | ||
```javascript | ||
import {createCustomEqual} from 'fast-equals'; | ||
import decircularize from 'decircularize'; | ||
import { createCustomEqual } from "fast-equals"; | ||
import decircularize from "decircularize"; | ||
const isDeepEqualCircular = createCustomEqual((comparator) => { | ||
const isDeepEqualCircular = createCustomEqual(comparator => { | ||
return (objectA, objectB) => { | ||
@@ -137,3 +158,3 @@ return comparator(decircularize(objectA), decircularize(objectB)); | ||
| | Operations / second | Relative margin of error | | ||
|------------------------|---------------------|--------------------------| | ||
| ---------------------- | ------------------- | ------------------------ | | ||
| **fast-equals** | **197,615** | **0.53%** | | ||
@@ -140,0 +161,0 @@ | nano-equal | 121.843 | 0.49% | |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48901
550
194