Library

TB comes with 20 libraries, built into the app. Bring one in with import, then use its functions with a dot.

import ioc

let note = "Beacon to hxxp://evil[.]example[.]com from 203.0.113.9"
let found = ioc.extract(note)
say(found.urls, found.ips)

Core

Everyday building blocks: numbers, text, dates, randomness, patterns and the computer you're on.

Files and data

Read and write files, JSON and CSV.

Security (SOC)

Parse logs, detect attacks, pull out and defang indicators, hash and decode, and report.

Network and intel

IP and CIDR maths, port checks, web requests and threat-intelligence lookups.

Desktop GUI

Windows, buttons, tables, menus and dialogs.

Testing

Checks for your own programs, run with tb test.

Built in, no import needed

These functions are always there, and every text, list, map and number has methods you call with a dot, like "hi".upper() or names.sort().

say(...)Show values on the screen, with spaces between them.
ask(prompt?) -> textShow prompt, wait for the person to type, and give back what they typed.
len(value) -> numberHow many letters (text), items (list) or keys (map).
str(value) -> textThe value as text.
num(text) -> numberThe text as a number, like num("42").
range(end) / range(start, end, step?) -> listA list of whole numbers from start up to (not including) end.
push(list, value) -> listAdd value to the end of the list.
care(name?)Show a kind message.
type(value) -> textOne of: number, text, bool, nil, list, map, function, module.
keys(map) -> listThe map's keys, in order.
int(value) -> numberThe whole-number part (3.9 gives 3). Text is turned into a number first.
round(number, digits?) -> numberRounded to digits after the dot (default 0). 2.5 rounds to 3.
min(list) / min(a, b, ...) -> valueThe smallest value.
max(list) / max(a, b, ...) -> valueThe biggest value.
sum(list) -> numberAll the numbers in the list added up.
sorted(list) -> listA new sorted list (all numbers or all text).
exit(code?)Stop the program now. 0 (the default) means all went well.

Methods on text

.chars() -> listA list of the text's letters.
.contains(part) -> boolTrue if part appears in the text.
.ends_with(part) -> boolTrue if the text ends with part.
.find(part) -> numberWhere part first appears (0 is the start), or -1.
.is_number() -> boolTrue if num() could turn this text into a number.
.len() -> numberHow many letters the text has.
.lines() -> listThe text cut into its lines.
.lower() -> textThe text in small letters.
.repeat(n) -> textThe text n times in a row.
.replace(old, new) -> textThe text with every old swapped for new.
.slice(start, end?) -> textThe letters from start up to (not including) end. Negative counts from the end.
.split(sep?) -> listCut the text at every sep. With no sep, cut at spaces.
.starts_with(part) -> boolTrue if the text begins with part.
.to_number() -> numberThe text as a number (like num()).
.trim() -> textThe text without spaces, tabs or newlines at the start and end.
.upper() -> textThe text in CAPITAL letters.

Methods on lists

.contains(value) -> boolTrue if the list has value in it.
.copy() -> listA new list with the same items.
.each(fn) -> nilCall fn(item) for every item.
.filter(fn) -> listA new list of the items where fn(item) is true.
.first() -> valueThe first item, or nil if the list is empty.
.index_of(value) -> numberThe position of value in the list, or -1.
.insert(position, value) -> listPut value at position, moving the rest along (changes the list).
.is_empty() -> boolTrue if the list has no items.
.join(sep?) -> textAll the items as one text, with sep between them.
.last() -> valueThe last item, or nil if the list is empty.
.len() -> numberHow many items the list has.
.map(fn) -> listA new list of fn(item) for every item.
.max() -> valueThe biggest item.
.min() -> valueThe smallest item.
.pop() -> valueTake the last item off the list (changes it) and give it back.
.push(value) -> listAdd value to the end (changes the list) and give the list back.
.reduce(fn, start) -> valueCombine the items: fn(fn(start, first), second) and so on.
.remove_at(position) -> valueTake out the item at position (changes the list) and give it back.
.reverse() -> listA new list in the opposite order.
.slice(start, end?) -> listA new list of the items from start up to (not including) end.
.sort() -> listA new sorted list (all numbers or all text).
.sort_by(fn) -> listA new list sorted by what fn(item) gives back.
.sum() -> numberAll the numbers added up.
.unique() -> listA new list without repeats (first ones kept).

Methods on maps

.copy() -> mapA new map with the same keys and values.
.get(key, default?) -> valueThe value for key, or default (nil) if it's missing.
.has(key) -> boolTrue if the map has this key.
.is_empty() -> boolTrue if the map has no keys.
.items() -> listA list of [key, value] pairs.
.keys() -> listThe map's keys, in order.
.len() -> numberHow many keys the map has.
.merge(other) -> mapA new map with both maps' keys (other wins).
.remove(key) -> valueTake key out of the map (changes it); gives back its value, or nil.
.set(key, value) -> mapPut value under key (changes the map) and give the map back.
.values() -> listThe map's values, in order.

Methods on numbers

.abs() -> numberThe number without its minus sign.
.ceil() -> numberThe whole number at or above it.
.floor() -> numberThe whole number at or below it.
.round(digits?) -> numberRounded to digits after the dot (default 0). 2.5 rounds to 3.
.to_text() -> textThe number as text (like str()).