About b.js

b.JS provides additional functions and prototypes for javascript To use b.JS in your project, just add the following script reference to your project:

basis functions #

typ |  wenn |  assert |  allEqual |  byVal | 

clsBasis functions #

clsDOM functions #

custom Elements #

basis functions

functions that enhance the functionality of javascript for easier development and are not directly related to the user experience.

typ ()

typ (variable) returns the type of a variable as a string. The following types are recognized: list, div, dict, str, int, float, bool, null, undefined and functions

wenn ()

wenn (condition, trueValue, falseValue) is a short hand notation / better readability for 'return condition ? trueValue : falseValue';

assert ()

assert (condition, message) throws an error if the condition is false

allEqual ()

allEqual (...values) returns true if all values are equal

byVal ()

byVal (data) creates a hard copy of a variable (instead of just creating a reference in case of list and dictionaries). It is equivalent to structuredClone and mimics the 'byVal' operater in VBA, hence the name

clsBasis

function that will in general directly affect the user experience.

download ()

download (fileContent, filename, mimeType = 'text/plain;charset=utf-8') triggers a download of a file with the specified content and filename. The mimeType can be specified, default is 'text/plain;charset=utf-8'.

upload ()

upload (multiple=false, readAs = 'text') triggers a file upload dialog and returns a Promise of a listof dictionaries [{file, content}, {...}, .... ]. If multiple is true, multiple files can be selected.

debounce ()

debounce (func, delay) delays a function call.

formatBracketText ()

formatBracketText (text, options = {}) Formats text with proper bracket indentation.

formatTagText ()

formatTagText (text, options = {}) Formats text with proper HTML tag indentation.

popup ()

popup (header, message) creates a pop-up window with a header and message. The pop-up can be closed by clicking the close button, clicking outside the pop-up, or pressing the Escape key.

clsDOM

functions that will in general directly affect the user experience. See clsDOM  for more details

AutoFill ()

AutoFill (listOfDictionaries, elementId, config) Modifies your HTML page by filling in the values of the provided list of dictionaries.
1) Reads div(elementId).innerHTML as template
2) Clears div(elementId).innerHTML = ''
3) Fills everything in one pass by replacing {{key}} with the corresponding value from each dictionary
Options:
- append: boolean, if true, appends to existing content instead of clearing it first

DownloadHTML ()

DownloadHTML (filename = 'document.html') Downloads the current HTML document as a file with the specified filename.

ExposeHTML ()

ExposeHTML (config) Exposes the HTML of a given element (div, script) in a textarea, allowing for easy viewing of its content. The function takes a configuration object that specifies the div to expose, the div to append the textarea to, and various options for formatting and behavior.

RemoveWithClass ()

RemoveWithClass (className) Removes all elements from the DOM that have the specified class name.

Custom Elements

custom HTML elements that can be used in your project.

SelectionPill ()

SelectionPill () creates a selection of options in the form of "pills" (buttons). The color of the selection-pill can be customized using CSS variables. You can also use your custom colors