( base: JSONValue | PartialJSONValue, diff: IDiffEntry[] | null, )
| 41 | diff: IDiffEntry[] | null, |
| 42 | ): JSONValue; |
| 43 | export function patch( |
| 44 | base: JSONValue | PartialJSONValue, |
| 45 | diff: IDiffEntry[] | null, |
| 46 | ): JSONValue { |
| 47 | if (typeof base === 'string') { |
| 48 | return patchString(base, diff as IDiffArrayEntry[], 0, false).remote; |
| 49 | } else if (Array.isArray(base)) { |
| 50 | const baseCopy = JSONExt.deepCopy(base) as JSONArray; |
| 51 | return patchSequence(baseCopy, diff as IDiffArrayEntry[]); |
| 52 | } else if (typeof base === 'number' || typeof base === 'boolean') { |
| 53 | throw new TypeError('Cannot patch an atomic type: ' + typeof base); |
| 54 | } else if (base === null) { |
| 55 | throw new TypeError('Cannot patch a null base!'); |
| 56 | } else { |
| 57 | const baseCopy = JSONExt.deepCopy(base) as JSONObject; |
| 58 | return patchObject(baseCopy, diff as IDiffObjectEntry[]); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Patch an array according to the diff. |
no test coverage detected