import { type $BuiltInProperties } from "https://deno.land/x/dax@0.33.0/mod.ts";
Properties
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.
Helper function for creating path references, which provide an easier way for
working with paths, directories, and files on the file system. Also, a re-export
of deno_std's path
module as properties on this object.
The function creates a new PathRef
from a path or URL string, file URL, or for the current module.
Methods
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();
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));
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"]);
Determines if the provided command exists resolving to true
if the command
will be resolved by the shell of the current $
or false otherwise.
Determines if the provided command exists resolving to true
if the command
will be resolved by the shell of the current $
or false otherwise.
Logs with potential indentation ($.logIndent
)
and output of commands or request responses.
Note: Everything is logged over stderr.
Similar to $.log
, but logs out the text lighter than usual. This
might be useful for logging out something that's unimportant.
Similar to $.log
, but will bold green the first word if one argument or
first argument if multiple arguments.
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;
});
Causes all $.log
and like functions to be logged with indentation and a label.
$.logGroup("Some label", () => {
$.log("This will be indented.");
});
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.
Ends a logging level.
Meant to be used with $.logGroup();
when not providing a function..
Shows a prompt asking the user to answer a yes or no question.
Shows a prompt asking the user to answer a yes or no question.
Shows a prompt asking the user to answer a yes or no question.
Shows a prompt asking the user to answer a yes or no question.
Shows a prompt selection to the user where there is one possible answer.
Shows a prompt selection to the user where there is one possible answer.
Shows a prompt selection to the user where there are multiple or zero possible answers.
Shows a prompt selection to the user where there are multiple or zero possible answers.
Shows an input prompt where the user can enter any text.
Shows an input prompt where the user can enter any text.
Shows an input prompt where the user can enter any text.
Shows an input prompt where the user can enter any text.
Shows a progress message when indeterminate or bar when determinate.
Shows a progress message when indeterminate or bar when determinate.
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 for the provided delay.
await $.sleep(1000); // ms
await $.sleep("1.5s");
await $.sleep("100ms");
Executes the command as raw text without escaping expressions.
const expr = "some text to echo";
$.raw`echo {expr}`; // outputs: some text to echo
Does the provided action until it succeeds (does not throw)
or the specified number of retries (count
) is hit.