Skip to content

Commit

Permalink
Agrego autoTypeCast
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoefe committed Nov 1, 2016
1 parent 84d1d62 commit 7c953b4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion lib/discrepances.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit 7c953b4

Please sign in to comment.