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 | 1x 1x 14x 14x 14x 14x 14x 14x 14x 14x | import {isValidIndex} from '@jsonjoy.com/json-pointer'; export function replaceIndices(path: string, arrayPath: string, index: string, incUp: boolean): string { const remainder = path.substr(arrayPath.length); let slashIndex = remainder.indexOf('/'); if (slashIndex === -1) slashIndex = remainder.length; const oldIndex = remainder.substr(0, slashIndex); const rest = remainder.substr(slashIndex); const isOldBigger = incUp ? oldIndex >= index : oldIndex > index; const shouldChangeIndex = isValidIndex(oldIndex) && isOldBigger; return shouldChangeIndex ? `${arrayPath}${~~oldIndex + (incUp ? 1 : -1)}${rest}` : path; } |