{ } qjs-modules

misc

Source: quickjs-misc.c — module exports a large flat list of functions plus many constants.

A grab-bag of system, process, buffer, and QuickJS-internals utilities. Grouped below by theme.

Filesystem & paths

FunctionArgsDescription
tempnam()0Generates a temporary file name.
mkstemp(template)1Creates and opens a unique temp file.
fnmatch(pattern, string, flags)3Shell-style pattern match.
glob(pattern, flags)2Filename globbing.
wordexp(words, flags)2Shell-style word expansion.
watch(path)1Watches a path for changes.
unlink(path)1Removes a file.
link / linkat / symlink / symlinkat2–3Create hard / symbolic links.
chmod / fchmod2Change file mode (by path / fd).
chown / fchown / lchown3Change ownership.
fsync / fdatasync1Flush file data to disk.
truncate / ftruncate2Set file length.
utime / utimes / lutimes / futimes2Set access/modification times.
access(path, mode)2Check file accessibility.
fcntl(fd, cmd, ...)2File descriptor control.
fstat(fd)1Stat by descriptor.
fmemopen(buf, mode)2Open an in-memory FILE.
_get_osfhandle / _open_osfhandle1Windows fd ↔ handle conversion.

Processes & users

FunctionArgsDescription
daemon(nochdir, noclose)2Detach into the background.
fork() / vfork()0Fork the current process.
exec(file, args)2Replace the process image.
kill(pid, sig)1Send a signal.
setsid()0Start a new session.
gettid / getpid / getppid / getsid0Process/thread ids.
getuid / getgid / geteuid / getegid0Read user/group ids.
setuid / setgid / seteuid / setegid1Set user/group ids.
getExecutable / getWorkingDirectory / getRootDirectory / getFileDescriptor0Resolve /proc/self/* links.
getCommandLine / getEnvironment / getProcStat / getProcMaps / getProcMounts0Read /proc info.
uname()0System identification.
getRelease()0OS release string.

Time & randomness

FunctionArgsDescription
getPerformanceCounter()0High-resolution counter.
hrtime()0High-resolution time ([s, ns]).
rand / randi0Random float / integer.
srand(seed)1Seed the generator.
randb(n)1Random bytes.

Terminal / console

FunctionArgsDescription
ioctl(fd, request, arg)3Device control.
getScreenSize()0Terminal size.
clearScreen / clearLine1ANSI erase.
setCursorPosition / moveCursor1Cursor control.
setTextAttribute / setTextColor2ANSI text styling.
setConsoleMode / getConsoleMode1–2Console mode (Windows).
ttySetRaw(fd)1Put a TTY into raw mode.

Buffers & ArrayBuffers

FunctionArgsDescription
toString(buf)1Bytes → string.
toArrayBuffer(value)1Coerce to an ArrayBuffer.
dupArrayBuffer / sliceArrayBuffer / concatArrayBuffer1Copy / slice / concatenate buffers.
searchArrayBuffer(haystack, needle)2Find a byte pattern.
copyArrayBuffer / compareArrayBuffer2Copy into / compare buffers.
toPointer(value)1Native pointer of a value.
strcmp(a, b)2C-string comparison.
charCode / charLength1Codepoint / UTF-8 length helpers.

Encoding & bit twiddling

FunctionArgsDescription
btoa / stoa1Base64 / byte encode.
atob / atos1Base64 decode (to bytes / string).
escape / unescape1Percent-style escaping.
quote / dequote1Add / remove quoting.
not / xor / and / or1–2Bitwise ops over buffers.
bitfieldSet / bits / bitfieldToArray / arrayToBitfield1Bitfield conversions.

QuickJS internals & reflection

FunctionArgsDescription
getPrototypeChain(value)0Walks the prototype chain.
immutableClass(value)1Marks a class immutable.
writeObject / readObject1Serialize / deserialize a value (bytecode form).
evalBinary(buf)1Evaluate compiled bytecode.
getOpCodes()0List VM opcodes.
getByteCode(fn)1Disassemble a function.
valueType / typeFlag / typeName / typeString / valueTag / valuePointer1Low-level value type info.
objectClassId / objectRefCount / objectOpaque1Object internals.
classAtom / className / classId1Class metadata.
stringPointer / stringLength / stringBuffer1String internals.
atomToString / atomToValue / findAtom / valueToAtom / dupAtom / freeAtom1Atom table operations.
getTypeId / getTypeStr / getTypeName1Type identification.
promiseState / promiseResult1Inspect a promise.
error()0Current error object.
atexit(fn)1Register an exit handler.
enqueueJob(fn)1Queue a microtask/job.

Type predicates (isX(value), 1 arg each)

isArray, isArrayBuffer, isBigDecimal, isBigFloat, isBigInt, isBool, isConstructor, isEmptyString, isError, isException, isExtensible, isFunction, isInstanceOf, isInteger, isJobPending, isLiveObject, isNull, isNumber, isObject, isRegisteredClass, isString, isSymbol, isUncatchableError, isUndefined, isUninitialized.

Constants

The module also exports a large set of errno, signal, O_*, S_*, F_*, AT_* and similar numeric constants.