API Reference

API Reference

Complete reference for all built-in funcs in Flowa.

Type funcs

funcDescriptionExample
type(x)Get type of valuetype(42)"number"
len(x)Get lengthlen("hello")5
tonumber(s)Convert to numbertonumber("42")42
tostring(x)Convert to stringtostring(42)"42"

String funcs

funcDescriptionExample
upper(s)Convert to uppercaseupper("hello")"HELLO"
lower(s)Convert to lowercaselower("WORLD")"world"
substring(s, start, end)Extract substringsubstring("hello", 0, 3)"hel"
contains(s, substr)Check if containscontains("hello", "ell")true
trim(s)Remove whitespacetrim(" hi ")"hi"
replace(s, old, new)Replace textreplace("hi", "i", "o")"ho"
split(s, delim)Split into arraysplit("a,b,c", ",")["a","b","c"]
startsWith(s, p)Check prefixstartsWith("abc", "a")true
endsWith(s, suf)Check suffixendsWith("abc", "c")true
charAt(s, i)Get char at indexcharAt("abc", 0)"a"

Math funcs

funcDescriptionExample
sqrt(x)Square rootsqrt(16)4
power(x, y)Exponentiationpower(2, 8)256
floor(x)Round downfloor(3.7)3
ceil(x)Round upceil(3.2)4
round(x)Round nearestround(3.5)4
abs(x)Absolute valueabs(-5)5
min(a, b)Minimummin(10, 5)5
max(a, b)Maximummax(10, 5)10

Array funcs

funcDescriptionExample
push(arr, x)Add to endpush([1,2], 3)[1,2,3]
pop(arr)Remove lastpop([1,2,3])3
shift(arr)Remove firstshift([1,2,3])1
reverse(arr)Reversereverse([1,2,3])[3,2,1]
sort(arr)Sortsort([3,1,2])[1,2,3]
slice(arr, start, end)Extract portionslice([1,2,3,4], 1, 3)[2,3]
includes(arr, x)Check containsincludes([1,2,3], 2)true
indexOf(arr, x)Find indexindexOf([1,2,3], 2)1
join(arr, sep)Join arrayjoin(["a","b"], ",")"a,b"

I/O funcs

funcDescription

System Functions

FunctionPurpose
exit(code)Terminate program
sleep(ms)Sleep for milliseconds
random()Random number (0-100)
print(s)Print to stdout

Error Handling (Result)

FunctionPurpose
Ok(val)Create success result
Err(val)Create error result
isOk(res)Check if success
isErr(res)Check if error
unwrap(res)Get value or panic

File System Module (fs)

funcDescription
fs.readFile(path)Read file contents
fs.writeFile(path, content)Write to file
fs.appendFile(path, content)Append to file
fs.exists(path)Check if file exists

JSON Module

funcDescription
json.stringify(obj)Convert to JSON string
json.parse(str)Parse JSON string

Authentication Module (auth)

funcDescription
auth.hash(password)Hash password with bcrypt
auth.verify(password, hash)Verify password

JWT Module

funcDescription
jwt.sign(payload)Create JWT token
jwt.verify(token)Verify token validity
jwt.decode(token)Decode token payload

Email Module (mail)

funcDescription
mail.send(to, subject, body)Send email via SMTP

SQLite Module

funcDescription
sqlite.open(path)Open/create database
sqlite.exec(db, sql)Execute SQL statement
sqlite.query(db, sql)Execute SELECT query
sqlite.close(db)Close database

HTTP Module

funcDescription
http.createServer()Create HTTP server
server.on(method, path, handler)Add route handler
server.listen(port)Start listening
http.get(url)Make GET request
http.post(url, data)Make POST request

Cron Module

funcDescription
cron.schedule(expr, fn)Schedule periodic task

Logging Module

funcDescription
log.info(msg)Info level log
log.warn(msg)Warning level log
log.error(msg)Error level log
log.debug(msg)Debug level log

OS Module

funcDescription

| os.exec(cmd) | Execute shell command | | os.cwd() | Get current directory | | os.chdir(path) | Change directory | | os.platform() | Get platform name | | os.arch() | Get architecture |

Environment Variables

Access via env object:

let value = env.VARIABLE_NAME;
let api_key = env.API_KEY;

Operators

Arithmetic

  • + Addition
  • - Subtraction
  • * Multiplication
  • / Division
  • % Modulo

Comparison

  • == Equal
  • != Not equal
  • < Less than
  • <= Less than or equal
  • > Greater than
  • >= Greater than or equal

Logical

  • && Logical AND
  • || Logical OR
  • ! Logical NOT

Keywords

Reserved keywords:

let, func, if, else, while, for, return, 
true, false, null, break, continue

Next Steps