Skip to content
This repository was archived by the owner on Jun 13, 2021. It is now read-only.
Marcel Kloubert edited this page Feb 2, 2019 · 38 revisions

A set of useful and handy helpers.

Code Execution

Executes a line of (JavaScript) code.

demo-tools1.gif

Enter $help to open the list of available functions and modules.

Constants

$cancel

The CancellationToken object, to check the current progress state.

$cancel.isCancellationRequested

$e

Stores the content of the active text editor, if available.

$alert( $e )

$progress

The Progress object, to control the current progress state ... s. withProgress().

$progress.report({ message: 'Hello, TM!' })

Functions

$alert(msg)

Shows a (warning) popup.

$alert("Hello, TM!")

$asc(str)

Handles a value as string and returns the ASCII (codes).

$asc("T")

$beautify()

Beautifies the code in the active editor and opens the result in a new one.

The following languages are supported:

  • CSS
  • HTML
  • JavaScript
$beautify

$buff(val, enc?)

Converts a value to a Buffer, if needed.

$buff('Hello, TM!', 'utf8')

$cmd(id, ...args)

Executes a Visual Studio Code command.

$cmd("editor.action.selectAll")

$compile()

Compiles the code in the active editor and opens the result in a new one.

The following languages are supported:

  • CoffeeScript
  • LESS
$compile

$csv(data)

Handles data as string in CSV format and displays them.

$csv( $GET('https://example.com/file.csv') )

$DELETE(url, body?, headers?)

Starts a HTTP DELETE request.

$DELETE("https://example.com/users/19861222")

$emojis(search?)

Returns a list of emojis, by using an optional filter.

$emojis("heart")

$exec()

Executes the code in the currently running editor.

$exec

$full(path)

Returns a full path.

$full("dir1/subDir1_1/myFile.txt")

$GET(url, headers?)

Starts a HTTP GET request.

$GET("https://example.com/users/19790905")

$guid(version?)

Generates a GUID.

$guid

$hash(algo, val, asBlob?)

Hashes a value.

$hash("sha1", "TM+MK")

$htmldec(val)

Handles a values as string, and decodes the HTML entities.

$htmldec("5979 > 23979")

$htmlenc(val)

Handles a values as string, and encodes the HTML entities.

$htmlenc("<tm>")

$ip(version6?, timeout?)

Tries to detect the public IP address.

$ip(true)

$ip4(timeout?)

Tries to detect the public IP address (version 4).

$ip4

$ip6(timeout?)

Tries to detect the public IP address (version 6).

$ip6

$ltrim(val)

Handles data as string and trims from leading whitespaces.

$ltrim('  TM + MK   ')

$lower(val)

Handles data as string and converts to lower case characters.

$lower('tm + MK')

$md(markdown)

Handles a value as Markdown string.

$md("# Header 1\\n\\nHello, TM!")

$md5(val, asBlob?)

Hashes a value with MD5.

$md5("TM+MK")

$now(timezone?)

Returns the current time with an optional timezone.

$now("Europe/Berlin")

$PATCH(url, body?, headers?)

Starts a HTTP PATCH request.

$PATCH("https://example.com/users/19790905")

$POST(url, body?, headers?)

Starts a HTTP POST request.

$POST("https://example.com/users/19790905")

$PUT(url, body?, headers?)

Starts a HTTP PUT request.

$PUT("https://example.com/users/19790905")

$pwd(length?, allowedChars?)

Generates a password.

$pwd(64)

$r(id)

Extended require() function, which also allows to access the modules of that extension.

$r("moment").utc()

$read(file, enc?)

Reads data from a file. Relative paths will be mapped to the directory of the currently opened editor or the .vscode-powertools sub folder inside the user's home directory.

$read("myFile.txt")

$res(val, mapper?)

Resolves a value.

$res( Promise.resolve("TM"), s => s.toLowerCase() )

$rtrim(val)

Handles data as string and trims from ending whitespaces.

$ltrim('  TM + MK   ')

$sha1(val, asBlob?)

Hashes a value with SHA-1.

$sha1("TM+MK")

$sha256(val, asBlob?)

Hashes a value with SHA-256.

$sha256("TM+MK")

$sha384(val, asBlob?)

Hashes a value with SHA-384.

$sha384("TM+MK")

$sha512(val, asBlob?)

Hashes a value with SHA-512.

$sha512("TM+MK")

$trim(val)

Handles data as string and trims from leading and ending whitespaces.

$trim('  TM + MK   ')

$uglify()

Uglifies the code in the active editor and opens the result in a new one.

The following languages are supported:

  • CoffeeScript
  • CSS
  • JavaScript
  • LESS
$uglify

$unwrap(val, maxLevel?, level?)

Unwraps a value from being a function.

$unwrap(() => 5979)

$upper(val)

Handles data as string and converts to upper case characters.

$upper('tm + MK')

$utc()

Returns the current time in UTC.

$utc

$uuid(version?)

Alias for $guid.

$uuid

$write(file, data, enc?)

Writes data to a file. Relative paths will be mapped to the directory of the currently opened editor or the .vscode-powertools sub folder inside the user's home directory.

$write("myFile.txt", "Data to write. Can be a string, stream or buffer")

Modules

Name Description Example
_ lodash _.isString(5979)
$fs fs-extra $fs.existsSync("/path/to/something")
$h helpers $h.normalizeString("TM+MK")
$m Moment.js $m()
$o opn $o("https://e-go-digital.com")
$vs Visual Studio Code API $vs.commands.getCommands

Key bindings

If you would like to define key bindings for quick access, you can use the following commands:

Name Description
ego.power-tools.codeExecution Opens the input box for executing JavaScript code.

Clone this wiki locally