Cosmic Docs



Contains common utilities. All functions here are also available in the global scope. You can call them directly without the cs.core prefix.

cs.core.getCliArgs (  ) .v8.Array

Returns an array of arguments used to start the process in the command line.

cs.core.print args: ?...any )

Prints any number of variables as strings separated by " ".

cs.core.puts args: ?...any )

Prints any number of variables as strings separated by " ". Wraps to the next line.

cs.core.dump args: ?...any )

Prints a descriptive string of the js value(s) separated by " ". Wraps to the next line.

cs.core.gets (  ) string

Reads input from the command line until a new line returned.

cs.core.timerNow (  ) BigInt

Returns the current timestamp since the runtime started in nanoseconds.

cs.core.bufferToUtf8 buffer: Uint8Array ) string

Converts a buffer to a UTF-8 string.

cs.core.createRandom seed: BigInt ) object

Create a fast random number generator for a given seed. This should not be used for cryptographically secure random numbers.

cs.core.setTimeout timeout: number, callback: function, callbackArg: ?any ) number

Invoke a callback after a timeout in milliseconds.

Returns the absolute path of the main script.

Returns the absolute path of the main script's directory. Does not include an ending slash. This is useful if you have additional source or assets that depends on the location of your main script.

cs.core.getAppDir : string ) string

Given an app name, returns the platform's app directory to read/write files to. This does not ensure that the directory exists. See cs.files.ensurePath.

Get the current clipboard text.

cs.core.setClipboardText text: string )

Set the current clipboard text.

cs.core.panic msg: ?string )

Prints the current stack trace and exits the program with an error code. This is useful to short circuit your program.

cs.core.exit code: number )

Terminate the program with a code. Use code=0 for a successful exit and a positive value for an error exit.

cs.core.errCode (  ) number

Returns the last error code. API calls that return null will set their error code to be queried by errCode() and errString().

cs.core.errString : runtime.api.cs_core.CsError ) string

Returns an error message for an error code.

Clears the last error.

cs.core.getOs (  ) runtime.api.cs_core.Os

Returns the host operating system.

cs.core.getOsVersion (  ) string

Returns the host operating system and version number as a string.

cs.core.getCpu (  ) string

Returns the host cpu arch and model as a string.

cs.core.getResourceUsage (  ) runtime.api.cs_core.ResourceUsage

Returns the resource usage of the current process.

cs.core.gc (  )

Invokes the JS engine garbage collector.

(  ) number

Gets the next random number between 0 and 1.

cs.core.ResourceUsage object
user_time_secs: number
user_time_usecs: number
sys_time_secs: number
sys_time_usecs: number
memory: number