Built-ins
These names are in scope in every module without an import. They come from the compiler and from the standard library's prelude (prelude reference).
| Name | What it is |
|---|---|
console.log(a, b, …), console.info(…), console.debug(…); console.error(…), console.warn(…) | print the arguments separated by spaces: log, info and debug to stdout, error and warn to stderr, as in Node. Values print like Node: [ 1, 2 ], { k: 1, s: 'a' }, Map(1) { 'a' => 1 } (a subclass M of Map or Set as M(1) [Map] { 'a' => 1 }, then its own fields: M(1) [Map] { 'a' => 1, tag: 't' }), ClassName { field: value } (or, for a class with a method keyed by Node's util.inspect.custom, what that returns: [Symbol.for("nodejs.util.inspect.custom")](): string { … }, or a constant holding that symbol as the key), a JsonValue like the parsed object, a promise as Promise { <pending> }, Promise { 42 } or Promise { <rejected> … } (its state now, without awaiting it or taking its value; unlike Node, one settled by a stored resolve/reject shows it only once the task next waits, so it still prints <pending> right after the call), numbers JS-style; an object graph that refers back to itself prints <ref *1> Node { next: [Circular *1] }, numbered per argument like Node ([ <ref *1> …, <ref *2> … ] for two cycles in one array). A value too long for one line (node's breakLength of 80 columns) prints one entry per line, indented by two spaces, and an array of more than six short entries in aligned columns, as Node does. Node's default limits apply: a container nested more than two levels deep prints as [Object], [Array], [ClassName], [Map], [Set] or [Promise] (an empty one in full, {} or []; a reference back to an object being printed stays [Circular *1]), and an array, Map or Set prints its first 100 entries followed by ... 50 more items (objects print every field) |
process.exit(code: i32) | exit immediately |
process.stdout.write(s), process.stderr.write(s) | write a string without a newline, ordered with console.log / console.error; return true like Node |
process.env.NAME, process.env[name] | an environment variable as string | null (null where Node has undefined); set one with setEnv and list them with envAll() of velt/process, which also has cwd() and byte writes |
process.argv | Node's [runtime, script, ...args] (process.argv.slice(2) is the arguments); a new array each read, so changing it in place is an error (velt/process) |
process.memoryUsage() | { rss, heapUsed } in bytes, a MemoryUsage (velt/process) |
panic(msg) | stop with a panic (exit code 101) |
assert(cond, msg), assertEq(a, b) | panic when the check fails (assertEq compares contents) |
assertThrows(() => f()) | the error f throws; panics if it returns normally |
deepEqual(a, b) | content comparison (== compares objects by identity) |
attempt(() => f()) | a throwing call as a value: T | E (Errors) |
Math | PI, E, sqrt floor ceil round trunc abs sign max min pow hypot random, … |
String(x), Number(x), Boolean(x), parseInt(s, radix), parseFloat(s), isNaN(x), isFinite(x), String.fromCharCode(...codes), NaN, Infinity | conversions and checks |
Buffer.alloc(n), Buffer.byteLength(s) | byte arrays (u8[]) (prelude) |
Number.isInteger(x), Number.isNaN, isFinite, isSafeInteger, parseInt, parseFloat, Number.MAX_SAFE_INTEGER, MIN_SAFE_INTEGER, EPSILON, MAX_VALUE, MIN_VALUE, NaN, POSITIVE_INFINITY, NEGATIVE_INFINITY | JS's Number members, on f64 |
JSON.stringify (also with an array replacer and space), JSON.parse<T>, JSON.parseValue, JsonValue, JsonError | JSON (velt/encoding/json) |
Error | base class of thrown errors: class Error { message: string } |
TypeError, RangeError, SyntaxError, ReferenceError, EvalError, URIError, AggregateError, AssertionError, DOMException | JavaScript's error classes, and the one assert throws (prelude) |
Comparable<T> | ordering interface (Comparable) |
Map<K, V> | insertion-ordered hash map (Types) |
Object.keys/values/entries/fromEntries/is/assign/freeze/hasOwn/getPrototypeOf/create(null), Object.prototype.hasOwnProperty.call, Object.prototype.toString.call, Array.isArray | JavaScript's object built-ins, on Velt's objects (Types) |
sleep(ms), yieldNow(), spawn(p, options?), Promise.all/race/allSettled/any/withResolvers/resolve/reject, new Promise((resolve, reject) => …), queueMicrotask(f) | async (Async) |
setTimeout(task, ms), clearTimeout(t), setInterval(task, ms), clearInterval(t), setImmediate(task), clearImmediate(t), Timer | timers, as in TypeScript; the callback may return a promise (() => save(doc), async () => { … }) or nothing (() => console.log("x")) (velt/time) |
shared(x), shared<T>, Mutex<T>, RwLock<T>, Atomic<T>, ThreadLocal<T> | thread-safe shared state (Async) |
WeakMap<K, V>, WeakSet<T>, WeakRef<T> | weak references, as in JavaScript (prelude) |
performance.now(): f64, Date.now(): i64 | monotonic and wall-clock milliseconds |
Date | JavaScript's dates (prelude) |
fetch(input, init), Request, Response, Headers | the WHATWG Fetch API, as in Node (velt/net/http) |
Blob, File, FormData | request and response bodies of the Fetch API (velt/net/http) |
AbortController, AbortSignal | cancellation, e.g. of a fetch (velt/task) |
URL, URLSearchParams, encodeURIComponent, encodeURI, decodeURIComponent, decodeURI | WHATWG URLs and percent-encoding (velt/net/url) |
Set<T> | insertion-ordered hash set (velt/collections) |
RegExp, /ab+c/gi | regular expressions (velt/text) |
StringBuilder | a growable string (velt/text) |
TextEncoder, TextDecoder | UTF-8 text to bytes and back (velt/encoding) |
ArrayBuffer, DataView, Uint8Array, Int8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array | bytes and the typed arrays that view them, as in Node (typed arrays) |
btoa(s), atob(s) | Base64 of binary strings, as in Node (velt/encoding) |
DOMException | the error web APIs throw, with name and code (prelude) |
ReadableStream, ReadableStreamDefaultReader, ReadableStreamDefaultController | WHATWG streams, as in Node (velt/io/streams) |
structuredClone(x) | an independent deep copy, x.clone() (Memory model); a function (at any depth) or an instance of a class of your own is a compile error, as JS throws or drops the class: write x.clone() |
Symbol.dispose, Symbol.asyncDispose | cleanup method names (Memory model) |
Symbol.iterator, Symbol.asyncIterator | iteration method names (Control flow) |
Symbol(desc), Symbol.for(key) | symbols, as property keys (Types, Symbol) |
Proxy, Reflect | JavaScript's proxies and reflection (Types) |
The modules behind fetch, AbortController, URL, Set, RegExp, TextEncoder, btoa,
DOMException and Uint8Array
(and the names next to them) are loaded only by programs that mention one of those names (or
hold a regex literal), so the others don't pay for compiling them; a module that imports or
declares such a name itself (import { Response } from "./api") uses its own and
doesn't load the global. Likewise a program that uses Response or Request loads the typed
arrays behind res.bytes() and res.arrayBuffer() only when it mentions bytes or
arrayBuffer (or names a typed array). Integer helpers (gcd,
clamp, …) are in velt/math. Everything else is imported from the
standard library as velt/<area> (Modules).
The functions the compiler calls behind the scenes (such as __anyAdd) live in std's internal
velt/lang: they are not in scope (cannot find `__anyAdd` in this scope) and can't be imported.