Types
hashing
Sha256Handle
type Sha256Handle = {
update: (data: Uint8Array) => void
digest: () => GUID
}types
AsyncSequence
type AsyncSequence<T> = AsyncIterable<T> | Sequence<T>
Union type for sync or async sequences.
Accepts both AsyncIterable (async generators) and sync Iterable. Used throughout library for streaming operations.
const sync: AsyncSequence<number> = [1, 2, 3]
const async: AsyncSequence<number> = async function*() { yield 1 }()Atom
type Atom = bigint | boolean | number | string
Primitive atomic value types.
Union of basic serializable types for hashing and encoding.
const values: Atom[] = [42, "hello", true, 123n]
BinaryInput
type BinaryInput = ArrayBuffer | string | Uint8Array
One thing that already is bytes: no waiting to read it.
A string counts because encoding one is a call rather than a round trip.
import type { BinaryInput } from "@pdfking/tfunc"
import { StringToUInt8 } from "@pdfking/tfunc"
const inputs: BinaryInput[] = ["hello", StringToUInt8("hello"), new ArrayBuffer(5)]
inputs.length // 3GUID
type GUID = Integer<"GUID", "u256">
Globally Unique Identifier as 256-bit bigint.
Branded type for type safety. Used for hash outputs (SHA-256).
StringGUID
type StringGUID = String<"GUID">
GUID as hex string representation.
String form of GUID for serialization/display.
AnyGUID
type AnyGUID = GUID | StringGUID
Union of bigint and string GUID forms.
JWTHeader
type JWTHeader = {
alg: string
typ: string
}JWT header structure.
Standard JWT header with algorithm and type fields.
const header: JWTHeader = { alg: "HS256", typ: "JWT" }Sequence
type Sequence<T> = Exclude<Iterable<T>, string>
Iterable sequence excluding strings.
Any Iterable except string (since strings are iterable but usually need special handling).
const arr: Sequence<number> = [1, 2, 3]
const gen: Sequence<number> = function*() { yield 1 }()XOR
type XOR<T, U> =
| ({ [K in Exclude<keyof T, keyof U>]?: never } & U)
| ({ [K in Exclude<keyof U, keyof T>]?: never } & T)Creates mutually exclusive union (one or the other, not both).
Ensures only properties from one type can be present at a time.
Similar to Result
type BinaryPdf = { source: File; page: undefined }
type PlottedPdf = { source: undefined; page: Page }
type SinglePagePdf = XOR<BinaryPdf, PlottedPdf>
// Can have source OR page, but not both