csv

Production-ready CSV parser and stringifier handling RFC 4180 rules

0 downloads owners: imabd645 repository

Install

ez install csv

Dependencies (1.0.0)

PackageRange
No dependencies.

Readme

CSV Library

A robust CSV (Comma-Separated Values) parser and stringifier for EZ, fully supporting RFC 4180 rules, including:

Installation

This library is included in the standard ezlib packages. Import it via:

use "csv"

Functions

parse(csvString)

Converts a CSV string into an Array of Dicts. The first row of the CSV is used as the keys for each dictionary.

dataStr = "name,age\nAlice,30\nBob,25"
rows = csv.parse(dataStr)
out rows[0]["name"] # "Alice"

stringify(dataArray)

Converts an Array of Dicts back into a CSV string. Automatically escapes fields that contain quotes, commas, or newlines.

data = [
    { "name": "Alice", "quote": "She said, \"Hello!\"" },
    { "name": "Bob", "quote": "No quote" }
]
csvStr = csv.stringify(data)
# name,quote
# Alice,"She said, ""Hello!"""
# Bob,No quote

read(filePath)

Reads a CSV file directly from disk and parses it into an Array of Dicts.

data = csv.read("data.csv")

write(filePath, dataArray)

Writes an Array of Dicts directly to a CSV file.

success = csv.write("output.csv", data)

Versions

VersionSizeDownloadsPublished
1.0.0 5.7 KB 0 1 hour ago

Integrity

sha256  c5980cb9c686ba20ccacbc9239403a042402c3851bc365efa81124271df2c9dd