Export isBinary and more types
This commit is contained in:
parent
8f1d2ca4b3
commit
7ee4fd8c72
1 changed files with 19 additions and 3 deletions
|
|
@ -5,12 +5,16 @@ import {
|
|||
SpanWithHistory as wasmSpanWithHistory,
|
||||
BuiltinTokenizer,
|
||||
reconcileWithHistory as wasmReconcileWithHistory,
|
||||
isBinary as wasmIsBinary,
|
||||
History,
|
||||
initSync,
|
||||
} from 'reconcile-text';
|
||||
|
||||
import wasmBytes from 'reconcile-text/reconcile_text_bg.wasm';
|
||||
|
||||
// Re-export types from the WASM module as these are part of our API
|
||||
export { History, BuiltinTokenizer };
|
||||
|
||||
/**
|
||||
* Represents a text document with associated cursor positions.
|
||||
*
|
||||
|
|
@ -87,15 +91,14 @@ export interface SpanWithHistory {
|
|||
* - "Character": Splits text into individual characters (fine-grained control)
|
||||
* - "Line": Splits text into lines (similar to git merge or diff3)
|
||||
*/
|
||||
export type Tokenizer = 'Line' | 'Word' | 'Character';
|
||||
const TOKENIZERS = ['Line', 'Word', 'Character'];
|
||||
|
||||
let isInitialised = false;
|
||||
|
||||
const UNSUPPORTED_TOKENIZER_ERROR = `Unsupported tokenizer. Only ${TOKENIZERS.join(
|
||||
', '
|
||||
)} are supported.`;
|
||||
|
||||
let isInitialised = false;
|
||||
|
||||
/**
|
||||
* Merges three versions of text using intelligent conflict resolution.
|
||||
*
|
||||
|
|
@ -204,6 +207,19 @@ export function reconcileWithHistory(
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check (using heuristics) if the given data is binary or text content.
|
||||
*
|
||||
* Only text inputs can be reconciled using the library's functions.
|
||||
*
|
||||
* @param data - The data to check for binary content. This should be a Uint8Array.
|
||||
* @returns True if the data is likely binary, false if it is likely text.
|
||||
*/
|
||||
export function isBinary(data: Uint8Array): boolean {
|
||||
init();
|
||||
return wasmIsBinary(data);
|
||||
}
|
||||
|
||||
function init() {
|
||||
if (isInitialised) {
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue