1.2.1 • Published 4 years ago
@moreavy/simple-csv-tools v1.2.1
simple-csv-tools
simple-csv-tools is a simple API to work on CSV spreadsheets.
Usage
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.
Methods
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 thearrparameter.sortColumns(fisrtlineisheaders: boolean, headers: array): Sorts data in the spreadhseet by it's columns and returns the sorted data. ThefisrtlineisheadersandsortNumericalRowsis set totrueby default. You need to give theheadersparameter only iffisrtlineisheadersis set tofalse. This method will return the array of all the columns in the spreadsheet in theColumnformat.
Methods Of Columns
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 return0if the element is not found.getElementBySrNo(srNo: number): Returns the element given of the perticular serial number in thesrNoparameter.includes(element:string/number): Returnstrueorfalsewhether the column contains the perticular value in theelementparameter.