Skip to main content

Standard Library

txiki.js ships a small standard library of modules that build on the core runtime. They are imported using the tjs: scheme:

import assert from 'tjs:assert';
import { parse } from 'tjs:path';
import { Database } from 'tjs:sqlite';

assert.eq(1 + 1, 2);

Modules

ModuleDescription
tjs:assertAssertion functions for testing
tjs:ffiForeign Function Interface for calling native libraries
tjs:getoptsCommand-line argument parsing
tjs:hashingCryptographic hash functions (guide)
tjs:ipaddrIP address parsing and manipulation
tjs:pathFile path utilities (POSIX and Windows)
tjs:posix-socketLow-level POSIX socket API
tjs:readlineInteractive line editing and ANSI colors
tjs:sqliteSQLite3 database
tjs:utilsUtility functions for formatting and inspecting values
tjs:uuidUUID generation and validation
tjs:wasiWebAssembly System Interface

See the API Reference for the full per-symbol documentation.

Build-time feature gating

A couple of modules depend on optional build features and may be absent from a custom build:

  • tjs:sqlite requires BUILD_WITH_SQLITE (on by default). When disabled, importing it throws and localStorage falls back to an in-memory store.
  • tjs:wasi (and the WebAssembly global) requires BUILD_WITH_WASM (on by default). When disabled, importing it throws a module-not-found error.

Detect availability at runtime via tjs.engine.features:

if (tjs.engine.features.sqlite) {
const { Database } = await import('tjs:sqlite');
// ...
}