Skip to main content
Version: v0.0.3

Function: splitWithOffsets()

splitWithOffsets(s, sep, base): Part[]

Split a string on a single-character separator, carrying each piece's absolute byte offset. Empty pieces are retained (the caller decides whether to drop the leading empty that a leading separator produces).

Parameters

s

string

The string to split.

sep

string

The single-character separator.

base

number

The absolute offset of s[0] in the original message.

Returns

Part[]

The pieces with their absolute offsets.

Example

splitWithOffsets("\x1cD7123", "\x1c", 56);
// [{ text: "", offset: 56 }, { text: "D7123", offset: 57 }]