Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Typeof Equality #2982

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/_createIndexFinder.js
Expand Up @@ -6,7 +6,7 @@ import isNaN from './isNaN.js';
export default function createIndexFinder(dir, predicateFind, sortedIndex) {
return function(array, item, idx) {
var i = 0, length = getLength(array);
if (typeof idx == 'number') {
if (typeof idx === 'number') {
if (dir > 0) {
i = idx >= 0 ? idx : Math.max(idx + length, i);
} else {
Expand Down
2 changes: 1 addition & 1 deletion modules/_createSizePropertyCheck.js
Expand Up @@ -4,6 +4,6 @@ import { MAX_ARRAY_INDEX } from './_setup.js';
export default function createSizePropertyCheck(getSizeProperty) {
return function(collection) {
var sizeProperty = getSizeProperty(collection);
return typeof sizeProperty == 'number' && sizeProperty >= 0 && sizeProperty <= MAX_ARRAY_INDEX;
return typeof sizeProperty === 'number' && sizeProperty >= 0 && sizeProperty <= MAX_ARRAY_INDEX;
}
}
4 changes: 2 additions & 2 deletions modules/_setup.js
Expand Up @@ -4,8 +4,8 @@ export var VERSION = '1.13.6';
// Establish the root object, `window` (`self`) in the browser, `global`
// on the server, or `this` in some virtual machines. We use `self`
// instead of `window` for `WebWorker` support.
export var root = (typeof self == 'object' && self.self === self && self) ||
(typeof global == 'object' && global.global === global && global) ||
export var root = (typeof self === 'object' && self.self === self && self) ||
(typeof global === 'object' && global.global === global && global) ||
Function('return this')() ||
{};

Expand Down
2 changes: 1 addition & 1 deletion modules/contains.js
Expand Up @@ -5,6 +5,6 @@ import indexOf from './indexOf.js';
// Determine if the array or object contains a given item (using `===`).
export default function contains(obj, item, fromIndex, guard) {
if (!isArrayLike(obj)) obj = values(obj);
if (typeof fromIndex != 'number' || guard) fromIndex = 0;
if (typeof fromIndex !== 'number' || guard) fromIndex = 0;
return indexOf(obj, item, fromIndex) >= 0;
}
2 changes: 1 addition & 1 deletion modules/isEmpty.js
Expand Up @@ -11,7 +11,7 @@ export default function isEmpty(obj) {
// Skip the more expensive `toString`-based type checks if `obj` has no
// `.length`.
var length = getLength(obj);
if (typeof length == 'number' && (
if (typeof length === 'number' && (
isArray(obj) || isString(obj) || isArguments(obj)
)) return length === 0;
return getLength(keys(obj)) === 0;
Expand Down
6 changes: 3 additions & 3 deletions modules/isEqual.js
Expand Up @@ -23,7 +23,7 @@ function eq(a, b, aStack, bStack) {
if (a !== a) return b !== b;
// Exhaust primitive checks
var type = typeof a;
if (type !== 'function' && type !== 'object' && typeof b != 'object') return false;
if (type !== 'function' && type !== 'object' && typeof b !== 'object') return false;
return deepEq(a, b, aStack, bStack);
}

Expand All @@ -36,7 +36,7 @@ function deepEq(a, b, aStack, bStack) {
var className = toString.call(a);
if (className !== toString.call(b)) return false;
// Work around a bug in IE 10 - Edge 13.
if (hasStringTagBug && className == '[object Object]' && isDataView(a)) {
if (hasStringTagBug && className === '[object Object]' && isDataView(a)) {
if (!isDataView(b)) return false;
className = tagDataView;
}
Expand Down Expand Up @@ -76,7 +76,7 @@ function deepEq(a, b, aStack, bStack) {
areArrays = true;
}
if (!areArrays) {
if (typeof a != 'object' || typeof b != 'object') return false;
if (typeof a !== 'object' || typeof b !== 'object') return false;

// Objects with different constructors are not equivalent, but `Object`s or `Array`s
// from different frames are.
Expand Down
4 changes: 2 additions & 2 deletions modules/isFunction.js
Expand Up @@ -6,9 +6,9 @@ var isFunction = tagTester('Function');
// Optimize `isFunction` if appropriate. Work around some `typeof` bugs in old
// v8, IE 11 (#1621), Safari 8 (#1929), and PhantomJS (#2236).
var nodelist = root.document && root.document.childNodes;
if (typeof /./ != 'function' && typeof Int8Array != 'object' && typeof nodelist != 'function') {
if (typeof /./ !== 'function' && typeof Int8Array !== 'object' && typeof nodelist !== 'function') {
isFunction = function(obj) {
return typeof obj == 'function' || false;
return typeof obj === 'function' || false;
};
}

Expand Down
2 changes: 1 addition & 1 deletion modules/max.js
Expand Up @@ -7,7 +7,7 @@ import each from './each.js';
export default function max(obj, iteratee, context) {
var result = -Infinity, lastComputed = -Infinity,
value, computed;
if (iteratee == null || (typeof iteratee == 'number' && typeof obj[0] != 'object' && obj != null)) {
if (iteratee == null || (typeof iteratee === 'number' && typeof obj[0] !== 'object' && obj != null)) {
obj = isArrayLike(obj) ? obj : values(obj);
for (var i = 0, length = obj.length; i < length; i++) {
value = obj[i];
Expand Down
2 changes: 1 addition & 1 deletion modules/min.js
Expand Up @@ -7,7 +7,7 @@ import each from './each.js';
export default function min(obj, iteratee, context) {
var result = Infinity, lastComputed = Infinity,
value, computed;
if (iteratee == null || (typeof iteratee == 'number' && typeof obj[0] != 'object' && obj != null)) {
if (iteratee == null || (typeof iteratee === 'number' && typeof obj[0] !== 'object' && obj != null)) {
obj = isArrayLike(obj) ? obj : values(obj);
for (var i = 0, length = obj.length; i < length; i++) {
value = obj[i];
Expand Down
4 changes: 2 additions & 2 deletions test/collections.js
Expand Up @@ -883,7 +883,7 @@
assert.deepEqual(_.toArray(expected.join('')), expected, 'maintains astral characters');
assert.deepEqual(_.toArray(''), [], 'empty string into empty array');

if (typeof document != 'undefined') {
if (typeof document !== 'undefined') {
// test in IE < 9
var actual;
try {
Expand Down Expand Up @@ -942,7 +942,7 @@
}, predicate);
});

if (typeof document != 'undefined') {
if (typeof document !== 'undefined') {
QUnit.test('Can use various collection methods on NodeLists', function(assert) {
var parent = document.createElement('div');
parent.innerHTML = '<span id=id1></span>textnode<span id=id2></span>';
Expand Down
2 changes: 1 addition & 1 deletion test/cross-document.js
Expand Up @@ -111,7 +111,7 @@
assert.ok(_.isError(iError), 'even from another frame');
});

if (typeof ActiveXObject != 'undefined') {
if (typeof ActiveXObject !== 'undefined') {
QUnit.test('IE host objects', function(assert) {
var xml = new ActiveXObject('Msxml2.DOMDocument.3.0');
assert.ok(!_.isNumber(xml));
Expand Down
26 changes: 13 additions & 13 deletions underscore-esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions underscore-node-f.cjs
Expand Up @@ -11,8 +11,8 @@ var VERSION = '1.13.6';
// Establish the root object, `window` (`self`) in the browser, `global`
// on the server, or `this` in some virtual machines. We use `self`
// instead of `window` for `WebWorker` support.
var root = (typeof self == 'object' && self.self === self && self) ||
(typeof global == 'object' && global.global === global && global) ||
var root = (typeof self === 'object' && self.self === self && self) ||
(typeof global === 'object' && global.global === global && global) ||
Function('return this')() ||
{};

Expand Down Expand Up @@ -130,9 +130,9 @@ var isFunction = tagTester('Function');
// Optimize `isFunction` if appropriate. Work around some `typeof` bugs in old
// v8, IE 11 (#1621), Safari 8 (#1929), and PhantomJS (#2236).
var nodelist = root.document && root.document.childNodes;
if (typeof /./ != 'function' && typeof Int8Array != 'object' && typeof nodelist != 'function') {
if (typeof /./ !== 'function' && typeof Int8Array !== 'object' && typeof nodelist !== 'function') {
isFunction = function(obj) {
return typeof obj == 'function' || false;
return typeof obj === 'function' || false;
};
}

Expand Down Expand Up @@ -202,7 +202,7 @@ function constant(value) {
function createSizePropertyCheck(getSizeProperty) {
return function(collection) {
var sizeProperty = getSizeProperty(collection);
return typeof sizeProperty == 'number' && sizeProperty >= 0 && sizeProperty <= MAX_ARRAY_INDEX;
return typeof sizeProperty === 'number' && sizeProperty >= 0 && sizeProperty <= MAX_ARRAY_INDEX;
}
}

Expand Down Expand Up @@ -290,7 +290,7 @@ function isEmpty(obj) {
// Skip the more expensive `toString`-based type checks if `obj` has no
// `.length`.
var length = getLength(obj);
if (typeof length == 'number' && (
if (typeof length === 'number' && (
isArray(obj) || isString(obj) || isArguments$1(obj)
)) return length === 0;
return getLength(keys(obj)) === 0;
Expand Down Expand Up @@ -356,7 +356,7 @@ function eq(a, b, aStack, bStack) {
if (a !== a) return b !== b;
// Exhaust primitive checks
var type = typeof a;
if (type !== 'function' && type !== 'object' && typeof b != 'object') return false;
if (type !== 'function' && type !== 'object' && typeof b !== 'object') return false;
return deepEq(a, b, aStack, bStack);
}

Expand All @@ -369,7 +369,7 @@ function deepEq(a, b, aStack, bStack) {
var className = toString.call(a);
if (className !== toString.call(b)) return false;
// Work around a bug in IE 10 - Edge 13.
if (hasStringTagBug && className == '[object Object]' && isDataView$1(a)) {
if (hasStringTagBug && className === '[object Object]' && isDataView$1(a)) {
if (!isDataView$1(b)) return false;
className = tagDataView;
}
Expand Down Expand Up @@ -409,7 +409,7 @@ function deepEq(a, b, aStack, bStack) {
areArrays = true;
}
if (!areArrays) {
if (typeof a != 'object' || typeof b != 'object') return false;
if (typeof a !== 'object' || typeof b !== 'object') return false;

// Objects with different constructors are not equivalent, but `Object`s or `Array`s
// from different frames are.
Expand Down Expand Up @@ -1267,7 +1267,7 @@ function sortedIndex(array, obj, iteratee, context) {
function createIndexFinder(dir, predicateFind, sortedIndex) {
return function(array, item, idx) {
var i = 0, length = getLength(array);
if (typeof idx == 'number') {
if (typeof idx === 'number') {
if (dir > 0) {
i = idx >= 0 ? idx : Math.max(idx + length, i);
} else {
Expand Down Expand Up @@ -1418,7 +1418,7 @@ function some(obj, predicate, context) {
// Determine if the array or object contains a given item (using `===`).
function contains(obj, item, fromIndex, guard) {
if (!isArrayLike(obj)) obj = values(obj);
if (typeof fromIndex != 'number' || guard) fromIndex = 0;
if (typeof fromIndex !== 'number' || guard) fromIndex = 0;
return indexOf(obj, item, fromIndex) >= 0;
}

Expand Down Expand Up @@ -1460,7 +1460,7 @@ function where(obj, attrs) {
function max(obj, iteratee, context) {
var result = -Infinity, lastComputed = -Infinity,
value, computed;
if (iteratee == null || (typeof iteratee == 'number' && typeof obj[0] != 'object' && obj != null)) {
if (iteratee == null || (typeof iteratee === 'number' && typeof obj[0] !== 'object' && obj != null)) {
obj = isArrayLike(obj) ? obj : values(obj);
for (var i = 0, length = obj.length; i < length; i++) {
value = obj[i];
Expand All @@ -1485,7 +1485,7 @@ function max(obj, iteratee, context) {
function min(obj, iteratee, context) {
var result = Infinity, lastComputed = Infinity,
value, computed;
if (iteratee == null || (typeof iteratee == 'number' && typeof obj[0] != 'object' && obj != null)) {
if (iteratee == null || (typeof iteratee === 'number' && typeof obj[0] !== 'object' && obj != null)) {
obj = isArrayLike(obj) ? obj : values(obj);
for (var i = 0, length = obj.length; i < length; i++) {
value = obj[i];
Expand Down