Module

x/dax/mod.ts>$BuiltInProperties

Cross-platform shell tools for Deno and Node.js inspired by zx.
Very Popular
Latest
interface $BuiltInProperties
import { type $BuiltInProperties } from "https://dotland.deno.dev/x/dax@0.39.2/mod.ts";

Collection of built-in properties that come with a $.

Type Parameters

optional
TExtras extends ExtrasObject = { }

Properties

dedent: Outdent

De-indents (a.k.a. dedent/outdent) template literal strings

Re-export of https://deno.land/x/outdent

Removes the leading whitespace from each line, allowing you to break the string into multiple lines with indentation. If lines have an uneven amount of indentation, then only the common whitespace is removed.

The opening and closing lines (which contain the ` marks) must be on their own line. The opening line must be empty, and the closing line may contain whitespace. The opening and closing line will be removed from the output, so that only the content in between remains.

path: createPath

Helper function for creating path references, which provide an easier way for working with paths, directories, and files on the file system.

The function creates a new Path from a path or URL string, file URL, or for the current module.

logDepth: number

Gets or sets the current log depth (0-indexed).

symbols: symbols

Symbols that can be attached to objects for better integration with Dax.

which: Which

Re-export of deno_which for getting the path to an executable.

whichSync: WhichSync

Similar to which, but synchronously.

Methods

request(url: string | URL): RequestBuilder

Makes a request to the provided URL throwing by default if the response is not successful.

const data = await $.request("https://plugins.dprint.dev/info.json")
 .json();
build$<TNewExtras extends ExtrasObject = { }>(options?: Create$Options<TNewExtras>): $Type<Omit<TExtras, keyof TNewExtras> & TNewExtras>

Builds a new $ which will use the state of the provided builders as the default and inherits settings from the $ the new $ was built from.

This can be useful if you want different default settings or want to change loggers for only a subset of code.

Example:

import $ from "https://deno.land/x/dax/mod.ts";

const commandBuilder = new CommandBuilder()
  .cwd("./subDir")
  .env("HTTPS_PROXY", "some_value");
const requestBuilder = new RequestBuilder()
  .header("SOME_VALUE", "value");

const new$ = $.build$({
  commandBuilder,
  requestBuilder,
  // optional additional functions to add to `$`
  extras: {
    add(a: number, b: number) {
      return a + b;
    },
  },
});

// this command will use the env described above, but the main
// process and default `$` won't have its environment changed
await new$`deno run my_script.ts`;

// similarly, this will have the headers that were set in the request builder
const data = await new$.request("https://plugins.dprint.dev/info.json").json();

// use the extra function we defined
console.log(new$.add(1, 2));
cd(path:
| string
| URL
| ImportMeta
| Path
): void

Changes the directory of the current process.

escapeArg(arg: string): string

Escapes an argument for the shell when NOT using the template literal.

This is done by default in the template literal, so you most likely don't need this, but it may be useful when using the command builder.

For example:

const builder = new CommandBuilder()
 .command(`echo ${$.escapeArg("some text with spaces")}`);

// equivalent to this:
const builder = new CommandBuilder()
 .command(`echo 'some text with spaces'`);

// you may just want to do this though:
const builder = new CommandBuilder()
 .command(["echo", "some text with spaces"]);
stripAnsi(text: string): string

Strips ANSI escape codes from a string

commandExists(commandName: string): Promise<boolean>

Determines if the provided command exists resolving to true if the command will be resolved by the shell of the current $ or false otherwise.

commandExistsSync(commandName: string): boolean

Determines if the provided command exists resolving to true if the command will be resolved by the shell of the current $ or false otherwise.

log(...data: any[]): void

Logs with potential indentation ($.logIndent) and output of commands or request responses.

Note: Everything is logged over stderr.

logLight(...data: any[]): void

Similar to $.log, but logs out the text lighter than usual. This might be useful for logging out something that's unimportant.

logStep(firstArg: string, ...data: any[]): void

Similar to $.log, but will bold green the first word if one argument or first argument if multiple arguments.

logError(firstArg: string, ...data: any[]): void

Similar to $.logStep, but will use bold red.

logWarn(firstArg: string, ...data: any[]): void

Similar to $.logStep, but will use bold yellow.

logGroup<TResult>(action: () => TResult): TResult

Causes all $.log and like functions to be logged with indentation.

$.logGroup(() => {
  $.log("This will be indented.");
  $.logGroup(() => {
    $.log("This will indented even more.");
  });
});

const result = await $.logGroup(async () => {
  $.log("This will be indented.");
  const value = await someAsyncWork();
  return value * 5;
});
logGroup<TResult>(label: string, action: () => TResult): TResult

Causes all $.log and like functions to be logged with indentation and a label.

$.logGroup("Some label", () => {
  $.log("This will be indented.");
});
logGroup(label?: string): void

Causes all $.log and like functions to be logged with indentation.

$.logGroup();
$.log("This will be indented.");
$.logGroup("Level 2");
$.log("This will be indented even more.");
$.logGroupEnd();
$.logGroupEnd();

Note: You must call $.logGroupEnd() when using this.

It is recommended to use $.logGroup(() => { ... }) over this one as it will internally call $.logGroupEnd() even when exceptions are thrown.

logGroupEnd(): void

Ends a logging level.

Meant to be used with $.logGroup(); when not providing a function..

maybeConfirm(message: string, options?: Omit<ConfirmOptions, "message">): Promise<boolean | undefined>

Shows a prompt asking the user to answer a yes or no question.

maybeConfirm(options: ConfirmOptions): Promise<boolean | undefined>

Shows a prompt asking the user to answer a yes or no question.

confirm(message: string, options?: Omit<ConfirmOptions, "message">): Promise<boolean>

Shows a prompt asking the user to answer a yes or no question.

confirm(options: ConfirmOptions): Promise<boolean>

Shows a prompt asking the user to answer a yes or no question.

maybeSelect(options: SelectOptions): Promise<number | undefined>

Shows a prompt selection to the user where there is one possible answer.

select(options: SelectOptions): Promise<number>

Shows a prompt selection to the user where there is one possible answer.

maybeMultiSelect(options: MultiSelectOptions): Promise<number[] | undefined>

Shows a prompt selection to the user where there are multiple or zero possible answers.

multiSelect(options: MultiSelectOptions): Promise<number[]>

Shows a prompt selection to the user where there are multiple or zero possible answers.

maybePrompt(message: string, options?: Omit<PromptOptions, "message">): Promise<string | undefined>

Shows an input prompt where the user can enter any text.

maybePrompt(options: PromptOptions): Promise<string | undefined>

Shows an input prompt where the user can enter any text.

prompt(message: string, options?: Omit<PromptOptions, "message">): Promise<string>

Shows an input prompt where the user can enter any text.

prompt(options: PromptOptions): Promise<string>

Shows an input prompt where the user can enter any text.

progress(message: string, options?: Omit<ProgressOptions, "message" | "prefix">): ProgressBar

Shows a progress message when indeterminate or bar when determinate.

progress(options: ProgressOptions): ProgressBar

Shows a progress message when indeterminate or bar when determinate.

setInfoLogger(logger: (...args: any[]) => void): void

Sets the logger used for info logging.

setWarnLogger(logger: (...args: any[]) => void): void

Sets the logger used for warn logging.

setErrorLogger(logger: (...args: any[]) => void): void

Sets the logger used for error logging.

setPrintCommand(value: boolean): void

Mutates the internal command builder to print the command text by default before executing commands instead of needing to build a custom $.

For example:

$.setPrintCommand(true);
const text = "example";
await $`echo ${text}`;

Outputs:

> echo example
example
sleep(delay: Delay): Promise<void>

Sleep for the provided delay.

await $.sleep(1000); // ms
await $.sleep("1.5s");
await $.sleep("100ms");
raw(strings: TemplateStringsArray, ...exprs: any[]): CommandBuilder

Executes the command as raw text without escaping expressions.

const expr = "some   text   to   echo";
$.raw`echo {expr}`; // outputs: some text to echo
withRetries<TReturn>(opts: RetryOptions<TReturn>): Promise<TReturn>

Does the provided action until it succeeds (does not throw) or the specified number of retries (count) is hit.