API Reference

API Reference

Complete reference for all built-in funcs in Flowa.

Type Functions

FunctionPurposeExample
type(x)Get type of valuetype(42)"number"
len(x)Lengthlen("hello")5
tonumber(s)Convert to numbertonumber("42")42
tostring(x)Convert to stringtostring(42)"42"
str(x)Alias for tostringstr(42)"42"
int(x)Alias for tonumberint("42")42

String Functions

FunctionPurposeExample
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"]
join(arr, sep)Join with separatorjoin(["a", "b"], "-")"a-b"
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 Functions

FunctionPurposeAliases
sqrt(x)Square root
power(x, y)Exponentiationpow(x, y)
floor(x)Round down
ceil(x)Round up
round(x)Round nearest
abs(x)Absolute value
min(a, b)Minimum
max(a, b)Maximum

Array Functions

FunctionPurposeExample
push(arr, x)Add elementpush([1,2], 3)[1,2,3]
pop(arr)Remove lastpop([1,2,3])3
shift(arr)Remove firstshift([1,2,3])1
reverse(arr)Reverse arrayreverse([1,2,3])[3,2,1]
sort(arr)Sort arraysort([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

Hash Functions

FunctionPurposeExample
keys(hash)Get all keyskeys({"a": 1, "b": 2})["a", "b"]
values(hash)Get all valuesvalues({"a": 1, "b": 2})[1, 2]
key in hashCheck key exists"name" in usertrue

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

Time Module

FunctionPurpose
time.now_ms()Returns current timestamp in milliseconds
time.since_s(reference_ms)Returns elapsed time in seconds since the reference timestamp

Test Module

FunctionPurpose
test(description, function)Run a test case with description
assert(condition, message)Assert that a condition is true, throws error if false

Keywords

Reserved keywords:

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

Next Steps