only-shallow
Advanced tools
Comparing version 1.1.2 to 1.1.3
36
index.js
@@ -28,13 +28,12 @@ 'use strict' | ||
* | ||
* 1. Use loose equality (==) only for value types (non-objects). This is the | ||
* biggest difference between only-shallow and deeper / deepest (along with | ||
* being more of a duck-typer, because it doesn't care about constructor | ||
* 1. Use loose equality (`==`) only for value types (non-objects). This is the | ||
* biggest difference between `only-shallow` and `deeper` / `deepest` (along | ||
* with being more of a duck-typer, because it doesn't care about constructor | ||
* matching), and it needs to be careful to filter out objects (including | ||
* Arrays). | ||
* 2. `null` *is* an object -- a singleton value object, in fact -- so if | ||
* either is null, return a == b. For the purposes of only-shallow, | ||
* 2. `null` *is* an object – a singleton value object, in fact – so if | ||
* either is `null`, return a == b. For the purposes of `only-shallow`, | ||
* loose testing of emptiness makes sense. | ||
* 3. Since the only matching entities to get to this test must be objects, if | ||
* a or b is not an object, they're clearly not the same. All unfiltered a | ||
* and b getting are objects (including null). | ||
* 3. Since the only way to make it this far is for `a` or `b` to be an object, if | ||
* `a` or `b` is *not* an object, they're clearly not the same. | ||
* 4. It's much faster to compare dates by numeric value than by lexical value. | ||
@@ -45,17 +44,8 @@ * 5. Same goes for Regexps. | ||
* 7. Objects are more complex: | ||
* a. ensure that a and b are on the same constructor chain | ||
* b. ensure that a and b have the same number of own properties (which is | ||
* what Object.keys returns). | ||
* c. ensure that cyclical references don't blow up the stack. | ||
* d. ensure that all the key names match (faster) | ||
* e. esnure that all of the associated values match, recursively (slower) | ||
* | ||
* (SOMEWHAT UNTESTED) ASSUMPTIONS: | ||
* | ||
* o Functions are only considered identical if they unify to the same | ||
* reference. To anything else is to invite the wrath of the halting problem. | ||
* o V8 is smart enough to optimize treating an Array like any other kind of | ||
* object. | ||
* o Users of this function are cool with mutually recursive data structures | ||
* that are otherwise identical being treated as the same. | ||
* a. Return `true` if `a` and `b` both have no properties. | ||
* b. Ensure that `a` and `b` have the same number of own properties with the | ||
* same names (which is what `Object.keys()` returns). | ||
* c. Ensure that cyclical references don't blow up the stack. | ||
* d. Ensure that all the key names match (faster). | ||
* e. Ensure that all of the associated values match, recursively (slower). | ||
*/ | ||
@@ -62,0 +52,0 @@ function shallower_ (a, b, ca, cb) { |
{ | ||
"name": "only-shallow", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "like `deeper` and `deepest`, but less strict, and with 90s flavor", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -47,4 +47,30 @@ [![only-shallow on npm](https://img.shields.io/npm/v/only-shallow.svg?style=flat)](http://npm.im/only-shallow) | ||
## details | ||
Copied from the source, here are the details of `only-shallow`'s algorithm: | ||
1. Use loose equality (`==`) only for value types (non-objects). This is the | ||
biggest difference between `only-shallow` and `deeper` / `deepest` (along | ||
with being more of a duck-typer, because it doesn't care about constructor | ||
matching), and it needs to be careful to filter out objects (including | ||
Arrays). | ||
2. `null` *is* an object – a singleton value object, in fact – so if | ||
either is `null`, return a == b. For the purposes of `only-shallow`, | ||
loose testing of emptiness makes sense. | ||
3. Since the only way to make it this far is for `a` or `b` to be an object, if | ||
`a` or `b` is *not* an object, they're clearly not the same. | ||
4. It's much faster to compare dates by numeric value than by lexical value. | ||
5. Same goes for Regexps. | ||
6. The parts of an arguments list most people care about are the arguments | ||
themselves, not the callee, which you shouldn't be looking at anyway. | ||
7. Objects are more complex: | ||
a. Return `true` if `a` and `b` both have no properties. | ||
b. Ensure that `a` and `b` have the same number of own properties with the | ||
same names (which is what `Object.keys()` returns). | ||
c. Ensure that cyclical references don't blow up the stack. | ||
d. Ensure that all the key names match (faster). | ||
e. Ensure that all of the associated values match, recursively (slower). | ||
## license | ||
ISC. Go nuts. |
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
12579
76
271