better compare

This commit is contained in:
Matt Hill
2022-09-14 11:08:00 -06:00
parent bb731c62ad
commit 0044c5ac4f
2 changed files with 33 additions and 13 deletions

View File

@@ -43,6 +43,10 @@ export function applyOperation<T>(
doc.data = recursiveApply(doc.data, jsonPathToKeyArray(path), op, value)
}
export function jsonPathToKeyArray(path: string): string[] {
return path.split('/').slice(1)
}
function recursiveApply<T extends Record<string, any> | any[]>(
data: T,
path: readonly string[],
@@ -105,7 +109,3 @@ function recursiveApplyArray<T extends any[]>(
function isObject(val: any): val is Record<string, unknown> {
return typeof val === 'object' && val !== null && !Array.isArray(val)
}
function jsonPathToKeyArray(path: string): string[] {
return path.split('/').slice(1)
}