From 7c953b4123637dc258c6b775265a9854241c2f8f Mon Sep 17 00:00:00 2001 From: "Diego F.(EW7)" Date: Tue, 1 Nov 2016 14:33:52 -0300 Subject: [PATCH] Agrego autoTypeCast --- .eslintrc.yml | 2 +- lib/discrepances.js | 11 ++++++++++- test/test.js | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index bc0938f..b9e256f 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -44,7 +44,7 @@ rules: # Best Practices accessor-pairs: 2 block-scoped-var: 0 - complexity: [2, 14] + complexity: [2, 15] consistent-return: 0 curly: 0 default-case: 0 diff --git a/lib/discrepances.js b/lib/discrepances.js index b0bd1af..8691959 100644 --- a/lib/discrepances.js +++ b/lib/discrepances.js @@ -158,9 +158,18 @@ function isSimpleValue(classType) { return ! classType.match(/^(array|object|regexp)$/i); } +var defaultOpts = { + unordered:true, + duckTyping:false, + autoTypeCast:false +}; + discrepances = function discrepances(a, b, opts){ - opts = changing({unordered:true, duckTyping:false}, opts||{}); + opts = changing(defaultOpts, opts||{}); if(a === b){ return null; } + /*eslint-disable eqeqeq */ + if(opts.autoTypeCast && a == b){ return null; } + /*eslint-enable eqeqeq */ var typeA = getType(a); var typeB = getType(b); if(typeA === typeB) { diff --git a/test/test.js b/test/test.js index a77d5d2..6769457 100644 --- a/test/test.js +++ b/test/test.js @@ -105,6 +105,8 @@ describe("discrepances", function(){ opts:{unordered:false} }, {a: new Example({uno:1}) , b: {uno:1} , expect: null, opts:{duckTyping:true} }, + {a: 7 , b: "7" , expect: null, opts:{autoTypeCast:true} }, + {a: 76 , b: "76" , expect: discrepances(76, "76"), }, ]; // esto es para evitar que values:[] tenga fechas distintas a 'a' y 'b' var dateFixtures = [