Skip to content

XHiddenProjects/CSVJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 

Repository files navigation

CSVJS

CSVJS Allows CSV, Comma-Separated values, in JS.

Starting up

Use this script to get the script

<script src="https://cdn.jsdelivr.net/gh/XHiddenProjects/[email protected]/csv.min.js"></script>

Creating object

To start the object use the csvJS() using a custom splicer and EOF(End of Line)

/**
  * Creates a CSV object to configure
  * @param {String} splice [Optional] - Character to splice in row
  * @param {String} EOF [Optional] - Character to split each column
  */
const csv = new csvJS(splice=',', EOF='\n')

Import CSV

To import CSV, use the fromFile method

/**
  * Converts CSV file to an Object
  * @param {String} file CSV File path to return as
  * @param {Number|Number[]} [ignoreLines=0] Ignore lines. Use 0 to use no-ignore lines
  * @returns {Object[]} CSV Object
  */
const myCSV = csv.fromFile({file_path},ignoreLines=0);

From String

To use a string version of CSV to create an object us the fromString method

/**
  * Converts CSV from string to object
  * @param {String} str CSV string
  * @param {Number|Number[]} ignoreLines Lines to ignore
  * @returns {Object[]} CSV object
  */
const myCSV = csv.fromString(str, ignoreLines=0);

Ignoring lines

Use the ignoreLines parameter of either a Number | Number[]. Numbers must be start from 1..., 0 means no-ignore or skip

Tables

To load up the table from an object, use the toTable method

/**
  * Creates a table off the object
  * @param {Element} elem Element to target the CSV
  */
csv.toTable({element});

Converting to SQL

To convert objects to SQL insert CMD line:

/**
  * Converts CSV Object to SQL
  * @returns {String} SQL String
  */
csv.toSQL();

Coverting Objects to CSV

To convert objects to CSV, use the toCSV() method

/**
  * Converts Object to CSV
  * @returns {String} CSV String
  */
csv.toCSV();

converting to JSON

To convert objects to JSON format, use toJSON() method

/**
  * Converts CSV Object to JSON
  * @param {Number} opt Options. JSON_OPTION_REGULAR | JSON_OPTION_TRANSPOSE
  * @returns {String} JSON object
  */
csv.toJSON(opt)

About

CSVJS Allows CSV, Comma-Separated values, in JS

Resources

Stars

Watchers

Forks

Packages

No packages published