Socket
Socket
Sign inDemoInstall

should-equal

Package Overview
Dependencies
1
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

LICENSE

48

cjs/should-equal.js

@@ -5,3 +5,3 @@ 'use strict';

var getType = _interopDefault(require('should-type'));
var t = _interopDefault(require('should-type'));

@@ -25,4 +25,4 @@ function format(msg) {

function typeToString(t) {
return t.type + (t.cls ? '(' + t.cls + (t.sub ? ' ' + t.sub : '') + ')' : '');
function typeToString(tp) {
return tp.type + (tp.cls ? '(' + tp.cls + (tp.sub ? ' ' + tp.sub : '') + ')' : '');
}

@@ -112,9 +112,7 @@

var typeA = getType(a);
var typeB = getType(b);
var typeA = t(a);
var typeB = t(b);
// if objects has different types they are not equal
var typeDifferent = typeA.type !== typeB.type || typeA.cls !== typeB.cls;
if (typeDifferent || ((this.checkSubType && typeA.sub !== typeB.sub) || !this.checkSubType)) {
if (typeA.type !== typeB.type || typeA.cls !== typeB.cls || typeA.sub !== typeB.sub) {
return this.collectFail(true, format(DIFFERENT_TYPES, typeToString(typeA), typeToString(typeB)));

@@ -196,4 +194,4 @@ }

checkPropertyEquality: function(propertyName) {
var eq = new EQ(this, this.a[propertyName], this.b[propertyName], this.path.concat([propertyName]));
eq.check0();
var _eq = new EQ(this, this.a[propertyName], this.b[propertyName], this.path.concat([propertyName]));
_eq.check0();
},

@@ -205,11 +203,11 @@

EQ.add('number', function(a, b) {
EQ.add(t.NUMBER, function(a, b) {
this.collectFail((a !== a && b === b) || (b !== b && a === a) || (a !== b && a === a && b === b), EQUALITY);
});
['symbol', 'boolean', 'string'].forEach(function(tp) {
[t.SYMBOL, t.BOOLEAN, t.STRING].forEach(function(tp) {
EQ.add(tp, EQ.checkStrictEquality);
});
EQ.add('function', function(a, b) {
EQ.add(t.FUNCTION, function(a, b) {
// functions are compared by their source code

@@ -221,3 +219,3 @@ this.collectFail(a.toString() !== b.toString(), FUNCTION_SOURCES);

EQ.add('object', 'regexp', function(a, b) {
EQ.add(t.OBJECT, t.REGEXP, function(a, b) {
// check regexp flags

@@ -232,3 +230,3 @@ var flags = ['source', 'global', 'multiline', 'lastIndex', 'ignoreCase', 'sticky', 'unicode'];

EQ.add('object', 'date', function(a, b) {
EQ.add(t.OBJECT, t.DATE, function(a, b) {
//check by timestamp only (using .valueOf)

@@ -240,4 +238,4 @@ this.collectFail(+a !== +b, EQUALITY);

['number', 'boolean', 'string'].forEach(function(tp) {
EQ.add('object', tp, function(a, b) {
[t.NUMBER, t.BOOLEAN, t.STRING].forEach(function(tp) {
EQ.add(t.OBJECT, tp, function(a, b) {
//primitive type wrappers

@@ -250,8 +248,8 @@ this.collectFail(a.valueOf() !== b.valueOf(), WRAPPED_VALUE);

EQ.add('object', function(a, b) {
EQ.add(t.OBJECT, function(a, b) {
this.checkPlainObjectsEquality(a, b);
});
['array', 'arguments', 'typed-array'].forEach(function(tp) {
EQ.add('object', tp, function(a, b) {
[t.ARRAY, t.ARGUMENTS, t.TYPED_ARRAY].forEach(function(tp) {
EQ.add(t.OBJECT, tp, function(a, b) {
this.checkPropertyEquality('length');

@@ -263,3 +261,3 @@

EQ.add('object', 'array-buffer', function(a, b) {
EQ.add(t.OBJECT, t.ARRAY_BUFFER, function(a, b) {
this.checkPropertyEquality('byteLength');

@@ -270,3 +268,3 @@

EQ.add('object', 'error', function(a, b) {
EQ.add(t.OBJECT, t.ERROR, function(a, b) {
this.checkPropertyEquality('name');

@@ -278,3 +276,3 @@ this.checkPropertyEquality('message');

EQ.add('object', 'buffer', function(a) {
EQ.add(t.OBJECT, t.BUFFER, function(a) {
this.checkPropertyEquality('length');

@@ -291,4 +289,4 @@

['map', 'set'].forEach(function(tp) {
EQ.add('object', tp, function(a, b) {
[t.MAP, t.SET, t.WEAK_MAP, t.WEAK_SET].forEach(function(tp) {
EQ.add(t.OBJECT, tp, function(a, b) {
this._meet.push([a, b]);

@@ -295,0 +293,0 @@

@@ -1,2 +0,2 @@

import getType from 'should-type';
import t from 'should-type';

@@ -20,4 +20,4 @@ function format(msg) {

function typeToString(t) {
return t.type + (t.cls ? '(' + t.cls + (t.sub ? ' ' + t.sub : '') + ')' : '');
function typeToString(tp) {
return tp.type + (tp.cls ? '(' + tp.cls + (tp.sub ? ' ' + tp.sub : '') + ')' : '');
}

@@ -107,9 +107,7 @@

var typeA = getType(a);
var typeB = getType(b);
var typeA = t(a);
var typeB = t(b);
// if objects has different types they are not equal
var typeDifferent = typeA.type !== typeB.type || typeA.cls !== typeB.cls;
if (typeDifferent || ((this.checkSubType && typeA.sub !== typeB.sub) || !this.checkSubType)) {
if (typeA.type !== typeB.type || typeA.cls !== typeB.cls || typeA.sub !== typeB.sub) {
return this.collectFail(true, format(DIFFERENT_TYPES, typeToString(typeA), typeToString(typeB)));

@@ -191,4 +189,4 @@ }

checkPropertyEquality: function(propertyName) {
var eq = new EQ(this, this.a[propertyName], this.b[propertyName], this.path.concat([propertyName]));
eq.check0();
var _eq = new EQ(this, this.a[propertyName], this.b[propertyName], this.path.concat([propertyName]));
_eq.check0();
},

@@ -200,11 +198,11 @@

EQ.add('number', function(a, b) {
EQ.add(t.NUMBER, function(a, b) {
this.collectFail((a !== a && b === b) || (b !== b && a === a) || (a !== b && a === a && b === b), EQUALITY);
});
['symbol', 'boolean', 'string'].forEach(function(tp) {
[t.SYMBOL, t.BOOLEAN, t.STRING].forEach(function(tp) {
EQ.add(tp, EQ.checkStrictEquality);
});
EQ.add('function', function(a, b) {
EQ.add(t.FUNCTION, function(a, b) {
// functions are compared by their source code

@@ -216,3 +214,3 @@ this.collectFail(a.toString() !== b.toString(), FUNCTION_SOURCES);

EQ.add('object', 'regexp', function(a, b) {
EQ.add(t.OBJECT, t.REGEXP, function(a, b) {
// check regexp flags

@@ -227,3 +225,3 @@ var flags = ['source', 'global', 'multiline', 'lastIndex', 'ignoreCase', 'sticky', 'unicode'];

EQ.add('object', 'date', function(a, b) {
EQ.add(t.OBJECT, t.DATE, function(a, b) {
//check by timestamp only (using .valueOf)

@@ -235,4 +233,4 @@ this.collectFail(+a !== +b, EQUALITY);

['number', 'boolean', 'string'].forEach(function(tp) {
EQ.add('object', tp, function(a, b) {
[t.NUMBER, t.BOOLEAN, t.STRING].forEach(function(tp) {
EQ.add(t.OBJECT, tp, function(a, b) {
//primitive type wrappers

@@ -245,8 +243,8 @@ this.collectFail(a.valueOf() !== b.valueOf(), WRAPPED_VALUE);

EQ.add('object', function(a, b) {
EQ.add(t.OBJECT, function(a, b) {
this.checkPlainObjectsEquality(a, b);
});
['array', 'arguments', 'typed-array'].forEach(function(tp) {
EQ.add('object', tp, function(a, b) {
[t.ARRAY, t.ARGUMENTS, t.TYPED_ARRAY].forEach(function(tp) {
EQ.add(t.OBJECT, tp, function(a, b) {
this.checkPropertyEquality('length');

@@ -258,3 +256,3 @@

EQ.add('object', 'array-buffer', function(a, b) {
EQ.add(t.OBJECT, t.ARRAY_BUFFER, function(a, b) {
this.checkPropertyEquality('byteLength');

@@ -265,3 +263,3 @@

EQ.add('object', 'error', function(a, b) {
EQ.add(t.OBJECT, t.ERROR, function(a, b) {
this.checkPropertyEquality('name');

@@ -273,3 +271,3 @@ this.checkPropertyEquality('message');

EQ.add('object', 'buffer', function(a) {
EQ.add(t.OBJECT, t.BUFFER, function(a) {
this.checkPropertyEquality('length');

@@ -286,4 +284,4 @@

['map', 'set'].forEach(function(tp) {
EQ.add('object', tp, function(a, b) {
[t.MAP, t.SET, t.WEAK_MAP, t.WEAK_SET].forEach(function(tp) {
EQ.add(t.OBJECT, tp, function(a, b) {
this._meet.push([a, b]);

@@ -290,0 +288,0 @@

{
"name": "should-equal",
"version": "1.0.0",
"version": "1.0.1",
"description": "Deep comparison of 2 instances for should.js",

@@ -31,6 +31,7 @@ "main": "cjs/should-equal.js",

"devDependencies": {
"eslint": "^2.0.0",
"eslint": "^3.0.0",
"eslint-config-shouldjs": "^1.0.2",
"mocha": "latest",
"mocha-better-spec-reporter": "latest",
"rollup": "^0.26.3"
"rollup": "0.34.7"
},

@@ -37,0 +38,0 @@ "dependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc