Stdlib
Core Utilities
Imported from the upstream Vibescript examples at stdlib/core_utilities.vibe and runnable in the browser today.
Source
stdlib/core_utilities.vibe
# vibe: 0.2
def run
parsed = JSON.parse("{\"id\":\"p-1\",\"score\":10}")
event_id = uuid
token = random_id(8)
parsed_time = Time.parse("2024-05-01 10:30:00", in: "UTC")
{
json_id: parsed.fetch("id"),
json_score: parsed.fetch("score"),
json_encoded: JSON.stringify({ id: parsed.fetch("id"), score: parsed.fetch("score") }),
regex_match: Regex.match("ID-[0-9]+", "ID-12 ID-34"),
regex_replace: Regex.replace("ID-12 ID-34", "ID-[0-9]+", "X"),
regex_replace_all: Regex.replace_all("ID-12 ID-34", "ID-[0-9]+", "X"),
uuid_length: event_id.length,
uuid_has_dash: event_id.include?("-"),
random_length: token.length,
to_int: to_int("42"),
to_float: to_float("1.25"),
parsed_time: parsed_time.format("2006-01-02T15:04:05Z07:00")
}
end
Output
Press run to execute run from this example.