UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

48 lines (47 loc) 1.3 kB
import * as str from './str'; export declare const enum LINE_PATCH_OP_TYPE { /** * The whole line is deleted. Delete the current src line and advance the src * counter. */ DEL = -1, /** * Lines are equal in src and dst. Keep the line in src and advance, both, src * and dst counters. */ EQL = 0, /** * The whole line is inserted. Insert the current dst line and advance the dst * counter. */ INS = 1, /** * The line is modified. Execute inner diff between the current src and dst * lines. Keep the line in src and advance the src and dst counters. */ MIX = 2 } export type LinePatchOp = [ type: LINE_PATCH_OP_TYPE, /** * Assignment of this operation to the line in the `src` array. */ src: number, /** * Assignment of this operation to the line in the `dst` array. */ dst: number, /** * Character-level patch. */ patch: str.Patch ]; export type LinePatch = LinePatchOp[]; /** * Aggregate character-by-character patch into a line-by-line patch. * * @param patch Character-level patch * @returns Line-level patch */ export declare const agg: (patch: str.Patch) => str.Patch[]; export declare const diff: (src: string[], dst: string[]) => LinePatch;