Skip to content

Commit

Permalink
refactor: use functions from @sinonjs/commons
Browse files Browse the repository at this point in the history
  • Loading branch information
mgred committed Aug 3, 2019
1 parent f9728f9 commit 545c39c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
16 changes: 9 additions & 7 deletions lib/deep-equal.js
Expand Up @@ -2,6 +2,8 @@

var valueToString = require("@sinonjs/commons").valueToString;
var className = require("@sinonjs/commons").className;
var arrayProto = require("@sinonjs/commons").prototypes.array;
var objectProto = require("@sinonjs/commons").prototypes.object;

var getClass = require("./get-class");
var identical = require("./identical");
Expand All @@ -14,10 +16,10 @@ var isObject = require("./is-object");
var isSet = require("./is-set");
var isSubset = require("./is-subset");

var every = Array.prototype.every;
var every = arrayProto.every;
var getTime = Date.prototype.getTime;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var indexOf = Array.prototype.indexOf;
var hasOwnProperty = objectProto.hasOwnProperty;
var indexOf = arrayProto.indexOf;
var keys = Object.keys;
var getOwnPropertySymbols = Object.getOwnPropertySymbols;

Expand Down Expand Up @@ -172,8 +174,8 @@ function deepEqualCyclic(actual, expectation, match) {
return mapsDeeplyEqual;
}

return every.call(expectationKeysAndSymbols, function(key) {
if (!hasOwnProperty.call(actualObj, key)) {
return every(expectationKeysAndSymbols, function(key) {
if (!hasOwnProperty(actualObj, key)) {
return false;
}

Expand All @@ -185,10 +187,10 @@ function deepEqualCyclic(actual, expectation, match) {
// (it's faster to check for isObject first, than to
// get -1 from getIndex for non objects)
var actualIndex = actualObject
? indexOf.call(actualObjects, actualValue)
? indexOf(actualObjects, actualValue)
: -1;
var expectationIndex = expectationObject
? indexOf.call(expectationObjects, expectationValue)
? indexOf(expectationObjects, expectationValue)
: -1;
// determines the new paths of the objects
// - for non cyclic objects the current path will be extended
Expand Down
4 changes: 2 additions & 2 deletions lib/get-class.js
@@ -1,12 +1,12 @@
"use strict";

var o = Object.prototype;
var toString = require("@sinonjs/commons").prototypes.object.toString;

function getClass(value) {
// Returns the internal [[Class]] by calling Object.prototype.toString
// with the provided value as this. Return value is a string, naming the
// internal class, e.g. "Array"
return o.toString.call(value).split(/[ \]]/)[1];
return toString(value).split(/[ \]]/)[1];
}

module.exports = getClass;
5 changes: 2 additions & 3 deletions lib/matcher.js
Expand Up @@ -19,6 +19,7 @@ var some = arrayProto.some;

var hasOwnProperty = objectProto.hasOwnProperty;
var isPrototypeOf = objectProto.isPrototypeOf;
var objectToString = objectProto.toString;

var stringIndexOf = stringProto.indexOf;

Expand Down Expand Up @@ -256,9 +257,7 @@ match.instanceOf = function(type) {
}
return match(function(actual) {
return actual instanceof type;
}, "instanceOf(" +
(functionName(type) || Object.prototype.toString.call(type)) +
")");
}, "instanceOf(" + (functionName(type) || objectToString(type)) + ")");
};

function createPropertyMatcher(propertyTest, messagePrefix) {
Expand Down

0 comments on commit 545c39c

Please sign in to comment.