Skip to content

Type Editor


Type Editor / @type-editor/changeset / types/TokenEncoder / TokenEncoder

Interface: TokenEncoder<T>

Defined in: types/TokenEncoder.ts:14

A token encoder can be passed when creating a ChangeSet in order to influence the way the library runs its diffing algorithm. The encoder determines how document tokens (such as nodes and characters) are encoded and compared.

Note that both the encoding and the comparison may run a lot, and doing non-trivial work in these functions could impact performance.

Type Parameters

Type Parameter
T

Methods

compareTokens()

ts
compareTokens(a, b): boolean;

Defined in: types/TokenEncoder.ts:51

Compare the given tokens. Should return true when they count as equal.

Parameters

ParameterTypeDescription
aTThe first token to compare.
bTThe second token to compare.

Returns

boolean

True if the tokens are equal, false otherwise.


encodeCharacter()

ts
encodeCharacter(char, marks): T;

Defined in: types/TokenEncoder.ts:23

Encode a given character, with the given marks applied.

Parameters

ParameterTypeDescription
charnumberThe character code to encode.
marksreadonly Mark[]The marks applied to the character.

Returns

T

The encoded representation of the character.


encodeNodeEnd()

ts
encodeNodeEnd(node): T;

Defined in: types/TokenEncoder.ts:41

Encode the end token for the given node. It is valid to encode every end token in the same way.

Parameters

ParameterTypeDescription
nodeNode_2The node to encode the end token for.

Returns

T

The encoded representation of the node end.


encodeNodeStart()

ts
encodeNodeStart(node): T;

Defined in: types/TokenEncoder.ts:32

Encode the start of a node or, if this is a leaf node, the entire node.

Parameters

ParameterTypeDescription
nodeNode_2The node to encode.

Returns

T

The encoded representation of the node start.