Skip to content
Lukas Dattenberger edited this page Feb 8, 2022 · 1 revision

Namespace: Csv

Table of contents

Type aliases

Variables

Functions

Type aliases

CsvEncoding

Ƭ CsvEncoding: "utf8" | "windows1252"

Defined in

lib/csv.ts:26

Variables

defaultParseOptions

defaultParseOptions: Object

Type declaration

Name Type
columns boolean
delimiter string
skip_empty_lines boolean

Defined in

lib/csv.ts:14


defaultWriteOptions

defaultWriteOptions: Object

Type declaration

Name Type
delimiter string
quoted_empty boolean
quoted_string boolean

Defined in

lib/csv.ts:20

Functions

readCSV

readCSV<T, P>(fileName, encoding?, options?): P extends { columns: false } ? Primitives[][] : T[]

Read a CSV file and return an array of objects. The Key Names a taken from the first line of the CSV.
Test

Type parameters

Name Type
T extends CsvRow<T>
P extends Options

Parameters

Name Type Default value Description
fileName string undefined
encoding CsvEncoding "utf8"
options? P & Options undefined Options used to parse the CSV file. Provided keys override the default ones.
{@link parse.Options}, defaultParseOptions

Returns

P extends { columns: false } ? Primitives[][] : T[]

Defined in

lib/csv.ts:73


readCSVAsync

readCSVAsync<T>(fileName, options?): Promise<T[]>

deprecated

Type parameters

Name Type
T extends CsvRow<T>

Parameters

Name Type
fileName string
options? Options

Returns

Promise<T[]>

Defined in

lib/csv.ts:94


toMap

toMap<T, K>(records, keyName): Map<T[K], T>

Create a map from an array of Objects. The key is taken from the objects based on the provided keyname.

Type parameters

Name Type
T T
K extends string | number | symbol

Parameters

Name Type Description
records T[]
keyName K Schlüssel -> Optimalerweise die Artikelnummer

Returns

Map<T[K], T>

Defined in

lib/csv.ts:52


writeCSV

writeCSV(inputArray, path, deleteCsvIfEmpty, encoding?, options?): Promise<void>

Writes an array of arrays / rows as a csv file.

Parameters

Name Type Description
inputArray Primitives[][] Array of Rows. Please make sure, that all rows have the same amount of elements.
path string Where to write the csv file?
deleteCsvIfEmpty boolean Delete any existing csv file, if the provided array has a length of 0. Alternatively the function will throw an exception if you provide an empty inputArray.
encoding? CsvEncoding
options? Options -

Returns

Promise<void>

Defined in

lib/csv.ts:146


writeCSVFromArray

writeCSVFromArray<T>(inputArray, path, deleteCsvIfEmpty?, encoding?, options?): Promise<void>

/** Writes an array of objets as a csv file. This function extracts the column names from the key of the first object. The Data is gathered from all Objects including the frist one.

Type parameters

Name Type
T extends CsvRow<T>

Parameters

Name Type Default value Description
inputArray Required<T>[] undefined Array of Objects.
path string undefined writeCSV
deleteCsvIfEmpty boolean false writeCSV
encoding? CsvEncoding undefined
options? Options undefined

Returns

Promise<void>

Defined in

lib/csv.ts:128


writeCSVFromMap

writeCSVFromMap<T>(inputMap, path, deleteCsvIfEmpty, encoding?, options?): Promise<void>

Writes a Map of objets to a csv file. This function extracts the column names from the key of the first object. The Data is gathered from all Objects including the frist one.

Type parameters

Name Type
T extends CsvRow<T>

Parameters

Name Type Description
inputMap Map<any, Required<T>> Map of Objects.
path string writeCSV
deleteCsvIfEmpty boolean writeCSV
encoding? CsvEncoding -
options? Options -

Returns

Promise<void>

Defined in

lib/csv.ts:104

dattelib

Namespaces

Clone this wiki locally