Skip to content

Standard Library Overview

Chuks ships with a built-in standard library that covers common tasks — HTTP, file I/O, math, JSON, string manipulation, time utilities, logging, cryptography, authentication, and more. Every module lives under the std/ namespace and is imported with a single line.

import { http } from "std/http";
import { math } from "std/math";
import { json } from "std/json";
import { fs } from "std/fs";
import { time } from "std/time";
import { date } from "std/date";
import { strings } from "std/strings";
import { log } from "std/log";
import { crypto } from "std/crypto";
import { jwt } from "std/jwt";
import { uuid } from "std/uuid";
import { dotenv } from "std/dotenv";
import { validate } from "std/validate";
import { rateLimit } from "std/rate_limit";
import { test } from "std/test";
import { channel } from "std/channel";
import { db } from "std/db";
import { Schema, SchemaBuilder, ColumnBuilder } from "std/db/schema";
import { Repository } from "std/db/repository";
import { QueryBuilder } from "std/db/query";
import { Buffer } from "std/buffer";
import { TcpConnection, TlsConnection, TcpServer, resolve } from "std/net";
// Error is globally available — no import needed
// new Error("message", code?, data?)
ModuleImportDescription
HTTPstd/httpHTTP client requests and server creation
Mathstd/mathMathematical functions and constants
JSONstd/jsonParse and stringify JSON data
File Systemstd/fsRead, write, and manage files and directories
Timestd/timeTimestamps, formatting, sleep, and date utilities
Datestd/dateDate creation, arithmetic, comparisons, and boundaries
Stringsstd/stringsString splitting, joining, replacing, and more
Logstd/logStructured, leveled logging with timestamps
Cryptostd/cryptoSHA, HMAC, MD5, PBKDF2, bcrypt, and secure random generation
JWTstd/jwtJSON Web Token signing, verification, decoding
UUIDstd/uuidUUID v4/v7 generation and validation
Dotenvstd/dotenvLoad and manage environment variables
Validatestd/validateInput validation for strings, types, and ranges
Rate Limitstd/rate_limitIn-memory rate limiting with time windows
Teststd/testAssertions and formatted test reporting
Base64std/base64Base64 encoding, decoding, and URL-safe variants
URLstd/urlURL parsing, formatting, query strings, encoding
Regexstd/regexRegular expression matching, replacing, splitting
Pathstd/pathFile path joining, resolving, and manipulation
OSstd/osPlatform info, env vars, shell commands, process info
Databasestd/dbSQL database access (SQLite, PostgreSQL, MySQL, MSSQL built-in)
Schemastd/db/schemaFluent schema definitions, DDL generation, relationships
Repositorystd/db/repositoryType-safe CRUD, query chaining, eager loading
Query Builderstd/db/queryFluent, chainable SQL query builder
Channelstd/channelInter-task communication with buffered/unbuffered channels
Bufferstd/bufferBinary data handling, byte-level I/O, protocol buffers
Netstd/netTCP/TLS networking, servers, and DNS resolution
Error(global)Structured error class with message, code, and data
import { http } from "std/http";
const resp = await http.get("https://api.example.com/data");
println(resp.status); // 200
println(resp.body); // response body
import { fs } from "std/fs";
const content = await fs.readFile("./config.json");
println(content);
import { json } from "std/json";
const data = json.parse('{"name": "Chuks", "version": 1}');
println(data["name"]); // "Chuks"
import { math } from "std/math";
const val = math.floor(math.random() * 100);
println(val);
import { time } from "std/time";
println(time.now());
await time.sleep(1000);
println("1 second later");
import { strings } from "std/strings";
const parts = strings.split("a,b,c", ",");
const joined = strings.join(parts, "-"); // "a-b-c"
import { log } from "std/log";
log.info("Server started", { "port": "3000" });
log.error("Request failed", { "status": "500" });
import { crypto } from "std/crypto";
const hash = crypto.sha256("hello world");
const token = crypto.randomBytes(32);
import { jwt } from "std/jwt";
const token = jwt.sign({ "sub": "user123" }, "secret", 3600000);
const claims = jwt.verify(token, "secret");
import { uuid } from "std/uuid";
const id = uuid.v7(); // Time-ordered, sortable
println(uuid.isValid(id)); // true
import { dotenv } from "std/dotenv";
dotenv.load();
const port = dotenv.get("PORT", "3000");
import { validate } from "std/validate";
validate.isEmail("user@example.com"); // true
validate.minLength("hi", 3); // false
import { rateLimit } from "std/rate_limit";
const limiter = rateLimit.create(100, 60000); // 100 req/min
rateLimit.check(limiter, "192.168.1.1"); // true or false
import { channel } from "std/channel";
const ch = channel.new(0);
spawn {
channel.send(ch, "hello from task");
}
const msg = channel.receive(ch);
println(msg); // "hello from task"
// Error is globally available — no import needed
try {
throw new Error("not found", 404);
} catch (e) {
println(e.message); // "not found"
println(e.code); // 404
}
import { test } from "std/test";
test.assertEqual(1 + 1, 2);
test.assert(len("hello") == 5);

In addition to the std/strings module, strings, arrays, and maps in Chuks have built-in methods that can be called directly on values without any import:

// String methods — no import needed
var s = "Hello World";
println(s.toUpperCase()); // "HELLO WORLD"
println(s.includes("World")); // true
// Array methods — no import needed
var nums = [3, 1, 2];
nums.sort();
println(nums); // [1, 2, 3]
// Map methods — no import needed
var m: map[string]int = {"a": 1, "b": 2};
println(m.keys()); // ["a", "b"]

See the dedicated Strings, Arrays, and Maps pages for complete API references.