# file-utils

Browser utilities for triggering file downloads.

---

## Functions

### `downloadFile(name: string, content: string): void`

Triggers a browser download of a plain-text file.

| Parameter | Description |
|-----------|-------------|
| `name` | The filename (e.g. `"data.txt"`) |
| `content` | The text content of the file |

Creates a hidden `<a>` element, sets its `href` to a data URL, appends it to the DOM, clicks it, then removes it.

```typescript
downloadFile("notes.txt", "Hello, world!");
```

---

### `downloadCSVRows<R extends Array<unknown>>(name: string, rows: R[]): void`

Downloads a CSV file built from row arrays. Each row is joined with commas; rows are joined with `\r\n`.

```typescript
downloadCSVRows("data.csv", [
    ["name", "age"],
    ["Alice", 30],
    ["Bob", 25],
]);
// → name,age\r\nAlice,30\r\nBob,25
```

---

### `downloadCSVColumns<C extends ArrayLike<unknown>>(name: string, columns: C[]): void`

Downloads a CSV file built from column arrays. Columns are transposed into rows. Columns may have different lengths — shorter columns are padded with empty strings.

If `columns` is empty, an empty file is downloaded.

```typescript
downloadCSVColumns("data.csv", [
    ["Alice", "Bob"],      // name column
    [30, 25],              // age column
]);
// → Alice,30\r\nBob,25
```

---

## Example

```typescript
import { downloadCSVRows, downloadCSVColumns } from "./file-utils";

// Row-oriented export
downloadCSVRows("report.csv", [
    ["id", "value"],
    [1, 42],
    [2, 99],
]);

// Column-oriented export (columns can have different lengths)
downloadCSVColumns("report.csv", [
    ["id", 1, 2, 3],
    ["score", 10, 20],   // shorter column — padded with ""
]);
```
