Expose to JS

This commit is contained in:
Andras Schmelczer 2025-10-26 21:44:43 +00:00
parent 450eaaff05
commit 1b46e5d237
9 changed files with 95 additions and 17 deletions

View file

@ -5,6 +5,7 @@ import {
SpanWithHistory as wasmSpanWithHistory,
reconcileWithHistory as wasmReconcileWithHistory,
isBinary as wasmIsBinary,
getCompactDiff as wasmGetCompactDiff,
initSync,
} from 'reconcile-text';
@ -179,6 +180,26 @@ export function reconcile(
return jsResult;
}
export function getCompactDiff(
original: string,
changed: string | TextWithOptionalCursors,
tokenizer: BuiltinTokenizer = 'Word'
): string {
init();
if (!BUILTIN_TOKENIZERS.includes(tokenizer)) {
throw new Error(UNSUPPORTED_TOKENIZER_ERROR);
}
const changedWasm = toWasmTextWithCursors(changed);
const result = wasmGetCompactDiff(original, changedWasm, tokenizer);
changedWasm.free();
return result;
}
/**
* Merges three versions of text and returns detailed provenance information.
*