Skip to content

Commit

Permalink
1.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
gfiorentino committed Mar 7, 2021
1 parent bc73c02 commit 6e0633c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 44 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "piffero",
"version": "1.0.10",
"version": "1.0.11",
"description": "",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
34 changes: 14 additions & 20 deletions src/handler/singlestephandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ export class SingleStepHandler {

stopHandler() {
this.status.verified = false;

if (!this.status.isBulkResponse) {
this.status.recording = false;
this.status.end = true; // temporaneo
this.status.recording = false;
this.status.end = true; // temporaneo
}
}

Expand Down Expand Up @@ -71,10 +71,7 @@ export class SingleStepHandler {
} else if (this.status.isMatching && this.status.depthCounter === 2) {
this.status.currentIndex++;
// se lavoriamo con un indice
if (
this.status.path.range &&
this.status.checkIndex()
) {
if (this.status.path.range && this.status.checkIndex()) {
if (this.isLast) {
this.push(`{${node}:`);
}
Expand Down Expand Up @@ -161,10 +158,7 @@ export class SingleStepHandler {
this.status.temp = "";
} else if (this.status.isMatching && this.status.depthCounter === 2) {
this.status.currentIndex++;
if (
this.status.path.range &&
this.status.checkIndex()
) {
if (this.status.path.range && this.status.checkIndex()) {
if (this.isLast) {
this.push(`[`);
}
Expand Down Expand Up @@ -205,10 +199,10 @@ export class SingleStepHandler {
}
}
this.status.depthCounter--;
// if (this.status.depthCounter < 3) {
// this.status.currentIndex=0;
// }
this.status.last = "closearray";
// if (this.status.depthCounter < 3) {
// this.status.currentIndex=0;
// }
this.status.last = "closearray";
}

key(node: any) {
Expand Down Expand Up @@ -263,9 +257,9 @@ export class SingleStepHandler {
) {
this.status.currentIndex++;
if (this.status.checkIndex() && !this.status.close) {
console.log(this.status.path.range ,this.status.currentIndex);
if(this.status.currentIndex > this.status.path.range.start) {
this.push(',');
console.log(this.status.path.range, this.status.currentIndex);
if (this.status.currentIndex > this.status.path.range.start) {
this.push(",");
}
this.push(`${node}`);
this.stopHandler();
Expand All @@ -277,8 +271,8 @@ export class SingleStepHandler {
this.push(`,${node}`);
} else {
this.push(`${node}`);
}
if (this.status.depthCounter === 1) {
}
if (this.status.depthCounter === 1) {
this.stopHandler();
this.status._needComma = true;
}
Expand Down
28 changes: 14 additions & 14 deletions src/jsonpath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,20 @@ export class JSONPath {
splittedIndexes.forEach((element) => indexes.push(Number(element)));
} else {
const [start, end, step] = splitted[1].split(":");
// TODO: refactoring
range = {
start: Number(start),
end: end ? Number(end) : 0,
step: step ? Number(step) : 0,
};
let _start = range.start;
let _end = range.end;
let _step= step ? Number(step) : 1;
indexes.push(_start);
for (let i = _start + _step; i < _end; i += _step){
indexes.push(i);
}
// TODO: refactoring
range = {
start: Number(start),
end: end ? Number(end) : 0,
step: step ? Number(step) : 0,
};

let _start = range.start;
let _end = range.end;
let _step = step ? Number(step) : 1;
indexes.push(_start);
for (let i = _start + _step; i < _end; i += _step) {
indexes.push(i);
}
}
}
indexes;
Expand Down
16 changes: 8 additions & 8 deletions src/pifferostatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ export class PifferoStatus {
}
}

set last (_last) {
// if (this.recording) {
this._last = _last;
// }
set last(_last) {
// if (this.recording) {
this._last = _last;
// }
}

get last() {
return this._last ;
return this._last;
}

get needComma(): boolean {
Expand All @@ -96,7 +96,7 @@ export class PifferoStatus {
checkIndex() {
const range = this.path.range;
if (this.path.indexes && this.path.indexes.length > 0) {
return this.path.indexes.indexOf(this.currentIndex) >= 0 ;
return this.path.indexes.indexOf(this.currentIndex) >= 0;
}

let start = 0;
Expand All @@ -106,7 +106,7 @@ export class PifferoStatus {
if (range.start >= 0) {
start = range.start;
}
if ( this.currentIndex < start ) {
if (this.currentIndex < start) {
return false;
}
if (range.end > 0) {
Expand All @@ -115,7 +115,7 @@ export class PifferoStatus {
if (range.step > 0) {
step = range.step;
}
if ( this.currentIndex > end) {
if (this.currentIndex > end) {
return false;
}
return Number.isInteger((this.currentIndex - start) / step);
Expand Down

0 comments on commit 6e0633c

Please sign in to comment.