Skip to content

Commit d86f613

Browse files
committed
fix: add type for PathProp and comment
1 parent ff5f4de commit d86f613

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export interface OperationTest extends OperationBase {
4949
value: any;
5050
}
5151

52+
export type PathProp = 'path' | 'from';
53+
5254
export type Operation =
5355
| OperationAdd
5456
| OperationRemove
@@ -57,7 +59,12 @@ export type Operation =
5759
| OperationMove
5860
| OperationTest;
5961

60-
const shiftIndices = (acceptedOp: Operation, proposedOps: Operation[], isAdd = false, pathProp = 'path'): void => {
62+
const shiftIndices = (
63+
acceptedOp: Operation,
64+
proposedOps: Operation[],
65+
isAdd = false,
66+
pathProp: PathProp = 'path',
67+
): void => {
6168
const lastSlash = acceptedOp[pathProp].lastIndexOf('/');
6269

6370
if (lastSlash === -1) return;
@@ -71,6 +78,8 @@ const shiftIndices = (acceptedOp: Operation, proposedOps: Operation[], isAdd = f
7178
const pathOfSameArray = proposedOp.path.indexOf(arrayPath) === 0;
7279

7380
if (pathOfSameArray) {
81+
// Does not use `pathProp` on the proposedOp since we need to deal with
82+
// both path types on the proposedOp anyway. See below it deals with `from`.
7483
proposedOp.path = replacePathIndices(proposedOp.path, arrayPath, index, isAdd);
7584
}
7685

@@ -92,7 +101,7 @@ const removeOperations = (
92101
proposedOps: Operation[],
93102
options: Options,
94103
skipWhitelist = false,
95-
pathProp = 'path',
104+
pathProp: PathProp = 'path',
96105
): void => {
97106
const {acceptedWinsOnEqualPath} = options;
98107
let currentIndex = 0;

0 commit comments

Comments
 (0)