Options
All
  • Public
  • Public/Protected
  • All
Menu

datakit

Index

Functions

fromCsv

  • fromCsv<RecordT>(csvTextString: string, config?: ICsvInputConfig): RecordT[]
  • Deserialize CSV text to a JavaScript array. Each element of the array contains fields that match the columns from the CSV data.

    Type parameters

    • RecordT

    Parameters

    • csvTextString: string

      The CSV text to deserialize.

    • Optional config: ICsvInputConfig

    Returns RecordT[]

    Returns an array of JavaScript objects that were deserialized from the CSV text.

fromJson

  • fromJson<RecordT>(jsonTextString: string, config?: IJsonInputConfig): RecordT[]
  • Deserialize JSON text to a JavaScript array.

    Type parameters

    • RecordT

    Parameters

    • jsonTextString: string

      The JSON text to deserialize.

    • Optional config: IJsonInputConfig

    Returns RecordT[]

    Returns an array of JavaScript objects that were deserialized from the JSON text.

fromObject

  • Convert a regular JavaScript object to 'tablular data'. Each element of the matches a field from the object.

    Parameters

    • obj: any

      The JavaScript object to convert to a dataframe.

    Returns IFieldDesc[]

    Returns an array with an element describing each field.

readCsv

  • readCsv<RecordT>(filePath: string, config?: ICsvInputConfig): Promise<RecordT[]>
  • Asynchronously deserialize a CSV file to a JavaScript array. Each element of the array contains fields that match the columns from the CSV file.

    example
    
    const data = await datakit.readCsv("my-data-file.csv");
    console.log(data);
    

    const config = { dynamicTyping: true, // ... other options ... }; const data = await datakit.readCsv("my-data-file.csv", config); console.log(data);

    Type parameters

    • RecordT

    Parameters

    • filePath: string

      Path to the file to be loaded.

    • Optional config: ICsvInputConfig

    Returns Promise<RecordT[]>

    Returns a promise for the loaded data.

readCsvSync

  • readCsvSync<RecordT>(filePath: string, config?: ICsvInputConfig): RecordT[]
  • Synchronously deserialize a CSV file to a JavaScript array. Each element of the array contains fields that match the columns from the CSV file.

    example
    
    const data = datakit.readCsvSync("my-data-file.csv");
    console.log(data);
    
    example
    
    const config = {
        dynamicTyping: true,
        // ... other options ...
    };
    const data = datakit.readCsvSync("my-data-file.csv", config);
    console.log(data);
    

    Type parameters

    • RecordT

    Parameters

    • filePath: string

      Path to the file to be loaded.

    • Optional config: ICsvInputConfig

    Returns RecordT[]

    Returns the loaded data.

readFile

  • readFile(filePath: string): Promise<string>
  • Like fs.readFile but returns a promise for the file data.

    example
    
    const data = await datakit.readFile("some-data-file.txt");
    console.log(data);
    

    Parameters

    • filePath: string

      Path to the file to be loaded.

    Returns Promise<string>

    A promise that is resolved with the contents of the file.

readJson

  • readJson<RecordT>(filePath: string): Promise<RecordT[]>
  • Asynchronously deserialize a JSON file to a JavaScript array.

    example
    
    const data = await datakit.readFile("my-data-file.json");
    console.log(data);
    

    Type parameters

    • RecordT

    Parameters

    • filePath: string

      Path to the file to be loaded.

    Returns Promise<RecordT[]>

    Returns a promise for the loaded data.

readJsonSync

  • readJsonSync<RecordT>(filePath: string): RecordT[]
  • Synchronously deserialize a JSON file to a JavaScript array.

    example
    
    const data = datakit.readJsonSync("my-data-file.json");
    console.log(data);
    

    Type parameters

    • RecordT

    Parameters

    • filePath: string

      Path to the file to be loaded.

    Returns RecordT[]

    Returns the loaded data.

toCsv

  • Serialize a JavaScript array to the CSV data format. Columns in the CSV file match fields from the objects in the array.

    example
    
    const data = [ ... JavaScript array of data ... ];
    const csvData = datakit.toCsv(data);
    console.log(csvData);
    
    example
    
    const data = [ ... JavaScript array of data ... ];
    const config = {
        header: false,
        // ... other options ...
    };
    const csvData = datakit.toCsv(data, config);
    console.log(csvData);
    

    Parameters

    Returns string

    Returns a string in the CSV data format that represents the data.

toJson

  • Serialize a JavaScript array to the JSON data format.

    example
    
    const data = [ ... JavaScript array of data ... ];
    const jsonData = datakit.toJson(data);
    console.log(jsonData);
    

    Parameters

    Returns string

    Returns a string in the JSON data format that represents the data.

writeCsv

  • writeCsv(filePath: string, input: any[], config?: ICsvOutputConfig): Promise<void>
  • Asynchronously serialize a JavaScript array to a CSV file. The fields in the objects of the array become the columns in the CSV file.

    example
    
    const data = [ ... JavaScript array of data ... ];
    await datakit.writeCsv("my-data-file.csv", data);
    
    example
    const config = {
        // ... Options for serialization ...
    };
    const data = [ ... JavaScript array of data ... ];
    await datakit.writeCsv("my-data-file.csv", config);
    

    Parameters

    • filePath: string

      Path to the file to be written.

    • input: any[]
    • Optional config: ICsvOutputConfig

    Returns Promise<void>

    Returns a promise that resolves when the file has been written.

writeCsvSync

  • Synchronously serialize a JavaScript array to a CSV file. The fields in the objects of the array become the columns in the CSV file.

    example
    
    const data = [ ... JavaScript array of data ... ];
    datakit.writeCsvSync("my-data-file.csv", data);
    
    example
    
    const config = {
        // ... Options for serialization ...
    };
    const data = [ ... JavaScript array of data ... ];
    datakit.writeCsvSync("my-data-file.csv", config);
    

    Parameters

    • filePath: string

      Path to the file to be written.

    • input: any[]
    • Optional config: ICsvOutputConfig

    Returns void

writeFile

  • writeFile(filePath: string, data: string): Promise<string>
  • Like fs.writeFile but returns a promise for completion of the asynchronous file write.

    example
    
    const data = "... JavaScript string with text data ...";
    await datakit.writeFile("some-data-file.txt", data);
    

    Parameters

    • filePath: string

      Path to the file to be written.

    • data: string

      Data to be written the to file.

    Returns Promise<string>

    A promise that is resolved when the file has been written.

writeJson

  • writeJson(filePath: string, input: any[]): Promise<void>
  • Asynchronously serialize a JavaScript array to a JSON file.

    example
    
    const data = [ ... JavaScript array of data ... ];
    await datakit.writeJson("my-data-file.json", data);
    

    Parameters

    • filePath: string

      Path to the file to be written.

    • input: any[]

    Returns Promise<void>

    Returns a promise that resolves when the file has been written.

writeJsonSync

  • writeJsonSync(filePath: string, input: any[]): void
  • Synchronously serialize a JavaScript array to a JSON file.

    example
    
    const data = [ ... JavaScript array of data ... ];
    datakit.writeJsonSync("my-data-file.json", data);
    

    Parameters

    • filePath: string

      Path to the file to be written.

    • input: any[]

    Returns void

    Returns a promise that resolves when the file has been written.

Generated using TypeDoc