sorbet
Sorbet This is the main module for Sorbet. It contains the types and functions for the Sorbet language.
Sorbet is a simple key-value configuration format with support for multi-line values using continuation lines.
Example:
key1 => value1
key2 => first line
> second line
> third line
Functions
pub fn format_dict(map: Dict(String, String)) -> String
Format a dictionary into the sorbet format.
Takes a dictionary of string keys and string values and converts it to a string in Sorbet format. Multi-line values are properly formatted with continuation lines.
Example
sorbet.format_dict(dict.from_list([
#("key1", "value1"),
#("key2", "line1\nline2")
]))
// Returns "key1 => value1\nkey2 => line1\n> line2"
pub fn format_key_value(key: String, value: String) -> String
Format a key and value into the sorbet format. If the value contains newlines, they will be formatted as continuation lines.
Examples
sorbet.format_key_value("key", "value")
// Returns "key => value"
sorbet.format_key_value("key", "line1\nline2")
// Returns "key => line1\n> line2"
pub fn parse(contents: String) -> Dict(String, String)
Parse a string in Sorbet format into a dictionary.
The format follows these rules:
- Each key-value pair is on a separate line with the format “key => value”
- Multi-line values use continuation lines starting with “>”
- Empty lines are ignored
- Whitespace around keys and values is trimmed
Examples
sorbet.parse("key => value")
// Returns a dictionary with {"key": "value"}
sorbet.parse("key => first line\n> second line")
// Returns a dictionary with {"key": "first line\nsecond line"}