@pdfking/structs

Runtime

checks

ArrayQ

const ArrayQ = Array.isArray

Type guard function that checks if a value is an array. Returns true if the value is an array, false otherwise.

Parameters

  • arg The value to check

Returns True if the value is an array, false otherwise

Example
import { ArrayQ } from "@pdfking/structs"

ArrayQ([1, 2, 3]) // true
ArrayQ("hello") // false

// Use in conditional logic
const input: string | string[] = "hello"
ArrayQ(input) ? input : [input] // ["hello"]

BigintQ

const BigintQ = <T>(value: T): value is bigint & T

Type guard function that checks if a value is a bigint. Returns true if the value is a bigint, false otherwise.

Parameters

  • value The value to check

Returns True if the value is a bigint, false otherwise

Example
import { BigintQ } from "@pdfking/structs"

BigintQ(10n) // true
BigintQ(10) // false

BooleanQ

const BooleanQ = <T>(value: T): value is boolean & T

Type guard function that checks if a value is a boolean. Returns true if the value is a boolean, false otherwise.

Parameters

  • value The value to check

Returns True if the value is a boolean, false otherwise

Example
import { BooleanQ } from "@pdfking/structs"

BooleanQ(true) // true
BooleanQ(1) // false

BytesQ

const BytesQ = <T>(value: T): value is Uint8Array & T

Type guard function that checks if a value is a Uint8Array. Returns true if the value is a Uint8Array, false otherwise.

Parameters

  • value The value to check

Returns True if the value is a Uint8Array, false otherwise

Example
import { BytesQ } from "@pdfking/structs"

BytesQ(new Uint8Array([1, 2, 3])) // true
BytesQ([1, 2, 3]) // false

FunctionQ

const FunctionQ = <T extends (...args: any[]) => any>(value: unknown): value is T

Type guard function that checks if a value is a function. Returns true if the value is a function, false otherwise.

Parameters

  • value The value to check

Returns True if the value is a function, false otherwise

NullQ

const NullQ = (value: unknown): value is null | undefined

Type guard function that checks if a value is null or undefined. Returns true if the value is null or undefined, false otherwise.

Parameters

  • value The value to check

Returns True if the value is null or undefined, false otherwise

Example
import { NullQ } from "@pdfking/structs"

NullQ(null) // true
NullQ(undefined) // true
NullQ("hello") // false

// Use in conditional logic
const input: string | undefined = undefined
NullQ(input) ? "default" : input // "default"

NumberQ

const NumberQ = <T>(value: T): value is number & T

Type guard function that checks if a value is a number. Returns true if the value is a number, false otherwise.

Parameters

  • value The value to check

Returns True if the value is a number, false otherwise

Example
import { NumberQ } from "@pdfking/structs"

const num = 42;
const str = "42";

if (NumberQ(num)) {
  console.log(num.toFixed(2)); // "42.00" (type narrowed to number)
}

if (NumberQ(str)) {
  // This block won't execute
}

// Use in filtering
const mixed = [1, "two", 3, "four"];
const numbers = mixed.filter(NumberQ); // [1, 3]

RecordQ

const RecordQ = (value: unknown): value is Record<string, unknown>

StringQ

const StringQ = <T>(value: T): value is string & T

Type guard function that checks if a value is a string. Returns true if the value is a string, false otherwise.

Parameters

  • value The value to check

Returns True if the value is a string, false otherwise

Example
import { StringQ } from "@pdfking/structs"

const str = "hello";
const num = 42;

if (StringQ(str)) {
  console.log(str.toUpperCase()); // "HELLO" (type narrowed to string)
}

if (StringQ(num)) {
  // This block won't execute
}

// Use in filtering
const mixed = [1, "two", 3, "four"];
const strings = mixed.filter(StringQ); // ["two", "four"]

functions

Render

const Render = <N extends string, T = {}, R = string>(
  names: { [K in N]: (ctx: NoInfer<T>) => R },
  item: EnumType<N, T>
): R

types

ContentType

const enum ContentType {
  BYTES = "application/octet-stream",
  HTML = "text/html",
  JSON = "application/json",
  JPEG = "image/jpeg",
  PDF = "application/pdf",
  PNG = "image/png",
  TEXT = "text/plain",
  TIFF = "image/tiff",
  WASM = "application/wasm",
  WEBP = "image/webp",
  ZIP = "application/zip",
  IDML = "application/vnd.adobe.indesign-idml-package",
  XML = "text/xml",
}