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,
|
SpanWithHistory as wasmSpanWithHistory,
|
||||||
BuiltinTokenizer,
|
BuiltinTokenizer,
|
||||||
reconcileWithHistory as wasmReconcileWithHistory,
|
reconcileWithHistory as wasmReconcileWithHistory,
|
||||||
|
isBinary as wasmIsBinary,
|
||||||
History,
|
History,
|
||||||
initSync,
|
initSync,
|
||||||
} from 'reconcile-text';
|
} from 'reconcile-text';
|
||||||
|
|
||||||
import wasmBytes from 'reconcile-text/reconcile_text_bg.wasm';
|
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.
|
* Represents a text document with associated cursor positions.
|
||||||
*
|
*
|
||||||
|
|
@ -87,15 +91,14 @@ export interface SpanWithHistory {
|
||||||
* - "Character": Splits text into individual characters (fine-grained control)
|
* - "Character": Splits text into individual characters (fine-grained control)
|
||||||
* - "Line": Splits text into lines (similar to git merge or diff3)
|
* - "Line": Splits text into lines (similar to git merge or diff3)
|
||||||
*/
|
*/
|
||||||
export type Tokenizer = 'Line' | 'Word' | 'Character';
|
|
||||||
const TOKENIZERS = ['Line', 'Word', 'Character'];
|
const TOKENIZERS = ['Line', 'Word', 'Character'];
|
||||||
|
|
||||||
let isInitialised = false;
|
|
||||||
|
|
||||||
const UNSUPPORTED_TOKENIZER_ERROR = `Unsupported tokenizer. Only ${TOKENIZERS.join(
|
const UNSUPPORTED_TOKENIZER_ERROR = `Unsupported tokenizer. Only ${TOKENIZERS.join(
|
||||||
', '
|
', '
|
||||||
)} are supported.`;
|
)} are supported.`;
|
||||||
|
|
||||||
|
let isInitialised = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merges three versions of text using intelligent conflict resolution.
|
* 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() {
|
function init() {
|
||||||
if (isInitialised) {
|
if (isInitialised) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue