shape-runtime 0.3.0

Bytecode compiler, builtins, and runtime infrastructure for Shape
Documentation
/// @module std::core::csv
/// CSV Parsing and Serialization
///
/// Parse CSV text into structured data and serialize data back to CSV format.
///
/// # Example
///
/// ```shape
/// use std::core::csv
///
/// let rows = csv.parse("name,age\nAlice,30\nBob,25")
/// let records = csv.parse_records("name,age\nAlice,30")
/// let text = csv.stringify([["a", "b"], ["1", "2"]])
/// ```

/// Parse CSV text into an array of rows (each row is an array of strings).
///
/// # Arguments
///
/// * `text` - CSV text to parse
///
/// # Returns
///
/// Array of rows, where each row is an array of field strings.
pub builtin fn parse(text: string) -> Array<Array<string>>;

/// Parse CSV text using the header row as keys, returning an array of hashmaps.
///
/// # Arguments
///
/// * `text` - CSV text to parse (first row is headers)
///
/// # Returns
///
/// Array of hashmaps with header keys and field values.
pub builtin fn parse_records(text: string) -> Array<HashMap<string, string>>;

/// Convert an array of rows to a CSV string.
///
/// # Arguments
///
/// * `data` - Array of rows, each row is an array of field strings
/// * `delimiter` - Field delimiter character (default: comma)
///
/// # Returns
///
/// CSV-formatted string.
pub builtin fn stringify(data: Array<Array<string>>, delimiter: string) -> string;

/// Convert an array of hashmaps to a CSV string with headers.
///
/// # Arguments
///
/// * `data` - Array of records (hashmaps with string keys and values)
/// * `headers` - Explicit header order (default: keys from first record)
///
/// # Returns
///
/// CSV-formatted string with header row.
pub builtin fn stringify_records(data: Array<HashMap<string, string>>, headers: Array<string>) -> string;

/// Read and parse a CSV file into an array of rows.
///
/// # Arguments
///
/// * `path` - Path to the CSV file
///
/// # Returns
///
/// `Ok(rows)` on success, `Err(message)` on failure.
pub builtin fn read_file(path: string) -> Result<Array<Array<string>>, string>;

/// Check if a string is valid CSV.
///
/// # Arguments
///
/// * `text` - String to validate as CSV
///
/// # Returns
///
/// `true` if the string is valid CSV.
pub builtin fn is_valid(text: string) -> bool;