interface StringZilla API
InterfaceStringZillaThe StringZilla bindings, the default export of stringzilla.39
*× 2Searches for a short buffer in a long one, zero-copy.
find(haystack: Buffer, needle: Buffer): bigint Parameters
haystackBuffer | Buffer to search in | |
|---|---|---|
needleBuffer | Buffer to search for |
Returns
Index of needle in haystack, or -1n if not found
find*× 2Searches for the last occurrence of a short buffer in a long one, zero-copy.
findLast(haystack: Buffer, needle: Buffer): bigint Parameters
haystackBuffer | Buffer to search in | |
|---|---|---|
needleBuffer | Buffer to search for |
Returns
Index of last needle in haystack, or -1n if not found
find*× 2Finds the first occurrence of a specific byte value, zero-copy.
findByte(haystack: Buffer, byte: number): bigint Parameters
haystackBuffer | Buffer to search in | |
|---|---|---|
bytenumber | Byte value to search for (0-255) |
Returns
Index of byte in haystack, or -1n if not found
findLast*× 2Finds the last occurrence of a specific byte value, zero-copy.
findLastByte(haystack: Buffer, byte: number): bigint Parameters
haystackBuffer | Buffer to search in | |
|---|---|---|
bytenumber | Byte value to search for (0-255) |
Returns
Index of last byte in haystack, or -1n if not found
findByte*× 2Finds the first occurrence of any byte from a set, zero-copy.
findByteFrom(haystack: Buffer, charset: Buffer): bigint Parameters
haystackBuffer | Buffer to search in | |
|---|---|---|
charsetBuffer | Buffer containing allowed byte values |
Returns
Index of first matching byte in haystack, or -1n if not found
findLastByte*× 2Finds the last occurrence of any byte from a set, zero-copy.
findLastByteFrom(haystack: Buffer, charset: Buffer): bigint Parameters
haystackBuffer | Buffer to search in | |
|---|---|---|
charsetBuffer | Buffer containing allowed byte values |
Returns
Index of last matching byte in haystack, or -1n if not found
*× 2Counts occurrences of a buffer in a larger buffer, zero-copy.
count(haystack: Buffer, needle: Buffer, overlap?: boolean): bigint Parameters
haystackBuffer | Buffer to search in | |
|---|---|---|
needleBuffer | Buffer to search for | |
overlapboolean | Whether to count overlapping matches |
Returns
Number of matches found; an empty needle matches
haystack.length + 1 times*× 2Computes hash of a buffer using StringZilla's fast hash algorithm, zero-copy.
hash(buffer: Buffer, seed?: number | bigint): bigint Parameters
bufferBuffer | Buffer to hash | |
|---|---|---|
seednumber | bigint | Optional seed for hash, defaulting to 0 |
Returns
64-bit hash value
*× 2Computes SHA-256 cryptographic hash of a buffer, zero-copy.
sha256(buffer: Buffer): Buffer Parameters
bufferBuffer | Buffer to hash |
|---|
Returns
32-byte SHA-256 digest
*× 2Compares two buffers for equality, zero-copy.
equal(first: Buffer, second: Buffer): boolean Parameters
firstBuffer | First buffer to compare | |
|---|---|---|
secondBuffer | Second buffer to compare |
Returns
True if buffers are equal, false otherwise
*× 2Compares two buffers lexicographically, zero-copy.
compare(first: Buffer, second: Buffer): number Parameters
firstBuffer | First buffer to compare | |
|---|---|---|
secondBuffer | Second buffer to compare |
Returns
-1 if first < second, 0 if equal, 1 if first > second
byte*× 2Computes the sum of all byte values in a buffer, zero-copy.
byteSum(buffer: Buffer): bigint Parameters
bufferBuffer | Buffer to sum |
|---|
Returns
Sum of all byte values
utf8Uncased*× 2Applies full Unicode case folding to a UTF-8 buffer.
utf8UncasedFold(buffer: Buffer, validate?: boolean): Buffer Parameters
bufferBuffer | UTF-8 encoded input | |
|---|---|---|
validateboolean | If true, validates UTF-8 and throws on invalid input |
Returns
Case-folded UTF-8 bytes, possibly longer than the input due to expansions
utf8Uncased*× 2Finds the first occurrence of needle in haystack under full Unicode case folding.
utf8UncasedFind(
haystack: Buffer,
needle: Buffer,
validate?: boolean,
): FindResult Parameters
haystackBuffer | UTF-8 encoded haystack | |
|---|---|---|
needleBuffer | UTF-8 encoded needle | |
validateboolean | If true, validates UTF-8 and throws on invalid input |
Returns
Object with the byte
index and matched byte length; index is -1n if not foundutf8*× 2Counts the Unicode codepoints in a UTF-8 buffer.
utf8Count(buffer: Buffer): bigint JavaScript strings are UTF-16, so String.prototype.length counts code units and
disagrees with this for anything outside the Basic Multilingual Plane.
Parameters
bufferBuffer | UTF-8 encoded input |
|---|
Returns
Number of codepoints
utf8*× 2Resolves a codepoint index to a byte offset in a UTF-8 buffer.
utf8Seek(buffer: Buffer, index: number | bigint): bigint Every offset the other exports return is a byte offset, so this is the bridge between those and codepoint-indexed positions.
Parameters
bufferBuffer | UTF-8 encoded input | |
|---|---|---|
indexnumber | bigint | Zero-based codepoint index |
Returns
Byte offset of that codepoint, or -1n if the buffer holds fewer
utf8*× 2Normalizes a UTF-8 buffer into the requested Unicode normal form.
utf8Norm(
buffer: Buffer,
form: Utf8NormalFormValue,
validate?: boolean,
): Buffer Parameters
bufferBuffer | UTF-8 encoded input | |
|---|---|---|
formUtf8NormalFormValue | One of the Utf8NormalForm constants | |
validateboolean | If true, validates UTF-8 and throws on invalid input |
Returns
Normalized UTF-8 bytes
utf8Find*× 2Finds the first byte violating the requested Unicode normal form.
utf8FindDenormalized(
buffer: Buffer,
form: Utf8NormalFormValue,
): bigint Parameters
bufferBuffer | UTF-8 encoded input | |
|---|---|---|
formUtf8NormalFormValue | One of the Utf8NormalForm constants |
Returns
Byte index of the first violation, or -1n if already normalized
HasherStateful hasher class for streaming hash computation.
Sha256Stateful SHA-256 hasher class for streaming hash computation.
DeviceThe CPU or a GPU, whose capabilities it reports; every call dispatches over the CPU's.
CapabilityLowercase capability names, like haswell, neon or cuda, mapped to their BigInt bits, and the cpus, gpus and any groups to theirs.
readonly Capability: Readonly<Record<CapabilityName, bigint>> Utf8UncasedNeedleUncased UTF-8 needle prepared once, over its own copy of the bytes, for repeated searches.
Utf8UncasedNeedle: Utf8UncasedNeedleConstructor Construct with new, then call findIn(haystack, validate?).
Utf8NormalFormUnicode normalization form constants for utf8Norm and utf8FindDenormalized.
readonly Utf8NormalForm: { readonly NFD: 0; readonly NFC: 1; readonly NFKD: 2; readonly NFKC: 3 } Utf8WordbreaksIterator over TR29 word segments as zero-copy subarray views of the buffer it keeps alive: for (const word of new sz.Utf8Wordbreaks(buffer, validate?)) ...
Utf8Wordbreaks: Utf8SegmentsConstructor Utf8GraphemesIterator over TR29 grapheme clusters, including multi-codepoint ZWJ emoji.
Utf8Graphemes: Utf8SegmentsConstructor Utf8SentencesIterator over TR29 sentence segments.
Utf8Sentences: Utf8SegmentsConstructor Utf8LinebreaksIterator over UAX14 line-break opportunities.
Utf8Linebreaks: Utf8SegmentsConstructor StringZillaThe StringZilla bindings, the default export of stringzilla.
interface StringZilla HasherStateful hasher class for streaming hash computation.
Sha256Stateful SHA-256 hasher class for streaming hash computation.
DeviceThe CPU or a GPU, whose capabilities it reports; every call dispatches over the CPU's.
CapabilityLowercase capability names, like haswell, neon or cuda, mapped to their BigInt bits, and the cpus, gpus and any groups to theirs.
readonly Capability: Readonly<Record<CapabilityName, bigint>> Utf8UncasedNeedleUncased UTF-8 needle prepared once, over its own copy of the bytes, for repeated searches.
Utf8UncasedNeedle: Utf8UncasedNeedleConstructor Construct with new, then call findIn(haystack, validate?).
Utf8NormalFormUnicode normalization form constants for utf8Norm and utf8FindDenormalized.
readonly Utf8NormalForm: { readonly NFD: 0; readonly NFC: 1; readonly NFKD: 2; readonly NFKC: 3 } Utf8WordbreaksIterator over TR29 word segments as zero-copy subarray views of the buffer it keeps alive: for (const word of new sz.Utf8Wordbreaks(buffer, validate?)) ...
Utf8Wordbreaks: Utf8SegmentsConstructor Utf8GraphemesIterator over TR29 grapheme clusters, including multi-codepoint ZWJ emoji.
Utf8Graphemes: Utf8SegmentsConstructor Utf8SentencesIterator over TR29 sentence segments.
Utf8Sentences: Utf8SegmentsConstructor Utf8LinebreaksIterator over UAX14 line-break opportunities.
Utf8Linebreaks: Utf8SegmentsConstructor