MCPcopy
hub / github.com/jupyter/nbdime / patch

Function patch

packages/nbdime/src/patch/generic.ts:43–60  ·  view source on GitHub ↗
(
  base: JSONValue | PartialJSONValue,
  diff: IDiffEntry[] | null,
)

Source from the content-addressed store, hash-verified

41 diff: IDiffEntry[] | null,
42): JSONValue;
43export 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.

Callers 6

patching.spec.tsFile · 0.90
applyDecisionsFunction · 0.90
constructorFunction · 0.90
patchSequenceFunction · 0.70
patchObjectFunction · 0.70

Calls 4

patchStringFunction · 0.90
patchSequenceFunction · 0.85
patchObjectFunction · 0.85
isArrayMethod · 0.80

Tested by

no test coverage detected