Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 12 additions & 28 deletions 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
Expand Up @@ -101,7 +101,7 @@
"axios": "^1.7.7",
"chalk": "^5.3.0",
"debug": "^4.3.7",
"jsonpathly": "^2.0.2",
"jsonpathly": "^3.0.0",
"mergician": "^2.0.2",
"open": "^10.1.0"
}
Expand Down
18 changes: 12 additions & 6 deletions src/core/overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,7 @@ export class Overlay {

// Take last element from path (which is the thing to act
// upon)
let thingToActUpon: number | string | undefined = explodedPath.pop()
// The last element (e.g. '"price"]' or '0]') contains a final ']'
// so we need to remove it AND we need to parse the element to
// transform the string in either a string or a number
thingToActUpon =
thingToActUpon === undefined ? '$' : (thingToActUpon = JSON.parse(thingToActUpon.slice(0, -1)) as number | string)
const thingToActUpon: number | string = this.pathEntryToKey(explodedPath.pop())

// Reconstruct the stringified path expression targeting the parent
const parentPath: string = explodedPath.join('][')
Expand All @@ -117,6 +112,17 @@ export class Overlay {
return action.description ? `Action '${action.description}'` : 'Action'
}

// The last path entry (e.g. "'price']" or '0]') contains a final
// ']' so we need to remove it AND we need to replace single quotes
// to double quotes AND FINALLY parse the element to transform the
// string in either a string or a number.
private pathEntryToKey(pathEntry: string | undefined): number | string {
if (pathEntry === undefined) {
return '$'
}
return JSON.parse(pathEntry.slice(0, -1).replaceAll(/(^'|'$)/g, '"'))
}

private remove(parent: JSONSchema4Object, property_or_index: number | string): void {
if (Array.isArray(parent)) {
parent.splice(property_or_index as number, 1)
Expand Down
Loading