The help()
function prints documentation for various APIs and values found in the YavaScript runtime.
Here is a list of all of YavaScript's APIs. Pass any value listed here into help(...)
to see its corresponding documentation.
env
: Read/write the process's environment variablesexec
: Run programs$
: Run programs and capture their outputChildProcess
: Lower-level program-running API used byexec
exists
: Check if a file/folder exists at a pathisFile
: Check if a path refers to a fileisDir
: Check if a path refers to a directory (folder)isLink
: Check if a path refers to a symbolic link (symlink)readFile
: Read the contents of a fileremove
: Delete (unlink) a filewriteFile
: Write data to diskcopy
: Copy a file or folderrename
: Rename (move) a fileisExecutable
: Check if a file has the executable bit set (ie. fromchmod +x
)isReadable
: Check if the current user has permissions to read a pathisWritable
: Check if the current user has permissions to write to a path
basename
: Get the last component of a pathcat
: Read one or more filescd
: Change the working directorychmod
: Change file/folder permissionsdirname
: Exclude last component from a pathecho
: Print values to stdoutexit
: Stop executionextname
: Get a file extension from a path or filenamels
: List the contents of a foldermkdir
: Create a foldermkdirp
: Recursively ensure a folder path existsprintf
: Print values with C format specifierspwd
: Get the present working directoryreadlink
: Get the target of a symlinkrealpath
: Resolve paths and symlinks to absolute pathssleep
: Pause execution for a period of timetouch
: Create a file or update its timestampswhich
: Find the path to a program on the systemgrepFile
: Search for matches in a filegrepString
: Search for matches in a string
Path
: Object representing a filesystem path, with methods for working with it.- Almost all YavaScript APIs accept Path objects in the same places where you could use path strings.
GitRepo
: methods for locating and getting info from git repositories on disk.glob
: Search the filesystem using globs. Returns an array of paths.assert
: Throw an error if a value isn't truthyis
: Check the runtime type of any valueassert.type
: Throw an error if a value doesn't have the expected typetypes
: Runtime types and type builders for use withis
andassert.type
help
: Print help docs for (almost) any runtime value
Methods which are useful when printing strings to a terminal (command-line) screen. Most of these function wrap strings in escape codes which causes terminals to print them with different styling.
quote
: Wrap a string in double-quotes and escape any double-quotes withinstripAnsi
: Remove ANSI control character sequences from a stringbgBlack
: Set background color to blackbgBlue
: Set background color to bluebgCyan
: Set background color to cyanbgGreen
: Set background color to greenbgMagenta
: Set background color to magentabgRed
: Set background color to redbgWhite
: Set background color to whitebgYellow
: Set background color to yellowblack
: Set text (foreground) color to blackblue
: Set text (foreground) color to bluecyan
: Set text (foreground) color to cyangray
: Set text (foreground) color to graygreen
: Set text (foreground) color to greengrey
: Set text (foreground) color to greymagenta
: Set text (foreground) color to magentared
: Set text (foreground) color to redwhite
: Set text (foreground) color to whiteyellow
: Set text (foreground) color to yellowbold
: Make text thickerdim
: Make text greyed out a bithidden
: Make text not visibleinverse
: Swap foreground and background colorsitalic
: Italicize textreset
: Reset all styles/colorsstrikethrough
: Cross out text with a lineunderline
: Put a line beneath text
console
: Standard JavaScript object. Write to stdout or stderr.print
: Write to stdout. Same asconsole.log
.echo
: Write to stdout. Same asconsole.log
.clear
: Write ANSI escape sequences to stdout which clear the terminal.inspect
: Create a human-readable string for any value.console
,print
, andecho
call this internally.logger
: The default logger, used by several YavaScript APIs. You can replace its properties to increase logging verbosity, similar toset -x
in traditional unix shells.
scriptArgs
: The command-line arguments passed to the program.parseScriptArgs
: Parse command-line arguments into an object.startRepl
: Enter the YavaScript REPL (Read-Eval-Print-Loop) from within one of your scripts.InteractivePrompt
: Create your own REPL__filename
: The absolute path to the currently-executing file__dirname
: The absolute path to the directory (folder) containing the currently-executing file
Each of these has a stringify
and parse
method, which can be used to convert between strings and objects/arrays/etc.
CSV
: For working with comma-separated valuesYAML
: For working with YAML Ain't Markup Language (yml)TOML
: For working with Tom's Obvious Minimal LanguageJSON
: Standard JavaScript object. For working with JavaScript Object Notation.
JSX
: Used when compiling JSX syntax. User overrides for JSX handling can go here.yavascript.compilers
: The internal compiler functions used by YavaScript to handle compile-to-JS languages. You can use these yourself with strings, if desired.
Additions/extensions to the standard ECMAScript objects found in the runtime.
String.prototype.grep
: Alias forgrepString
RegExp.escape
: Escape special RegExp characters in a stringString.dedent
: Remove leading indentation from template strings
There are several lowercase aliases for builtin constructors, so that certain types passed to is
and assert.type
can be written with the same casing as they use in TypeScript.
bigint
: Alias forBigInt
boolean
: Alias forBoolean
number
: Alias forNumber
string
: Alias forString
symbol
: Alias forSymbol
For convenience, two builtin modules from QuickJS are also available as globals.
std
: The "quickjs:std" moduleos
: The "quickjs:os" module
Pass any of the listed values, or any other value, into help(...)
to read its documentation. For example:
help(exec); // Prints documentation for the `exec` function
help(__dirname); // Prints documentation about `__dirname`
help(TOML); // Prints documentation about the `TOML` object
help(TOML.stringify); // Prints documentation about the `TOML.stringify` function