Skip to content
Closed
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
6 changes: 3 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export function arrayIntersection<T>(first: T[], second: T[]): T[] {
return first.filter(item => secondSet.has(item));
}

export function keyBy<T>(arr: T[], getKey: (item: T) => any): Record<string, T> {
export function keyBy<T>(arr: T[], getKey: (item: T, index: number) => any): Record<string, T> {
const result: Record<string, T> = {};
for (const item of arr) {
result[String(getKey(item))] = item;
for (const [index, item] of Object.entries(arr)) {
result[String(getKey(item, Number(index)))] = item;
}
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/jsonDiff.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { arrayDifference as difference, arrayIntersection as intersection, keyBy, splitJSONPath } from './helpers.js';

type FunctionKey = (obj: any, shouldReturnKeyName?: boolean) => any;
type FunctionKey = (obj: any, index: number) => any;
type EmbeddedObjKeysType = Record<string, string | FunctionKey>;
type EmbeddedObjKeysMapType = Map<string | RegExp, string | FunctionKey>;
enum Operation {
Expand Down