Skip to content

Commit

Permalink
v 0.2.0 actualizo versiones
Browse files Browse the repository at this point in the history
Mejoro cómo muestra las diferencias de texto
  • Loading branch information
emilioplatzer committed Aug 28, 2017
1 parent f89990c commit c2be6c4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
29 changes: 14 additions & 15 deletions lib/discrepances.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,22 @@ function getClassOnlyForSomeOfBuiltIns(variable, opts) {
throw new Error('undetected class type:' + typeof variable);
}

function timeStr(dt) { return datetime(dt).toYmdHmsM().substr(11); }
function timeStr(dt) { return datetime.ms(dt).toYmdHmsM().substr(11); }

function compareStrings(a,b) {
var pos=-1, i, j;
for(i=0; i<Math.min(a.length,b.length); ++i) {
if(a[i] !== b[i]) {
pos = i;
break;
}
}
for(j=b.length-1, i=a.length-1; i>=0; --j,--i) {
if(a[i] !== b[j]) { break; }
}
return {
differences:[a.substring(pos, i+2), b.substring(pos, j+2), {pos:pos}],
var pos=0;
var rPos=0;
while(pos<Math.min(a.length,b.length) && a[pos]==b[pos]) pos++;
while(rPos>pos-Math.min(a.length,b.length) && a[a.length+rPos-1] == b[b.length+rPos-1]) rPos--;
var answer={
differences:[a.substring(pos, a.length+rPos), b.substring(pos, b.length+rPos), {pos:pos}],
values:[a,b]
};
if(rPos){
answer.differences[2].rPos = rPos;
}
return answer;
}

function objectWithProp(key, val) {
Expand Down Expand Up @@ -122,10 +121,10 @@ function compareDates(a, b) {
var timesDiffer = timeStr(a) !== timeStr(b);
var msDiff = a.getTime()-b.getTime();
var showTimeDiff = Math.abs(msDiff) <= 359999000; // 99 * 60 * 60 * 1000 + 59 * 60 * 1000 + 59 * 1000;
if(datetime(a).toYmd() !== datetime(b).toYmd()) {
if(datetime.ms(a).toYmd() !== datetime.ms(b).toYmd()) {
// aas[0]=ymd, aas[1]=hmsm
var aas = datetime(a).toYmdHmsM().split(' ');
var bbs = datetime(b).toYmdHmsM().split(' ');
var aas = datetime.ms(a).toYmdHmsM().split(' ');
var bbs = datetime.ms(b).toYmdHmsM().split(' ');
res.push(aas[0]);
if(timesDiffer) {
res.push(' ');
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "discrepances",
"description": "show discrepances in several flavors",
"version": "0.1.4",
"version": "0.2.0",
"author": "Codenautas <codenautas@googlegroups.com>",
"repository": "codenautas/discrepances",
"license": "MIT",
Expand All @@ -18,14 +18,14 @@
"main": "lib/discrepances.js",
"files": ["lib"],
"dependencies": {
"best-globals": "~0.9.3"
"best-globals": "~0.10.0"
},
"devDependencies": {
"body-parser": "~1.17.2",
"cookie-parser": "~1.4.3",
"expect.js": "~0.3.1",
"express": "~4.15.3",
"express-session": "~1.15.3",
"express": "~4.15.4",
"express-session": "~1.15.5",
"express-useragent": "~1.0.7",
"istanbul": "~0.4.5",
"karma": "~1.7.0",
Expand All @@ -39,11 +39,11 @@
"karma-phantomjs-launcher": "~1.0.4",
"karma-safari-launcher": "~1.0.0",
"istanbul-middleware": "~0.2.2",
"mocha": "~3.4.2",
"phantomjs-prebuilt": "~2.1.14",
"mocha": "~3.5.0",
"phantomjs-prebuilt": "~2.1.15",

"audit-copy": "~0.0.5",
"json4all": "~0.3.3",
"json4all": "~0.3.6",
"require-bro": "~0.1.5"
},
"engines": {
Expand Down
13 changes: 8 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,17 @@ describe("discrepances", function(){
},
{a:{x:1, y:2, z:[3]} , b:{x:1, y:2, z:[3]} , expect:null },
{a:"un string" , b:"un string" , expect:null },
{a:"un negro pez" , b:"un blanco pez" ,
expect:{differences: ['negro', 'blanco', {pos:3}], values:["un negro pez", "un blanco pez"]}
{a:"un gris pez" , b:"un blanco pez" ,
expect:{differences: ['gris', 'blanco', {pos:3, rPos:-4}], values:["un gris pez", "un blanco pez"]}
},
{a:"un pez negro" , b:"un pez blanco" ,
expect:{differences: ['negro', 'blanco', {pos:7}], values:["un pez negro", "un pez blanco"]}
{a:"un pez gris" , b:"un pez blanco" ,
expect:{differences: ['gris', 'blanco', {pos:7}], values:["un pez gris", "un pez blanco"]}
},
{a:"negro el ocho" , b:"rojo el ocho" ,
expect:{differences: ['negro', 'rojo' , {pos:0}], values:["negro el ocho", "rojo el ocho"]}
expect:{differences: ['negr', 'roj' , {pos:0, rPos:-9}], values:["negro el ocho", "rojo el ocho"]}
},
{a:'2017-12-23 13:40:00.000', b:'2017-12-23 13:40:00',
expect:{differences:[".000","",{pos:19}],values:["2017-12-23 13:40:00.000","2017-12-23 13:40:00"]}
},
{a:null , b:undefined , expect:{types:['null', 'undefined'], values:[null, undefined]} },
{a:{a:7, b:[]} , b:fechaActual , expect:{classes:['Object', 'Date']} },
Expand Down

0 comments on commit c2be6c4

Please sign in to comment.