Appearance
csv
Type Aliases
TParseEachLineCallback
ts
type TParseEachLineCallback = (line) => void;Defined in: src/csv/index.ts:1
Parameters
| Parameter | Type |
|---|---|
line | any[] |
Returns
void
Functions
parse()
ts
function parse(input, output?): any[][];Defined in: src/csv/index.ts:39
Parses a CSV string into a 2D array.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
input | string | undefined | Raw CSV string. |
output | any[][] | [] | Optional output array to push rows into. |
Returns
any[][]
Array of parsed rows (arrays of values).
Example
ts
parse('1;2;3\n4;5;6'); // => [[1, 2, 3], [4, 5, 6]]parseEachLine()
ts
function parseEachLine(input, callback): void;Defined in: src/csv/index.ts:13
Parses a CSV string and calls callback for each parsed line. Columns are separated by ; and URI-decoded, then JSON-parsed where possible.
Parameters
| Parameter | Type | Description |
|---|---|---|
input | string | Raw CSV string. |
callback | TParseEachLineCallback | Called with an array of parsed column values for each line. |
Returns
void
Example
ts
parseEachLine('1;2;3\n4;5;6', (line) => console.log(line));
// => [1, 2, 3], then [4, 5, 6]stringify()
ts
function stringify(data): string;Defined in: src/csv/index.ts:52
Serializes a 2D array into a CSV string. Columns are JSON-encoded and URI-encoded, joined by ;, rows joined by \n.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | any[][] | 2D array of values to serialize. |
Returns
string
Serialized CSV string.
Example
ts
stringify([[1, 2, 3], [4, 5, 6]]); // => '1;2;3\n4;5;6'