mirror of
https://github.com/bearlanguageorg/bear.git
synced 2026-08-26 14:57:18 +00:00
More buildins and vscode exstention <CO-AUthored, ai>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
// crypto.vr — hashing and encoding (part of the VuurRaaf stdlib).
|
||||
//
|
||||
// import crypto
|
||||
// println(crypto.sha256("hello"))
|
||||
// println(crypto.md5("hello"))
|
||||
// println(crypto.base64_encode("hello")) // aGVsbG8=
|
||||
// println(crypto.base64_decode("aGVsbG8="))
|
||||
|
||||
fn sha256(s) {
|
||||
return sha256(s)
|
||||
}
|
||||
|
||||
fn md5(s) {
|
||||
return md5(s)
|
||||
}
|
||||
|
||||
fn base64_encode(s) {
|
||||
return base64_encode(s)
|
||||
}
|
||||
|
||||
fn base64_decode(s) {
|
||||
return base64_decode(s)
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// csv.vr — comma-separated values parsing (part of the VuurRaaf stdlib).
|
||||
//
|
||||
// import csv
|
||||
// let rows = csv.parse("name,age\namy,30\nbob,41")
|
||||
// // rows == [["name", "age"], ["amy", "30"], ["bob", "41"]]
|
||||
// println(rows[1][0]) // amy
|
||||
//
|
||||
// parse returns an array of rows; each row is an array of cell strings.
|
||||
// Quoted fields, embedded commas and newlines are handled.
|
||||
|
||||
fn parse(s) {
|
||||
return csv_parse(s)
|
||||
}
|
||||
+23
@@ -21,3 +21,26 @@ fn post(url, data) {
|
||||
fn get_text(url) {
|
||||
return http_get(url).body
|
||||
}
|
||||
|
||||
// request sends any method with custom headers (a {name: value} struct) and
|
||||
// a timeout in milliseconds, and returns {status, body}. A timeout <= 0 uses
|
||||
// the default (30s). Network failures throw; HTTP errors are normal responses.
|
||||
fn request(method, url, data, headers, timeout_ms) {
|
||||
return http_req(method, url, data, headers, timeout_ms)
|
||||
}
|
||||
|
||||
fn get_with_headers(url, headers) {
|
||||
return http_req("GET", url, "", headers, 0)
|
||||
}
|
||||
|
||||
fn post_with_headers(url, data, headers) {
|
||||
return http_req("POST", url, data, headers, 0)
|
||||
}
|
||||
|
||||
fn get_timeout(url, timeout_ms) {
|
||||
return http_req("GET", url, "", {}, timeout_ms)
|
||||
}
|
||||
|
||||
fn post_timeout(url, data, timeout_ms) {
|
||||
return http_req("POST", url, data, {}, timeout_ms)
|
||||
}
|
||||
|
||||
@@ -73,3 +73,23 @@ fn env(name) {
|
||||
fn exec(cmd) {
|
||||
return build_exec(cmd)
|
||||
}
|
||||
|
||||
// ext returns the file extension including the dot ("file.txt" -> ".txt").
|
||||
fn ext(path) {
|
||||
return path_ext(path)
|
||||
}
|
||||
|
||||
// abs converts a path to an absolute one.
|
||||
fn abs(path) {
|
||||
return path_abs(path)
|
||||
}
|
||||
|
||||
// rel returns path relative to base ("a/b/c.txt" relative to "a" -> "b/c.txt").
|
||||
fn rel(path, base) {
|
||||
return path_rel(path, base)
|
||||
}
|
||||
|
||||
// exec_full runs a shell command and returns {code, stdout, stderr}.
|
||||
fn exec_full(cmd) {
|
||||
return exec_full(cmd)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// regex.vr — regular expressions (part of the VuurRaaf stdlib).
|
||||
//
|
||||
// import regex
|
||||
// if regex.match(r"^[a-z]+$", "hello") {
|
||||
// println("all lowercase")
|
||||
// }
|
||||
// for m in regex.find_all(r"\d+", "a1b22c333") {
|
||||
// println(m) // "1", "22", "333"
|
||||
// }
|
||||
//
|
||||
// Patterns use RE2 syntax (no backreferences). Invalid patterns throw and
|
||||
// can be caught with try/catch.
|
||||
|
||||
fn is_match(pattern, s) {
|
||||
return regex_match(pattern, s)
|
||||
}
|
||||
|
||||
// find_all returns an array of every substring that matches the pattern.
|
||||
fn find_all(pattern, s) {
|
||||
return regex_find_all(pattern, s)
|
||||
}
|
||||
|
||||
// replace substitutes every match with `repl`.
|
||||
fn replace(pattern, s, repl) {
|
||||
return regex_replace(pattern, s, repl)
|
||||
}
|
||||
|
||||
fn split(pattern, s) {
|
||||
return regex_split(pattern, s)
|
||||
}
|
||||
+23
@@ -34,3 +34,26 @@ fn date(t) {
|
||||
fn clock(t) {
|
||||
return format_time(t, "HH:mm:ss")
|
||||
}
|
||||
|
||||
// weekday(t) returns the day of the week, e.g. "Mon", "Tue", ... "Sun".
|
||||
fn weekday(t) {
|
||||
return weekday(t)
|
||||
}
|
||||
|
||||
// --- date arithmetic (all values are Unix epoch seconds) ---
|
||||
|
||||
fn add_seconds(t, n) {
|
||||
return t + n
|
||||
}
|
||||
|
||||
fn add_minutes(t, n) {
|
||||
return t + n * 60
|
||||
}
|
||||
|
||||
fn add_hours(t, n) {
|
||||
return t + n * 3600
|
||||
}
|
||||
|
||||
fn add_days(t, n) {
|
||||
return t + n * 86400
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user