turbocommons-ts
Version:
General purpose library that implements frequently used and generic software development tasks
114 lines (113 loc) • 5.28 kB
TypeScript
/**
* TurboCommons is a general purpose and cross-language library that implements frequently used and generic software development tasks.
*
* Website : -> https://turboframework.org/en/libs/turbocommons
* License : -> Licensed under the Apache License, Version 2.0. You may not use this file except in compliance with the License.
* License Url : -> http://www.apache.org/licenses/LICENSE-2.0
* CopyRight : -> Copyright 2015 Edertone Advanded Solutions (08211 Castellar del Vallès, Barcelona). http://www.edertone.com
*/
import { TableObject } from './TableObject';
/**
* CSV data abstraction
*/
export declare class CSVObject extends TableObject {
/**
* True if the CSV data was loaded with headers enabled or false if not
*/
private _hasHeaders;
/**
* CSVObject stores all the information for a CSV document and provides easy access to all the
* columns and values and allows us to operate with it's data easily.
*
* @param string A string containing valid csv data
* @param headers Specifies if the first row of the provided csv data contains the column names or not. It is important to correctly set this value to avoid invalid data
* @param delimiter The character that is used as the csv delimiter. ',' is set by default
* @param enclosure The character that is used to escape fields when special characters are found
*
* @return The constructed CSVObject
*/
constructor(string?: string, headers?: boolean, delimiter?: string, enclosure?: string);
/**
* Get the value contained at the specified csv cell
*
* @param row An integer containing the index for the row that we want to retrieve
* @param column An integer or a string containing the index or label for the column that we want to retrieve
*
* @return The value for the cell that is located at the specified row and column
*/
getCell(row: number, column: number | string): string;
/**
* Set the value for a csv cell
*
* @param row An integer containing the index for the row that we want to set
* @param column An integer or a string containing the index or label for the column that we want to set
* @param value The value we want to set to the specified cell. Only string values are allowed
*
* @see TableObject.setCell
*
* @return The assigned value after beign stored into the csv cell
*/
setCell(row: number, column: number | string, value: any): any;
/**
* Check if the provided value contains valid CSV information.
*
* @param value Object to test for valid CSV data. Accepted values are: Strings containing CSV data or CSVObject elements
*
* @return True if the received object represent valid CSV data. False otherwise.
*/
static isCSV(value: any): boolean;
/**
* Check if two provided CSV structures represent the same data
*
* @param csv A valid string or CSVObject to compare with the current one
*
* @return true if the two CSV elements are considered equal, false if not
*/
isEqualTo(csv: any): boolean;
/**
* Generate the textual representation for the csv data stored on this object.
* The output of this method is ready to be stored on a physical .csv file.
*
* @param delimiter The character that is used as the csv delimiter. ',' is set by default
* @param enclosure The character that is used to escape fields when special characters are found
*
* @return A valid csv string ready to be stored on a .csv file
*/
toString(delimiter?: string, enclosure?: string): string;
/**
* Auxiliary method that is used to add a new field to the table at the specified position
*
* @param currentRow The row where we want to add the field
* @param currentColumn The column where we want to add the field
* @param fieldValue The value we want to add to the field
*
* @return void
*/
private _insertField;
/**
* Auxiliary method to correctly format a csv field so it can be stored as a string
*
* @param field The field that has to be formatted
* @param delimiter The character that is used as the csv delimiter. ',' is set by default
* @param enclosure The character that is used to escape fields when special characters are found
*
* @return The field correctly scaped and ready to be stored on a string
*/
private _escapeField;
/**
* Auxiliary method that looks for the next delimiter or newline characters on the csv string starting at the specified position.
*
* @param string The full csv string to search in.
* @param currentIndex The csv string starting point for the search
* @param delimiter The character that is used as the csv delimiter
*
* @return The index where the next delimiter or newline character is found
*/
private _findNextDelimiterIndex;
/**
* Auxiliary method to load the first csv row as the column names and avoid duplicate column names
*
* @return void
*/
private _defineHeaders;
}