simple-csv-tools
is a simple API to work on CSV spreadsheets.
When you import simple-scv-tools
, you'll be reported with a class. The class provides the API for working on your spreadsheet.
const Spreadsheet = require("simple-csv-tools");
var sheet = new Spreadsheet(path: string, stringsOnly: boolean);
The path
parameter is for the the spreadsheet's (.csv
file format) file path. simple-csv-tools
supports numbers. The stringsOnly
parameter (false
by default)
is a boolean to ask whether the data should be returned only in the string format. If stringsOnly
is set to true
, numerical values will be returned in the string
format.
toStr()
: Returns the string of the spreadsheet in the CSV format.toArr()
: Returns an array containing the same data in the spreadsheet (JSON format)writeJSON(...paths: string[])
: Converts CSV to JSON and writes files to the paths given in the parameters.parse(arr: array)
: Ovverides the spreadsheets to the given data in JSON form from thearr
parameter.sortColumns(fisrtlineisheaders: boolean, headers: array)
: Sorts data in the spreadhseet by it's columns and returns the sorted data. Thefisrtlineisheaders
andsortNumericalRows
is set totrue
by default. You need to give theheaders
parameter only iffisrtlineisheaders
is set tofalse
. This method will return the array of all the columns in the spreadsheet in theColumn
format.
sortedData()
: Returns the data of the column sorted using serial numbers (from up to down).srNo(element: string/number)
: Returns the serial number of the element in the column. Will return0
if the element is not found.getElementBySrNo(srNo: number)
: Returns the element given of the perticular serial number in thesrNo
parameter.includes(element:string/number)
: Returnstrue
orfalse
whether the column contains the perticular value in theelement
parameter.