JavaScript · Types

Types

import { StringZilla } from 'stringzilla'; 6.0.0-rc.1 · 91a27bdd

API

InterfaceStringZillaThe StringZilla bindings, the default export of stringzilla.39
stringzilla.d.ts:184 ↗
interface StringZilla
*× 2Searches for a short buffer in a long one, zero-copy.
stringzilla.d.ts:192 ↗
find(haystack: Buffer, needle: Buffer): bigint

Parameters

haystackBufferBuffer to search in
needleBufferBuffer 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.
stringzilla.d.ts:201 ↗
findLast(haystack: Buffer, needle: Buffer): bigint

Parameters

haystackBufferBuffer to search in
needleBufferBuffer 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.
stringzilla.d.ts:210 ↗
findByte(haystack: Buffer, byte: number): bigint

Parameters

haystackBufferBuffer to search in
bytenumberByte 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.
stringzilla.d.ts:219 ↗
findLastByte(haystack: Buffer, byte: number): bigint

Parameters

haystackBufferBuffer to search in
bytenumberByte 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.
stringzilla.d.ts:228 ↗
findByteFrom(haystack: Buffer, charset: Buffer): bigint

Parameters

haystackBufferBuffer to search in
charsetBufferBuffer 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.
stringzilla.d.ts:237 ↗
findLastByteFrom(haystack: Buffer, charset: Buffer): bigint

Parameters

haystackBufferBuffer to search in
charsetBufferBuffer 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.
stringzilla.d.ts:247 ↗
count(haystack: Buffer, needle: Buffer, overlap?: boolean): bigint

Parameters

haystackBufferBuffer to search in
needleBufferBuffer to search for
overlapbooleanWhether 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.
stringzilla.d.ts:256 ↗
hash(buffer: Buffer, seed?: number | bigint): bigint

Parameters

bufferBufferBuffer to hash
seednumber | bigintOptional seed for hash, defaulting to 0

Returns

64-bit hash value
*× 2Computes SHA-256 cryptographic hash of a buffer, zero-copy.
stringzilla.d.ts:268 ↗
sha256(buffer: Buffer): Buffer

Parameters

bufferBufferBuffer to hash

Returns

32-byte SHA-256 digest
*× 2Compares two buffers for equality, zero-copy.
stringzilla.d.ts:281 ↗
equal(first: Buffer, second: Buffer): boolean

Parameters

firstBufferFirst buffer to compare
secondBufferSecond buffer to compare

Returns

True if buffers are equal, false otherwise
*× 2Compares two buffers lexicographically, zero-copy.
stringzilla.d.ts:290 ↗
compare(first: Buffer, second: Buffer): number

Parameters

firstBufferFirst buffer to compare
secondBufferSecond 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.
stringzilla.d.ts:298 ↗
byteSum(buffer: Buffer): bigint

Parameters

bufferBufferBuffer to sum

Returns

Sum of all byte values
utf8Uncased*× 2Applies full Unicode case folding to a UTF-8 buffer.
stringzilla.d.ts:314 ↗
utf8UncasedFold(buffer: Buffer, validate?: boolean): Buffer

Parameters

bufferBufferUTF-8 encoded input
validatebooleanIf 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.
stringzilla.d.ts:324 ↗
utf8UncasedFind(
    haystack: Buffer,
    needle: Buffer,
    validate?: boolean,
): FindResult

Parameters

haystackBufferUTF-8 encoded haystack
needleBufferUTF-8 encoded needle
validatebooleanIf true, validates UTF-8 and throws on invalid input

Returns

Object with the byte index and matched byte length; index is -1n if not found
utf8*× 2Counts the Unicode codepoints in a UTF-8 buffer.
stringzilla.d.ts:340 ↗
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

bufferBufferUTF-8 encoded input

Returns

Number of codepoints
utf8*× 2Resolves a codepoint index to a byte offset in a UTF-8 buffer.
stringzilla.d.ts:352 ↗
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

bufferBufferUTF-8 encoded input
indexnumber | bigintZero-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.
stringzilla.d.ts:365 ↗
utf8Norm(
    buffer: Buffer,
    form: Utf8NormalFormValue,
    validate?: boolean,
): Buffer

Parameters

bufferBufferUTF-8 encoded input
formUtf8NormalFormValueOne of the Utf8NormalForm constants
validatebooleanIf 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.
stringzilla.d.ts:374 ↗
utf8FindDenormalized(
    buffer: Buffer,
    form: Utf8NormalFormValue,
): bigint

Parameters

bufferBufferUTF-8 encoded input
formUtf8NormalFormValueOne of the Utf8NormalForm constants

Returns

Byte index of the first violation, or -1n if already normalized
HasherStateful hasher class for streaming hash computation.
stringzilla.d.ts:260 ↗
Hasher: HasherConstructor

Use this for hashing data that arrives in chunks.

Sha256Stateful SHA-256 hasher class for streaming hash computation.
stringzilla.d.ts:272 ↗
Sha256: Sha256Constructor

Use this for hashing data that arrives in chunks.

DeviceThe CPU or a GPU, whose capabilities it reports; every call dispatches over the CPU's.
stringzilla.d.ts:301 ↗
Device: DeviceConstructor
CapabilityLowercase capability names, like haswell, neon or cuda, mapped to their BigInt bits, and the cpus, gpus and any groups to theirs.
stringzilla.d.ts:305 ↗
readonly Capability: Readonly<Record<CapabilityName, bigint>>
Utf8UncasedNeedleUncased UTF-8 needle prepared once, over its own copy of the bytes, for repeated searches.
stringzilla.d.ts:329 ↗
Utf8UncasedNeedle: Utf8UncasedNeedleConstructor

Construct with new, then call findIn(haystack, validate?).

Utf8NormalFormUnicode normalization form constants for utf8Norm and utf8FindDenormalized.
stringzilla.d.ts:355 ↗
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?)) ...
stringzilla.d.ts:378 ↗
Utf8Wordbreaks: Utf8SegmentsConstructor
Utf8GraphemesIterator over TR29 grapheme clusters, including multi-codepoint ZWJ emoji.
stringzilla.d.ts:381 ↗
Utf8Graphemes: Utf8SegmentsConstructor
Utf8SentencesIterator over TR29 sentence segments.
stringzilla.d.ts:384 ↗
Utf8Sentences: Utf8SegmentsConstructor
Utf8LinebreaksIterator over UAX14 line-break opportunities.
stringzilla.d.ts:387 ↗
Utf8Linebreaks: Utf8SegmentsConstructor
StringZillaThe StringZilla bindings, the default export of stringzilla.
stringzilla.d.ts:184 ↗
interface StringZilla
HasherStateful hasher class for streaming hash computation.
stringzilla.d.ts:260 ↗
Hasher: HasherConstructor

Use this for hashing data that arrives in chunks.

Sha256Stateful SHA-256 hasher class for streaming hash computation.
stringzilla.d.ts:272 ↗
Sha256: Sha256Constructor

Use this for hashing data that arrives in chunks.

DeviceThe CPU or a GPU, whose capabilities it reports; every call dispatches over the CPU's.
stringzilla.d.ts:301 ↗
Device: DeviceConstructor
CapabilityLowercase capability names, like haswell, neon or cuda, mapped to their BigInt bits, and the cpus, gpus and any groups to theirs.
stringzilla.d.ts:305 ↗
readonly Capability: Readonly<Record<CapabilityName, bigint>>
Utf8UncasedNeedleUncased UTF-8 needle prepared once, over its own copy of the bytes, for repeated searches.
stringzilla.d.ts:329 ↗
Utf8UncasedNeedle: Utf8UncasedNeedleConstructor

Construct with new, then call findIn(haystack, validate?).

Utf8NormalFormUnicode normalization form constants for utf8Norm and utf8FindDenormalized.
stringzilla.d.ts:355 ↗
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?)) ...
stringzilla.d.ts:378 ↗
Utf8Wordbreaks: Utf8SegmentsConstructor
Utf8GraphemesIterator over TR29 grapheme clusters, including multi-codepoint ZWJ emoji.
stringzilla.d.ts:381 ↗
Utf8Graphemes: Utf8SegmentsConstructor
Utf8SentencesIterator over TR29 sentence segments.
stringzilla.d.ts:384 ↗
Utf8Sentences: Utf8SegmentsConstructor
Utf8LinebreaksIterator over UAX14 line-break opportunities.
stringzilla.d.ts:387 ↗
Utf8Linebreaks: Utf8SegmentsConstructor