Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (keywordValue.index !== undefined) {
matchedResultArrayIndex = keywordValue.index === "-" ? resultArray.length - 1 : keywordValue.index;
}
// Handle $match.query
else if (keywordValue.query !== undefined) {
// Try to find a matching item in the result
const path = jsonpath.paths(resultArray, keywordValue.query)[0];
matchedResultArrayIndex = path !== undefined ? path[1] as number : undefined;
}
// Handle $match.path
else if (keywordValue.path !== undefined) {
// Try to find a matching item in the result
if (jsonPtr.get(resultArray, keywordValue.path) !== undefined) {
[matchedResultArrayIndex] = jsonPtr.decodePointer(keywordValue.path)[0];
}
}
// Ignore the item if no match found
if (matchedResultArrayIndex === undefined || resultArray[matchedResultArrayIndex] === undefined) {
return {resultArray, resultArrayIndex};
}
// Process result array item
const result = this._processor.processArrayItem(keywordValue.value, sourceArray, sourceArrayIndex, resultArray, matchedResultArrayIndex, target);
// Check if an array item has been inserted or removed below or at the current array item
if (matchedResultArrayIndex <= resultArrayIndex) {
resultArrayIndex += result.resultArrayIndex - matchedResultArrayIndex;
}