the runtime enum indicating which runtime's working-directory/url-path to retrieve.
a boolean flag that, when true, returns the full href
url of the runtime, rather than the root origin
. defaults to true
.
a posix string path of the working-directory/url-path of the specified runtime.
an error is thrown if the runtime associated with the provided enum is undefined, or if an invalid enum is provided.
import { assertEquals } from "jsr:@std/assert"
import process from "node:process" // this works in deno 2.0
assertEquals(getRuntimeCwd(RUNTIME.DENO), getRuntimeCwd(RUNTIME.NODE))
assertEquals(getRuntimeCwd(RUNTIME.DENO), Deno.cwd().replaceAll(/\\\\?/g, "/"))
assertEquals(getRuntimeCwd(RUNTIME.NODE), process.cwd().replaceAll(/\\\\?/g, "/"))
retrieves the current working directory or URL based on the specified RUNTIME enum.
chrome.runtime.getURL("")
)undefined
object.depending on the provided
runtime_enum
, the current working directory is defined as the following:DENO
,BUN
, andNODE
: the result will be that of the runtime'scwd()
method.CHROMIUM
andEXTENSION
: the result will be the url string obtained fromruntime.getURL("")
.WEB
andWORKER
: a url string will be returned that will vary based on thecurrent_path
flag (true
by default):current_path == false
:location.origin
will be returned (i.e. the root of your webpage, which is your domain-name + subdomain-name).current_path == true
: the directory path oflocation.href
will be returned.