# Types

> StringZilla for JavaScript

`import { StringZilla } from 'stringzilla';`

## StringZilla

The StringZilla bindings, the default export of `stringzilla`.

```typescript
interface StringZilla
```

## *

Searches for a short buffer in a long one, zero-copy.

```typescript
find(haystack: Buffer, needle: Buffer): bigint
```

- `haystack`: Buffer to search in
- `needle`: Buffer to search for

## find*

Searches for the last occurrence of a short buffer in a long one, zero-copy.

```typescript
findLast(haystack: Buffer, needle: Buffer): bigint
```

- `haystack`: Buffer to search in
- `needle`: Buffer to search for

## find*

Finds the first occurrence of a specific byte value, zero-copy.

```typescript
findByte(haystack: Buffer, byte: number): bigint
```

- `haystack`: Buffer to search in
- `byte`: Byte value to search for (0-255)

## findLast*

Finds the last occurrence of a specific byte value, zero-copy.

```typescript
findLastByte(haystack: Buffer, byte: number): bigint
```

- `haystack`: Buffer to search in
- `byte`: Byte value to search for (0-255)

## findByte*

Finds the first occurrence of any byte from a set, zero-copy.

```typescript
findByteFrom(haystack: Buffer, charset: Buffer): bigint
```

- `haystack`: Buffer to search in
- `charset`: Buffer containing allowed byte values

## findLastByte*

Finds the last occurrence of any byte from a set, zero-copy.

```typescript
findLastByteFrom(haystack: Buffer, charset: Buffer): bigint
```

- `haystack`: Buffer to search in
- `charset`: Buffer containing allowed byte values

## *

Counts occurrences of a buffer in a larger buffer, zero-copy.

```typescript
count(haystack: Buffer, needle: Buffer, overlap?: boolean): bigint
```

- `haystack`: Buffer to search in
- `needle`: Buffer to search for
- `overlap`: Whether to count overlapping matches

## *

Computes hash of a buffer using StringZilla's fast hash algorithm, zero-copy.

```typescript
hash(buffer: Buffer, seed?: number | bigint): bigint
```

- `buffer`: Buffer to hash
- `seed`: Optional seed for hash, defaulting to 0

## *

Computes SHA-256 cryptographic hash of a buffer, zero-copy.

```typescript
sha256(buffer: Buffer): Buffer
```

- `buffer`: Buffer to hash

## *

Compares two buffers for equality, zero-copy.

```typescript
equal(first: Buffer, second: Buffer): boolean
```

- `first`: First buffer to compare
- `second`: Second buffer to compare

## *

Compares two buffers lexicographically, zero-copy.

```typescript
compare(first: Buffer, second: Buffer): number
```

- `first`: First buffer to compare
- `second`: Second buffer to compare

## byte*

Computes the sum of all byte values in a buffer, zero-copy.

```typescript
byteSum(buffer: Buffer): bigint
```

- `buffer`: Buffer to sum

## utf8Uncased*

Applies full Unicode case folding to a UTF-8 buffer.

```typescript
utf8UncasedFold(buffer: Buffer, validate?: boolean): Buffer
```

- `buffer`: UTF-8 encoded input
- `validate`: If true, validates UTF-8 and throws on invalid input

## utf8Uncased*

Finds the first occurrence of `needle` in `haystack` under full Unicode case folding.

```typescript
utf8UncasedFind(
    haystack: Buffer,
    needle: Buffer,
    validate?: boolean,
): FindResult
```

- `haystack`: UTF-8 encoded haystack
- `needle`: UTF-8 encoded needle
- `validate`: If true, validates UTF-8 and throws on invalid input

## utf8*

Counts the Unicode codepoints in a UTF-8 buffer.

```typescript
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.

- `buffer`: UTF-8 encoded input

## utf8*

Resolves a codepoint index to a byte offset in a UTF-8 buffer.

```typescript
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.

- `buffer`: UTF-8 encoded input
- `index`: Zero-based codepoint index

## utf8*

Normalizes a UTF-8 buffer into the requested Unicode normal form.

```typescript
utf8Norm(
    buffer: Buffer,
    form: Utf8NormalFormValue,
    validate?: boolean,
): Buffer
```

- `buffer`: UTF-8 encoded input
- `form`: One of the [`Utf8NormalForm`](#Utf8NormalForm) constants
- `validate`: If true, validates UTF-8 and throws on invalid input

## utf8Find*

Finds the first byte violating the requested Unicode normal form.

```typescript
utf8FindDenormalized(
    buffer: Buffer,
    form: Utf8NormalFormValue,
): bigint
```

- `buffer`: UTF-8 encoded input
- `form`: One of the [`Utf8NormalForm`](#Utf8NormalForm) constants

## Hasher

Stateful hasher class for streaming hash computation.

```typescript
Hasher: HasherConstructor
```

Use this for hashing data that arrives in chunks.

## Sha256

Stateful SHA-256 hasher class for streaming hash computation.

```typescript
Sha256: Sha256Constructor
```

Use this for hashing data that arrives in chunks.

## Device

The CPU or a GPU, whose capabilities it reports; every call dispatches over the CPU's.

```typescript
Device: DeviceConstructor
```

## Capability

Lowercase capability names, like `haswell`, `neon` or `cuda`, mapped to their `BigInt` bits, and the `cpus`, `gpus` and `any` groups to theirs.

```typescript
readonly Capability: Readonly<Record<CapabilityName, bigint>>
```

## Utf8UncasedNeedle

Uncased UTF-8 needle prepared once, over its own copy of the bytes, for repeated searches.

```typescript
Utf8UncasedNeedle: Utf8UncasedNeedleConstructor
```

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

## Utf8NormalForm

Unicode normalization form constants for [`utf8Norm`](#utf8Norm) and [`utf8FindDenormalized`](#utf8FindDenormalized).

```typescript
readonly Utf8NormalForm: { readonly NFD: 0; readonly NFC: 1; readonly NFKD: 2; readonly NFKC: 3 }
```

## Utf8Wordbreaks

Iterator over TR29 word segments as zero-copy `subarray` views of the buffer it keeps alive: `for (const word of new sz.Utf8Wordbreaks(buffer, validate?)) ...`

```typescript
Utf8Wordbreaks: Utf8SegmentsConstructor
```

## Utf8Graphemes

Iterator over TR29 grapheme clusters, including multi-codepoint ZWJ emoji.

```typescript
Utf8Graphemes: Utf8SegmentsConstructor
```

## Utf8Sentences

Iterator over TR29 sentence segments.

```typescript
Utf8Sentences: Utf8SegmentsConstructor
```

## Utf8Linebreaks

Iterator over UAX14 line-break opportunities.

```typescript
Utf8Linebreaks: Utf8SegmentsConstructor
```

## StringZilla

The StringZilla bindings, the default export of `stringzilla`.

```typescript
interface StringZilla
```

## Hasher

Stateful hasher class for streaming hash computation.

```typescript
Hasher: HasherConstructor
```

Use this for hashing data that arrives in chunks.

## Sha256

Stateful SHA-256 hasher class for streaming hash computation.

```typescript
Sha256: Sha256Constructor
```

Use this for hashing data that arrives in chunks.

## Device

The CPU or a GPU, whose capabilities it reports; every call dispatches over the CPU's.

```typescript
Device: DeviceConstructor
```

## Capability

Lowercase capability names, like `haswell`, `neon` or `cuda`, mapped to their `BigInt` bits, and the `cpus`, `gpus` and `any` groups to theirs.

```typescript
readonly Capability: Readonly<Record<CapabilityName, bigint>>
```

## Utf8UncasedNeedle

Uncased UTF-8 needle prepared once, over its own copy of the bytes, for repeated searches.

```typescript
Utf8UncasedNeedle: Utf8UncasedNeedleConstructor
```

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

## Utf8NormalForm

Unicode normalization form constants for [`utf8Norm`](#utf8Norm) and [`utf8FindDenormalized`](#utf8FindDenormalized).

```typescript
readonly Utf8NormalForm: { readonly NFD: 0; readonly NFC: 1; readonly NFKD: 2; readonly NFKC: 3 }
```

## Utf8Wordbreaks

Iterator over TR29 word segments as zero-copy `subarray` views of the buffer it keeps alive: `for (const word of new sz.Utf8Wordbreaks(buffer, validate?)) ...`

```typescript
Utf8Wordbreaks: Utf8SegmentsConstructor
```

## Utf8Graphemes

Iterator over TR29 grapheme clusters, including multi-codepoint ZWJ emoji.

```typescript
Utf8Graphemes: Utf8SegmentsConstructor
```

## Utf8Sentences

Iterator over TR29 sentence segments.

```typescript
Utf8Sentences: Utf8SegmentsConstructor
```

## Utf8Linebreaks

Iterator over UAX14 line-break opportunities.

```typescript
Utf8Linebreaks: Utf8SegmentsConstructor
```

