Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | 1x 1x 1x 1x 1x 35x 35x 35x 35x 35x 35x 34x 15x 15x 15x 6x 6x 6x 28x | import {OpRemove, type Op} from '../../json-patch/op'; import {isRoot, isValidIndex, formatJsonPointer, isPathEqual} from '@jsonjoy.com/json-pointer'; import {lowerArrayPath} from './util'; import type {Operation} from '../../json-patch/types'; import {operationToOp} from '../../json-patch/codec/json'; export const xRemove = (add: OpRemove, op: Op): null | Op => { Iif (isRoot(add.path)) return null; Iif (isRoot(op.path)) return op; const lastIndex = add.path.length - 1; const lastStep = add.path[lastIndex]; const isLastStepNumberLike = isValidIndex(lastStep); if (op instanceof OpRemove && isPathEqual(add.path, op.path) && isLastStepNumberLike) return null; if (isLastStepNumberLike) { const newPath = lowerArrayPath(add.path, op.path); const newFrom = op.from ? lowerArrayPath(add.path, op.from) : undefined; if (newPath || newFrom) { const operation: Operation = { ...op.toJson(), path: newPath ? formatJsonPointer(newPath) : op.path, }; if (newFrom) (operation as any).from = newFrom; return operationToOp(operation, {}); } } return op; }; |