Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Notebooks

Marcel Kloubert edited this page Jun 13, 2021 · 13 revisions

Notebooks

⚠️⚠️⚠️ NOTICE: This is a feature, which is currently under development! ⚠️⚠️⚠️

Since version 1.57, Visual Studio Code supports an API for custom notebooks.

Power Tools uses the .egobook extension for its own notebook files.

To create a new notebook, simple create a blank file with a .egobook extension.

Supported languages

Functions

$csv( csvData, delimiter = ';', newLine = '\n' )

Handles data as string and add a HTML tables of the data, if it returned.

// https://support.staffbase.com/hc/de/articles/360007108391-Beispiele-f%C3%BCr-CSV-Dateien
const csvData = `Username; Identifier;First name;Last name
booker12;9012;Rachel;Booker
grey07;2070;Laura;Grey
johnson81;4081;Craig;Johnson
jenkins46;9346;Mary;Jenkins
smith79;5079;Jamie;Smith`;

return $csv(csvData);  // must be returned, if it should be displayed

$delete( url, data?, headers? )

Does a HTTP DELETE request and returns the data directly, if status code is less than 400.

// body and headers are optional
const responseData = await $delete('https://api.example.com/getFoo', 'This is a string body', {
    'x-my-header1': 'tm+mk'
});

$get( url, headers? )

Does a HTTP GET request and returns the data directly, if status code is less than 400.

// headers are optional
const responseData = await $get('https://api.example.com/getFoo', {
    'x-my-header1': 'tm+mk'
});

$patch( url, data?, headers? )

Does a HTTP PATCH request and returns the data directly, if status code is less than 400.

// body and headers are optional
const responseData = await $patch('https://api.example.com/getFoo', 'This is a string body', {
    'x-my-header1': 'tm+mk'
});

$post( url, data?, headers? )

Does a HTTP POST request and returns the data directly, if status code is less than 400.

// body and headers are optional
const responseData = await $post('https://api.example.com/getFoo',
    Buffer.from('This is a binary body', 'utf8')
, {
    'x-my-header1': 'tm+mk'
});

$put( url, data?, headers? )

Does a HTTP PUT request and returns the data directly, if status code is less than 400.

// body and headers are optional
const responseData = await $put('https://api.example.com/getFoo',
    Buffer.from('This is a binary body', 'utf8')
, {
    'x-my-header1': 'tm+mk'
});

$request( method, url, ...args )

Does a HTTP request and returns an AxiosResponse.

// headers are optional
const response1 = await $request('GET', 'https://api.example.com/getFoo', {
    'x-my-header1': 'tm+mk'
});

// headers and body are optional
const response2 = await $request('POST', 'https://api.example.com/postBar', {
    'bodyProp1': 5979,
    'bodyProp2': '23979'
}, {
    'x-my-header1': 'tm+mk'
});

$require( module )

Includes a module from the extension context, what means, that you can use any module, which is shipped with the extension.

const moment = $require('moment');

const now = moment();

$setMarkdown( md )

Sets Markdown content, by converting it to HTML output.

$setMarkdown(`# My output

As GitHub markdown`);

$setHTML( html )

Sets HTML output.

$setHtml('My output as <em><strong>HTML</strong></em>');

$setText( text )

Sets text output.

$setText('My output as text');

$str( val )

Converts any value to a string, that is not (null) and not (undefined).

$str(0);  // '0'
$str(null);  // ''
$str(undefined);  // ''

$unset( name )

Unsets a value, which is stored as metadata in the notebook.

$unset('myValue');

$val( name, newValue? )

Gets or sets a value, which should be stored as metadata in the notebook.

// get value
const myValue = $val('myValue');

// set value
//
// (undefined) would unset the value
await $val('myValue', 5979);

Modules

Name Description
_ lodash
$axios axios
$fs fs-extra
$helpers vscode-helpers
$moment Moment.js
$vscode Visual Studio Code API