gizlang:node
TypeScript's and Node's globals: the timers and new Promise, and the ones that reach the process: fetch, process, and the file functions of node:fs and node:fs/promises. A program's own code calls them with no System parameter: they use the process's System, the authority that a C declaration has too (checker ambientAuthority). A package whose manifest limits its imports gets none of them, and passes a System instead.
import * as Node from "gizlang:node";Types
Env
type EnvThe environment of the process: process.env.HOME reads one variable, undefined when it is not set.
Opaque: create and use it through this module's functions.
Process
type ProcessNode's process: its arguments, environment and working directory, and the exit.
Opaque: create and use it through this module's functions.
Response
type ResponseAn HTTP response as fetch gives it: the status, its headers, and the body read whole.
status:f64ok:boolheaders:Vec<gizlang_http.Header>
RequestInit
type RequestInit = { method?: string; body?: string; }The options of fetch: the method (GET when none) and the body.
method:_gizlang_sdk_core.Option<string>body:_gizlang_sdk_core.Option<string>
Functions
fetch
function fetch(url: string, init?: RequestInit): ResponseAn HTTP or HTTPS request to URL, read whole, as Node's fetch(url). It throws an Error when the URL is not http or
https, or the request fails; a status of 400 or more is a Response with ok false.
Effects: fail, read, write, console, io.
readFileSync
function readFileSync(path: string, encoding?: string): stringThe text of the file PATH (readFileSync(path, "utf8")). The encoding is read as UTF-8 whatever it names.
Effects: fail, read, write, console, io.
writeFileSync
function writeFileSync(path: string, text: string): voidReplace the file PATH with TEXT, made when it is missing.
Effects: fail, read, write, console, io.
appendFileSync
function appendFileSync(path: string, text: string): voidAdd TEXT at the end of the file PATH, made when it is missing.
Effects: fail, read, write, console, io.
existsSync
function existsSync(path: string): boolWhether PATH exists.
Effects: fail, read, write, console, io.
readFile
async function readFile(path: string, encoding?: string): Promise<string>node:fs/promises readFile: the text of the file PATH.
Effects: fail, read, write, console, io.
writeFile
async function writeFile(path: string, text: string): Promise<void>node:fs/promises writeFile: replace the file PATH with TEXT.
Effects: fail, read, write, console, io.
setTimeout
function setTimeout(run: () => void, ms?: number): numberRun RUN once after MS milliseconds, when the code before it has run: the end of main, or a Promise that waits.
Effects: fail, read, write, console, io.
setInterval
function setInterval(run: () => void, ms?: number): numberRun RUN every MS milliseconds until clearInterval.
Effects: fail, read, write, console, io.
clearTimeout
function clearTimeout(id: number): voidStop the timer ID; nothing for an ID that has run or never was.
Effects: fail, read, write, console, io.
clearInterval
function clearInterval(id: number): voidStop the interval ID.
Effects: fail, read, write, console, io.
runTimers
function runTimers(): voidRun every timer left: the end of a main that set one (parser timers).
Effects: fail, read, write, console, io.
waitPromise
function waitPromise(executor: (resolve: () => void) => void): voidnew Promise(resolve => ...) with no value: EXECUTOR runs, then the timers until it calls resolve.
Effects: fail, read, write, console, io.
newPromise
function newPromise<T>(executor: (resolve: (value: T) => void) => void): Tnew Promise<T>(resolve => ...): EXECUTOR runs, then the timers until it calls resolve with the value.
newPromiseOr
function newPromiseOr<T>(executor: (resolve: (value: T) => void, reject: (reason: Error) => void) => void): Tnew Promise<T>((resolve, reject) => ...): as newPromise, and a call of reject throws its reason.
random
function random(): numberA number in [0, 1), as TypeScript's Math.random(). Not for keys or tokens: gizlang:crypto's randomBytes is.
Effects: fail, read, write, console, io.
Methods
Env.property
function Env.property(self: Env, name: string): Option<string>The value of the environment variable NAME (process.env.NAME), or undefined.
Effects: fail, read, write, console, io.
Process.argv
function Process.argv(self: Process): Vec<string>The arguments (process.argv). argv[0] and argv[1] stand for Node's runtime and script, so the arguments
start at index 2, where process.argv.slice(2) reads them.
Effects: fail, read, write, console, io.
Process.env
function Process.env(self: Process): EnvThe environment (process.env).
Process.platform
function Process.platform(self: Process): stringThe operating system as Node names it: "linux", "darwin" or "win32".
Effects: fail, read, write, console, io.
Process.exit
function Process.exit(self: Process, code: number): voidEnd the process with CODE (0 to 255), as process.exit(code) does.
Effects: fail, read, write, console, io.
Process.cwd
function Process.cwd(self: Process): stringThe working directory.
Effects: fail, read, write, console, io.
Response.text
function Response.text(self: Response): stringThe body as UTF-8 text.
Effects: fail.
Response.json
function Response.json(self: Response): JsonThe body parsed as JSON.
Effects: fail.
Constants
process
const process: Process = { _unused: false }Node's process.